Skip to content

Commit 2e1a9ce

Browse files
authored
gh-100428: Make float documentation more accurate (#100437)
Previously, the grammar did not accept `float("10")`. Also implement mdickinson's suggestion of removing the indirection.
1 parent f5b7b19 commit 2e1a9ce

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Doc/library/functions.rst

+12-9
Original file line numberDiff line numberDiff line change
@@ -650,20 +650,23 @@ are always available. They are listed here in alphabetical order.
650650
sign may be ``'+'`` or ``'-'``; a ``'+'`` sign has no effect on the value
651651
produced. The argument may also be a string representing a NaN
652652
(not-a-number), or positive or negative infinity. More precisely, the
653-
input must conform to the following grammar after leading and trailing
654-
whitespace characters are removed:
653+
input must conform to the ``floatvalue`` production rule in the following
654+
grammar, after leading and trailing whitespace characters are removed:
655655

656656
.. productionlist:: float
657657
sign: "+" | "-"
658658
infinity: "Infinity" | "inf"
659659
nan: "nan"
660-
numeric_value: `floatnumber` | `infinity` | `nan`
661-
numeric_string: [`sign`] `numeric_value`
662-
663-
Here ``floatnumber`` is the form of a Python floating-point literal,
664-
described in :ref:`floating`. Case is not significant, so, for example,
665-
"inf", "Inf", "INFINITY", and "iNfINity" are all acceptable spellings for
666-
positive infinity.
660+
digitpart: `digit` (["_"] `digit`)*
661+
number: [`digitpart`] "." `digitpart` | `digitpart` ["."]
662+
exponent: ("e" | "E") ["+" | "-"] `digitpart`
663+
floatnumber: number [`exponent`]
664+
floatvalue: [`sign`] (`floatnumber` | `infinity` | `nan`)
665+
666+
Here ``digit`` is a Unicode decimal digit (character in the Unicode general
667+
category ``Nd``). Case is not significant, so, for example, "inf", "Inf",
668+
"INFINITY", and "iNfINity" are all acceptable spellings for positive
669+
infinity.
667670

668671
Otherwise, if the argument is an integer or a floating point number, a
669672
floating point number with the same value (within Python's floating point

0 commit comments

Comments
 (0)