[Python-ideas] isinstance(Decimal(), Real) -> False?
Nick Coghlan
ncoghlan at gmail.com
Wed Aug 28 09:02:20 CEST 2013
On 28 August 2013 11:47, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
> 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?
If I recall correctly, it was the fact that isinstance(d, Real)
implies isinstance(d, Complex), yet there's no way to do complex
arithmetic with Decimal real and imaginary components.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list