Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49368

Problems with subclassing enum34

From Thomas Heller <theller@ctypes.org>
Newsgroups comp.lang.python
Subject Problems with subclassing enum34
Date 2013-06-28 12:48 +0200
Message-ID <b357q6Fql37U1@mid.individual.net> (permalink)

Show all headers | View raw


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
...
 >>> class MyEnum(ctypes.c_int, enum.Enum):
...     FOOBAR = 42
...     __metaclass__ = MyEnum_meta
...
 >>> MyEnum.FOOBAR
42
 >>>

It should have printed '<MyEnum.FOOBAR: 42>'.

Any ideas?

Thanks,
Thomas

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


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