isinstance() and multiple inheritance/ctypes
Rob Gaddi
rgaddi at technologyhighland.invalid
Wed Aug 26 17:21:56 EDT 2015
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
-------------------------------------------------------
Is there an issue with isinstance and multiple inheritance? Conversely
is there an issue with isinstance and ctypes derived classes (Bitfield
isn't, but Bitfield is a mixin that always works with Unions) I know
that ctypes classes can get really wonky on this stuff.
More generally, is there any good way to introspect ctypes derived
classes? I have to figure out whether things are derived from Structure,
Union, Array etc. through some ugly indirect methods, and have no idea
why.
--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.
More information about the Python-list
mailing list