[Python-checkins] [3.9] bpo-39416: Document some restrictions on the default string representations of numeric classes (GH-18111) (GH-22860)
miss-islington
webhook-mailer at python.org
Wed Oct 21 14:56:26 EDT 2020
https://github.com/python/cpython/commit/ec62b47ebc8f29007942c8e9f3f260af91ca58cb
commit: ec62b47ebc8f29007942c8e9f3f260af91ca58cb
branch: 3.9
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-10-21T11:56:16-07:00
summary:
[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 c60394c7fc9cc09b16e9675a3eeb5844b6d8523f)
Co-authored-by: kpinc <kop at karlpinc.com>
Automerge-Triggered-By: GH:merwok
files:
A Misc/NEWS.d/next/Documentation/2020-01-22-05-14-53.bpo-39416.uYjhEm.rst
M Doc/reference/datamodel.rst
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index aaa161aad2773..c0e7edb2421b0 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:
diff --git a/Misc/NEWS.d/next/Documentation/2020-01-22-05-14-53.bpo-39416.uYjhEm.rst b/Misc/NEWS.d/next/Documentation/2020-01-22-05-14-53.bpo-39416.uYjhEm.rst
new file mode 100644
index 0000000000000..279a5f18ff855
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2020-01-22-05-14-53.bpo-39416.uYjhEm.rst
@@ -0,0 +1 @@
+Document some restrictions on the default string representations of numeric classes.
More information about the Python-checkins
mailing list