[Python-Dev] PEP 0484 - the Numeric Tower (original) (raw)

Raymond Hettinger raymond.hettinger at gmail.com
Tue Oct 13 11:38:07 EDT 2015


On Oct 13, 2015, at 4:21 AM, Laura Creighton <lac at openend.se> wrote:

Any chance of adding Decimal to the list of things that are also acceptable for things annotated float?

From Lib/numbers.py:

Notes on Decimal

----------------

Decimal has all of the methods specified by the Real abc, but it should

not be registered as a Real because decimals do not interoperate with

binary floats (i.e. Decimal('3.14') + 2.71828 is undefined). But,

abstract reals are expected to interoperate (i.e. R1 + R2 should be

expected to work if R1 and R2 are both Reals).

That is still true:

Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "copyright", "credits" or "license()" for more information.

from decimal import Decimal Decimal('3.14') + 2.71828 Traceback (most recent call last): File "<pyshell#1>", line 1, in Decimal('3.14') + 2.71828 TypeError: unsupported operand type(s) for +: 'decimal.Decimal' and 'float'

Raymond Hettinger



More information about the Python-Dev mailing list