This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Sergey.Kirpichev, docs@python, rhettinger
Date 2021-03-23.07:28:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616484491.7.0.560125533154.issue43602@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-03-23 07:35:42rhettingerunlinkissue43602 messages
2021-03-23 07:28:11rhettingersetrecipients: + rhettinger, docs@python, Sergey.Kirpichev
2021-03-23 07:28:11rhettingersetmessageid: <1616484491.7.0.560125533154.issue43602@roundup.psfhosted.org>
2021-03-23 07:28:11rhettingerlinkissue43602 messages
2021-03-23 07:28:11rhettingercreate