Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'calls.': 0.09; 'derived': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thus,': 0.09; 'api': 0.11; 'enum': 0.16; 'kern': 0.16; 'metaclass': 0.16; 'metaclasses': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subclass': 0.16; 'subject:Problems': 0.16; 'typeerror:': 0.16; 'underlying': 0.16; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'interpret': 0.24; 'pass': 0.26; 'skip:_ 20': 0.27; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'robert': 0.30; 'work.': 0.31; '"",': 0.31; 'ctypes': 0.31; 'file': 0.32; 'class': 0.32; 'skip:m 30': 0.32; '(most': 0.33; 'subject:with': 0.35; 'but': 0.35; 'instances': 0.36; 'module.': 0.36; 'two': 0.37; 'to:addr:python- list': 0.38; 'recent': 0.39; 'skip:_ 30': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'our': 0.64; 'chance': 0.65; 'thomas': 0.65; 'world': 0.66; 'believe': 0.68; 'eco': 0.84; 'terrible': 0.84; 'either:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Problems with subclassing enum34 Date: Fri, 28 Jun 2013 12:16:40 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 213.1.240.226 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372418213 news.xs4all.nl 15889 [2001:888:2000:d::a6]:39127 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49370 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 "", 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 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