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

Paul Moore p.f.moore at gmail.com
Wed Aug 28 12:22:47 CEST 2013


On 28 August 2013 11:15, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:

> There's also no way to arithmetic with int/Fraction real and imaginary
> components (e.g. gaussian integers etc.) but these are still instances
> of Complex.
>

The difference is that there is no implicit conversion from Decimal to
float:

>>> from decimal import Decimal as D
>>> D('1.5') + 2.3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'Decimal' and 'float'
>>> from fractions import Fraction as F
>>> F(1,2) + 2.3
2.8

IIRC, that's the reason Decimal is treated specially here - maybe it's not
a sufficiently good reason (I don't have an opinion on that) but from what
little I recall of the discussions around the time, it's the key
distinguishing feature of Decimal in these matters...

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130828/b63b252f/attachment.html>


More information about the Python-ideas mailing list