Skip to content

bpo-39416: Document some restrictions on the default string representations of numeric classes #18111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this should have been changed to numeric too, but that’s very minor so I will leave it and merge the backport PRs as is.

: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:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document some restrictions on the default string representations of numeric classes.