Problems with subclassing enum34
Robert Kern
robert.kern at gmail.com
Fri Jun 28 07:16:40 EDT 2013
On 2013-06-28 11:48, 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.
>
> When I do this, I get a metaclass conflict:
>
>
> >>> class MyEnum(ctypes.c_int, enum.Enum):
> ... FOOBAR = 0
> ...
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: Error when calling the metaclass bases
> metaclass conflict: the metaclass of a derived class must be a (non-strict)
> subclass of the metaclasses of all its bases
> >>>
>
>
>
> When I do this, it does not work either:
>
> >>> class MyEnum_meta(type(ctypes.c_int), type(enum.Enum)):
> ... pass
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 Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list