mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[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/python-dev@python.org/thread/FV22TKT3S2Q3P7PNN6MCXI6IX3HRRNAL/
(cherry picked from commit c60394c7fc
)
Co-authored-by: kpinc <kop@karlpinc.com>
Automerge-Triggered-By: GH:merwok
This commit is contained in:
parent
871c6ccf4a
commit
ec62b47ebc
2 changed files with 19 additions and 0 deletions
|
@ -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:
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Document some restrictions on the default string representations of numeric classes.
|
Loading…
Add table
Add a link
Reference in a new issue