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


Groups > comp.lang.python > #95679

Re: isinstance() and multiple inheritance/ctypes

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 <rosuav@gmail.com>
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 <mrlalj$nlt$1@dont-email.me>
References <mrlalj$nlt$1@dont-email.me>
Date Thu, 27 Aug 2015 09:12:55 +1000
Subject Re: isinstance() and multiple inheritance/ctypes
From Chris Angelico <rosuav@gmail.com>
To Rob Gaddi <rgaddi@technologyhighland.invalid>
Cc "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.67.1440630784.11709.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Thu, Aug 27, 2015 at 7:21 AM, Rob Gaddi
<rgaddi@technologyhighland.invalid> 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
<class 'bitfield.bf'>
>>> bf.__mro__
(<class 'bitfield.bf'>, <class '_ctypes.Union'>, <class
'_ctypes._CData'>, <class 'bitfield.Bitfield'>, <class 'object'>)
>>> type(bf)
<class '_ctypes.UnionType'>
>>> type(bf).__mro__
(<class '_ctypes.UnionType'>, <class 'type'>, <class 'object'>)

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__

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


Thread

isinstance() and multiple inheritance/ctypes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-08-26 21:21 +0000
  Re: isinstance() and multiple inheritance/ctypes Terry Reedy <tjreedy@udel.edu> - 2015-08-26 17:46 -0400
  Re: isinstance() and multiple inheritance/ctypes Chris Angelico <rosuav@gmail.com> - 2015-08-27 09:12 +1000
    Re: isinstance() and multiple inheritance/ctypes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-08-26 23:42 +0000
  Re: isinstance() and multiple inheritance/ctypes Chris Angelico <rosuav@gmail.com> - 2015-08-27 09:14 +1000
    Re: isinstance() and multiple inheritance/ctypes Steven D'Aprano <steve@pearwood.info> - 2015-08-27 22:59 +1000
      Re: isinstance() and multiple inheritance/ctypes Chris Angelico <rosuav@gmail.com> - 2015-08-28 00:33 +1000
        Re: isinstance() and multiple inheritance/ctypes Steven D'Aprano <steve@pearwood.info> - 2015-08-28 13:02 +1000
          Re: isinstance() and multiple inheritance/ctypes Chris Angelico <rosuav@gmail.com> - 2015-08-28 13:25 +1000

csiph-web