I try to check if a variable is an instance of a number of any type (int
, float
, Fraction
, Decimal
, etc.).
I cam accross this question and its answer: How to properly use python's isinstance() to check if a variable is a number?
However, I would like to exclude complex numbers such as 1j
.
The class numbers.Real
looked perfect but it returns False
for Decimal
numbers...
from numbers Real
from decimal import Decimal
print(isinstance(Decimal(1), Real))
# False
In contradiction, it works fine with Fraction(1)
for example.
The documentation describes some operations which should work with the number, I tested them without any error on a decimal instance. Decimal objects cannot contains complex numbers moreover.
So, why isinstance(Decimal(1), Real)
would return False
?