Skip to content

Commit 0dea924

Browse files
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 2e1a9ce) Co-authored-by: Shantanu <[email protected]>
1 parent 3ea6f7f commit 0dea924

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
@@ -628,20 +628,23 @@ are always available. They are listed here in alphabetical order.
628628
sign may be ``'+'`` or ``'-'``; a ``'+'`` sign has no effect on the value
629629
produced. The argument may also be a string representing a NaN
630630
(not-a-number), or positive or negative infinity. More precisely, the
631-
input must conform to the following grammar after leading and trailing
632-
whitespace characters are removed:
631+
input must conform to the ``floatvalue`` production rule in the following
632+
grammar, after leading and trailing whitespace characters are removed:
633633

634634
.. productionlist:: float
635635
sign: "+" | "-"
636636
infinity: "Infinity" | "inf"
637637
nan: "nan"
638-
numeric_value: `floatnumber` | `infinity` | `nan`
639-
numeric_string: [`sign`] `numeric_value`
640-
641-
Here ``floatnumber`` is the form of a Python floating-point literal,
642-
described in :ref:`floating`. Case is not significant, so, for example,
643-
"inf", "Inf", "INFINITY", and "iNfINity" are all acceptable spellings for
644-
positive infinity.
638+
digitpart: `digit` (["_"] `digit`)*
639+
number: [`digitpart`] "." `digitpart` | `digitpart` ["."]
640+
exponent: ("e" | "E") ["+" | "-"] `digitpart`
641+
floatnumber: number [`exponent`]
642+
floatvalue: [`sign`] (`floatnumber` | `infinity` | `nan`)
643+
644+
Here ``digit`` is a Unicode decimal digit (character in the Unicode general
645+
category ``Nd``). Case is not significant, so, for example, "inf", "Inf",
646+
"INFINITY", and "iNfINity" are all acceptable spellings for positive
647+
infinity.
645648

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

0 commit comments

Comments
 (0)