Skip to content

Commit 89fac4c

Browse files
[3.8] bpo-39416: Document some restrictions on the default string representations of numeric classes (GH-18111) (GH-22861)
[[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/[email protected]/thread/FV22TKT3S2Q3P7PNN6MCXI6IX3HRRNAL/ (cherry picked from commit c60394c) Co-authored-by: kpinc <[email protected]> Automerge-Triggered-By: GH:merwok
1 parent f3982d6 commit 89fac4c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Doc/reference/datamodel.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@ Ellipsis
182182
related to mathematical numbers, but subject to the limitations of numerical
183183
representation in computers.
184184

185+
The string representations of the Numeric classes, computed by
186+
:meth:`__repr__` and :meth:`__str__`, have the following
187+
properties:
188+
189+
* They are valid numeric literals which, when passed to their
190+
class constructor, produce an object having the value of the
191+
original numeric.
192+
193+
* The representation is in base 10, when possible.
194+
195+
* Leading zeros, possibly excepting a single zero before a
196+
decimal point, are not shown.
197+
198+
* Trailing zeros, possibly excepting a single zero after a
199+
decimal point, are not shown.
200+
201+
* A sign is shown only when the number is negative.
202+
185203
Python distinguishes between integers, floating point numbers, and complex
186204
numbers:
187205

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document some restrictions on the default string representations of numeric classes.

0 commit comments

Comments
 (0)