Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Thomas Heller Newsgroups: comp.lang.python Subject: Problems with subclassing enum34 Date: Fri, 28 Jun 2013 12:48:38 +0200 Lines: 40 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Ie3iqJmqALzPRZaLLrQxtw2vIO92RdNY1+9xMoU4ZWntoSylU= Cancel-Lock: sha1:zcN34Q61pHsLaM8gl52NsctRfG0= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 Xref: csiph.com comp.lang.python:49368 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 "", line 1, in 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 ''. Any ideas? Thanks, Thomas