Skip to content

Commit ec62b47

Browse files
[3.9] bpo-39416: Document some restrictions on the default string representations of numeric classes (GH-18111) (GH-22860)
[[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 871c6cc commit ec62b47

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
@@ -187,6 +187,24 @@ Ellipsis
187187
related to mathematical numbers, but subject to the limitations of numerical
188188
representation in computers.
189189

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

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)