Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49370
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Subject | Re: Problems with subclassing enum34 |
| Date | 2013-06-28 12:16 +0100 |
| References | <b357q6Fql37U1@mid.individual.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3956.1372418213.3114.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problems with subclassing enum34 Thomas Heller <theller@ctypes.org> - 2013-06-28 12:48 +0200
Re: Problems with subclassing enum34 Robert Kern <robert.kern@gmail.com> - 2013-06-28 12:16 +0100
Re: Problems with subclassing enum34 88888 Dihedral <dihedral88888@gmail.com> - 2013-06-28 04:52 -0700
Re: Problems with subclassing enum34 Ethan Furman <ethan@stoneleaf.us> - 2013-06-28 08:16 -0700
Re: Problems with subclassing enum34 Thomas Heller <theller@ctypes.org> - 2013-06-28 17:25 +0200
Re: Problems with subclassing enum34 Thomas Heller <theller@ctypes.org> - 2013-06-28 17:32 +0200
Re: Problems with subclassing enum34 Robert Kern <robert.kern@gmail.com> - 2013-06-28 17:17 +0100
Re: Problems with subclassing enum34 Ethan Furman <ethan@stoneleaf.us> - 2013-06-28 10:09 -0700
csiph-web