Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(python': 0.05; 'context': 0.05; 'cc:addr:python-list': 0.09; '-------': 0.09; 'subclass': 0.09; 'subject:ctypes': 0.09; 'thu,': 0.15; '(),': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guessing': 0.16; 'linux)': 0.16; 'magic': 0.16; 'omitting': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; '(on': 0.22; 'trying': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'message-id:@mail.gmail.com': 0.27; '-----': 0.29; "i'm": 0.30; 'subject:/': 0.30; 'skip:_ 10': 0.32; 'case,': 0.34; 'running': 0.34; 'skip:- 50': 0.35; 'received:google.com': 0.35; 'skip:( 30': 0.35; 'false': 0.35; 'quite': 0.35; 'but': 0.36; 'there': 0.36; 'created': 0.36; 'subject:: ': 0.37; 'some': 0.40; 'your': 0.60; '3.4': 0.84; 'lying': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=s4Bf40gGOES3Yrtm3Ypd/OrCeBthAEr46wR7xecVjBs=; b=GBzff4G/dlJ+kuNoUoHI1tKG3f64sNQCgaeaMtBK+Y7JuDkVyLGyy08zQ3VaGwarxv 7+n+BHisXdLWk7oovY5LRU2GWrHrbn6dsA8eIotitAcvsllJdZsoKIwEkhZek08NIf+w wj4EjGjNH+MMLNVlVip4qskoTi7aGDEJwesNKIbK1hm2C1mZ5+FNUxV5c7gwjm09QuKV d+kFO3UE2RRD9TQW2KWesKhE38dD+gwq44IE2CgS0+PGx0cOIlqYgIWlmJoItXsq203s OE8LeDsffXZUYVH/YIUz3xVAvZFIyHz6/jz2yKA9ER1Jckig7nZwPNCfHYsH0EkD3yVo I/WA== MIME-Version: 1.0 X-Received: by 10.50.118.104 with SMTP id kl8mr14838302igb.92.1440630775522; Wed, 26 Aug 2015 16:12:55 -0700 (PDT) In-Reply-To: References: Date: Thu, 27 Aug 2015 09:12:55 +1000 Subject: Re: isinstance() and multiple inheritance/ctypes From: Chris Angelico To: Rob Gaddi Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440630784 news.xs4all.nl 23767 [2001:888:2000:d::a6]:48493 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95679 On Thu, Aug 27, 2015 at 7:21 AM, Rob Gaddi wrote: > I'm running into some strangeness trying to work with the bitfield module > from my ctypes-bitfield package (on PyPi). I'm trying to use isinstance > (), and it's kinda sorta lying to me. > > ----- IPython session (Python 3.4 under Linux) ------- > In [649]: bf.__mro__ > Out[649]: (bitfield._TD, _ctypes.Union, _ctypes._CData, > bitfield.Bitfield, builtins.object) > > In [650]: isinstance(bf, bitfield.Bitfield) > Out[650]: False > > In [651]: bf.__bases__ > Out[651]: (_ctypes.Union, bitfield.Bitfield) > > In [652]: bf.__bases__[1] > Out[652]: bitfield.Bitfield > > In [653]: bf.__bases__[1] is bitfield.Bitfield > Out[653]: True > ------------------------------------------------------- You're omitting some context here, but after poking around with your module a bit, I'm guessing you created bf somewhat thus? >>> bf = bitfield.make_bf("bf", (("asdf",bitfield.c_uint,2),)) >>> bf >>> bf.__mro__ (, , , , ) >>> type(bf) >>> type(bf).__mro__ (, , ) If that's the case, then it's quite correct: bf is not a Bitfield, it is a subclass of bitfield. >>> isinstance(bf,type) True >>> isinstance(bf(),bitfield.Bitfield) True >>> issubclass(bf,bitfield.Bitfield) True Or is there a magic __isinstance__