Problems with subclassing enum34
Thomas Heller
theller at ctypes.org
Fri Jun 28 11:25:27 EDT 2013
Am 28.06.2013 17:16, schrieb Ethan Furman:
> On 06/28/2013 03:48 AM, Thomas Heller wrote:
>> trying out the enum34 module.
>>
>> What I want to create is a subclass of enum.Enum that is also based
>> on ctypes.c_int so that I can better use enum instances in ctypes
>> api calls.
>
> Have you tried using enum.IntEnum? If you were able to pass ints in
> before, IntEnum should work.
I'm sure that IntEnum works as expected, but I need enums that are
subclasses of ctypes.c_int (so that argument type checking and return
value conversions in ctypes api calls work).
Robert Kern:
>
> enum.EnumMeta uses super() in its __new__() implementation but
> _ctypes.PyCSimpleType doesn't. Thus, only
> _ctypes.PyCSimpleType.__new__() gets a chance to run. Switching the
> order of the two might work.
>
Robert found the problem but I'm unsure if there is a solution.
Also I'm unsure whether this is a bug in ctypes or in enum or if
they are simply incompatible.
Thomas
More information about the Python-list
mailing list