I'm trying to get a deeper understanding in Python's data model and I don't fully understand the following code:
>>> x = 1
>>> isinstance(x,int)
True
>>> isinstance(x,numbers.Integral)
True
>>> inspect.getmro(int)
(<type 'int'>, <type 'object'>)
>>> inspect.getmro(numbers.Integral)
(<class 'numbers.Integral'>, <class 'numbers.Rational'>, <class 'numbers.Real'>,
<class 'numbers.Complex'>, <class 'numbers.Number'>, <type 'object'>)
Based on the above, it seems that int
and number.Integral
are not in the same hierarchy.
From the Python reference (2.6.6) I see
numbers.Integral - These represent elements from the mathematical set of integers (positive and negative).
What's the difference between int
and numbers.Integral
? Does it have something to do with the type int
vs class numbers.Integral
I see in the above output?