1

I expected isinstance function to return True only for types that exist in object's type mro tuple. But:

>>> isinstance(int(), numbers.Integral)
True
>>> int.__mro__
(<type 'int'>, <type 'object'>)

Why int.mro does not contain numbers.Integral?

Timur
  • 295
  • 2
  • 12
  • I don't know the internals enough to point at something, but generally the objects implemented in C for speed bypass some things – Nick T Feb 26 '18 at 16:11
  • Why should it? `numbers.Integral` is for defining the interface, that doesn't mean it needs to be in the `int` mro. – wim Feb 26 '18 at 16:14
  • `int` isn't a descendent of `Integral` in the normal sense, but only because `Integral.__subclasshook__` is implemented to make it *look* like it is. – chepner Feb 26 '18 at 16:25

0 Answers0