1

Consider the following:

from decimal import Decimal
from numbers import Number, Complex, Real

z = Decimal(0)

# Expected: a == b == c == True
# Actual (Python 3.6.5):
a = isinstance(z, Number)  # True
b = isinstance(z, Complex) # False
c = isinstance(z, Real)    # False

Decimal appears to implement everything that is needed to be considered Real according to PEP3141, so what gives? Notably, fractions.Fraction is correctly categorized by the above snippet (e.g. a == b == c == True).

Jason
  • 125
  • 5

1 Answers1

1

This is actually mentioned in PEP 3141:

After consultation with its authors it has been decided that the Decimal type should not at this time be made part of the numeric tower.

So Decimal was intentionally excluded.

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
  • That teaches me to read to the end! – Jason Sep 19 '18 at 13:48
  • @Jason In looking for why, I found another question here that goes into more detail, so you should check that out as well. – Patrick Haugh Sep 19 '18 at 13:49
  • thanks for finding that -- the posted solution is both obvious and exactly what I needed, and the explanation is also very informative and likely to save me from seemingly random errors in the future. – Jason Sep 19 '18 at 13:57