[Python-checkins] gh-100428: Make float documentation more accurate (GH-100437)
miss-islington
webhook-mailer at python.org
Sat Dec 24 15:15:52 EST 2022
https://github.com/python/cpython/commit/0dea92409e291cd61135d509204f60c46f6dfc0b
commit: 0dea92409e291cd61135d509204f60c46f6dfc0b
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-12-24T12:15:46-08:00
summary:
gh-100428: Make float documentation more accurate (GH-100437)
Previously, the grammar did not accept `float("10")`.
Also implement mdickinson's suggestion of removing the indirection.
(cherry picked from commit 2e1a9ce9890aba748a518a39d01d1ea6d623d0d9)
Co-authored-by: Shantanu <12621235+hauntsaninja at users.noreply.github.com>
files:
M Doc/library/functions.rst
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 97641d1b85cb..46e77fdb4155 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -628,20 +628,23 @@ are always available. They are listed here in alphabetical order.
sign may be ``'+'`` or ``'-'``; a ``'+'`` sign has no effect on the value
produced. The argument may also be a string representing a NaN
(not-a-number), or positive or negative infinity. More precisely, the
- input must conform to the following grammar after leading and trailing
- whitespace characters are removed:
+ input must conform to the ``floatvalue`` production rule in the following
+ grammar, after leading and trailing whitespace characters are removed:
.. productionlist:: float
sign: "+" | "-"
infinity: "Infinity" | "inf"
nan: "nan"
- numeric_value: `floatnumber` | `infinity` | `nan`
- numeric_string: [`sign`] `numeric_value`
-
- Here ``floatnumber`` is the form of a Python floating-point literal,
- described in :ref:`floating`. Case is not significant, so, for example,
- "inf", "Inf", "INFINITY", and "iNfINity" are all acceptable spellings for
- positive infinity.
+ digitpart: `digit` (["_"] `digit`)*
+ number: [`digitpart`] "." `digitpart` | `digitpart` ["."]
+ exponent: ("e" | "E") ["+" | "-"] `digitpart`
+ floatnumber: number [`exponent`]
+ floatvalue: [`sign`] (`floatnumber` | `infinity` | `nan`)
+
+ Here ``digit`` is a Unicode decimal digit (character in the Unicode general
+ category ``Nd``). Case is not significant, so, for example, "inf", "Inf",
+ "INFINITY", and "iNfINity" are all acceptable spellings for positive
+ infinity.
Otherwise, if the argument is an integer or a floating point number, a
floating point number with the same value (within Python's floating point
More information about the Python-checkins
mailing list