[Python-ideas] isinstance(Decimal(), Real) -> False?

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Aug 28 03:47:36 CEST 2013


I came across the following today:

$ python3.3
Python 3.3.0 (default, Sep 29 2012, 17:14:58)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numbers
>>> import decimal
>>> d = decimal.Decimal()
>>> isinstance(d, numbers.Number)
True
>>> isinstance(d, numbers.Complex)
False
>>> isinstance(d, numbers.Real)
False
>>> isinstance(d, numbers.Rational)
False
>>> isinstance(d, numbers.Integral)
False

That seems plainly absurd to me. Decimals are quite clearly real
numbers. I then found the following in PEP-3141 [1]:
"""
The Decimal Type

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.
"""

What was the rationale for this decision and does it still apply?


Oscar

References:
[1] http://www.python.org/dev/peps/pep-3141/#the-decimal-type


More information about the Python-ideas mailing list