diff options
author | kpinc <kop@karlpinc.com> | 2020-10-21 17:13:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-21 17:13:50 (GMT) |
commit | c60394c7fc9cc09b16e9675a3eeb5844b6d8523f (patch) | |
tree | 9f1da18368e736ff1dd1c3380786f146342ca441 /Doc/reference | |
parent | c7437e2c0216e05fbf17bf96294cb20954e36e48 (diff) | |
download | cpython-c60394c7fc9cc09b16e9675a3eeb5844b6d8523f.zip cpython-c60394c7fc9cc09b16e9675a3eeb5844b6d8523f.tar.gz cpython-c60394c7fc9cc09b16e9675a3eeb5844b6d8523f.tar.bz2 |
bpo-39416: Document some restrictions on the default string representations of numeric classes (GH-18111)
[bpo-39416](): Document string representations of the Numeric classes
This is a change to the specification of the Python language.
The idea here is to put sane minimal limits on the Python language's default
representations of its Numeric classes. That way "Marty's Robotic Massage Parlor
and Python Interpreter" implementation of Python won't do anything too
crazy.
Some discussion in the email thread:
Subject: Documenting Python's float.__str__()
https://mail.python.org/archives/list/python-dev@python.org/thread/FV22TKT3S2Q3P7PNN6MCXI6IX3HRRNAL/
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/datamodel.rst | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 29e64cb..d9b72a9 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -187,6 +187,24 @@ Ellipsis related to mathematical numbers, but subject to the limitations of numerical representation in computers. + The string representations of the Numeric classes, computed by + :meth:`__repr__` and :meth:`__str__`, have the following + properties: + + * They are valid numeric literals which, when passed to their + class constructor, produce an object having the value of the + original numeric. + + * The representation is in base 10, when possible. + + * Leading zeros, possibly excepting a single zero before a + decimal point, are not shown. + + * Trailing zeros, possibly excepting a single zero after a + decimal point, are not shown. + + * A sign is shown only when the number is negative. + Python distinguishes between integers, floating point numbers, and complex numbers: |