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

Michele Lacchia michelelacchia at gmail.com
Wed Aug 28 10:25:42 CEST 2013


How can isinstance(d, Real) imply isinstance(d, Complex)? Can you elaborate
a little more?
It makes no sense to me, since the set of real numbers is a subset of the
complex one.


On Wed, Aug 28, 2013 at 9:02 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> 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
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
Michele Lacchia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130828/f91c73fa/attachment-0001.html>


More information about the Python-ideas mailing list