cpython icon indicating copy to clipboard operation
cpython copied to clipboard

No exception set but raise SystemError when setting _fields_ of ctypes.Structure in __init_subclass__

Open nyaoouo opened this issue 3 years ago • 1 comments

Bug report

No exception set but raise SystemError when setting _fields_ of ctypes.Structure in __init_subclass__
Reproduce code:

import ctypes


class ParentStructure(ctypes.Structure):
    def __init_subclass__(cls, **kwargs):
        cls._fields_ =[('v1',ctypes.c_uint),('v2',ctypes.c_uint),]
        super().__init_subclass__(**kwargs)


class ChildStructure(ParentStructure):
    pass

Output Exception

Traceback (most recent call last):
  File "D:\Projects\pythonProject\main.py", line 10, in <module>
    class ChildStructure(ParentStructure):
  File "D:\Projects\pythonProject\main.py", line 6, in __init_subclass__
    cls._fields_ =[('v1',ctypes.c_uint),('v2',ctypes.c_uint),]
SystemError: error return without exception set

Your environment

Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32

  • PR: gh-99283
  • PR: gh-99285

nyaoouo avatar Nov 09 '22 05:11 nyaoouo

I proposed a PR that sets the exception.

sobolevn avatar Nov 09 '22 09:11 sobolevn