Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

We don't have a choice here.  Operations between decimals and floats raise a 
TypeError.  So, we can't register Decimal as a Real; otherwise, static type 
checking wouldn't be able to flag the following as invalid:

    def add(a: Real, b: Real) -> Real:
        return a + b

    a: Real = Decimal('1.1')
    b: Real = 2.2
    print(add(a, b))

This gives:

    Traceback (most recent call last):
      File "/Users/raymond/Documents/tmp.py", line 10, in <module>
        print(add(a, b))
      File "/Users/raymond/Documents/tmp.py", line 6, in add
        return a + b
    TypeError: unsupported operand type(s) for +: 'decimal.Decimal' and 'float'

Almost the whole point of static checking is to avoid these TypeErrors at 
runtime

----------
nosy: +rhettinger

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43602>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to