From 50807c3b99f3847a51a512745aa7ce35a6c719d7 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 22 Dec 2022 14:52:58 -0600 Subject: [PATCH 1/8] gh-100428: Make float documentation more accurate Previously, the grammar did not accept `float("10")`. Also implement mdickinson's suggestion of removing the indirection. --- Doc/library/functions.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 2110990d188973..7bb6bbb6a9611a 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -657,11 +657,16 @@ are always available. They are listed here in alphabetical order. sign: "+" | "-" infinity: "Infinity" | "inf" nan: "nan" - numeric_value: `floatnumber` | `infinity` | `nan` + + number: floatnumber [`exponent`] + floatnumber: [`digitpart`] "." `digitpart` | `digitpart` ["."] + digitpart: `digit` (["_"] `digit`)* + exponent: ("e" | "E") ["+" | "-"] `digitpart` + + numeric_value: `number` | `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, + Case is not significant, so, for example, "inf", "Inf", "INFINITY", and "iNfINity" are all acceptable spellings for positive infinity. From 78e38a85e3c0c490090616f0a4094331a5c974d6 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 22 Dec 2022 14:59:36 -0600 Subject: [PATCH 2/8] remove empty lines --- Doc/library/functions.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 7bb6bbb6a9611a..379f7a83a4e976 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -657,12 +657,10 @@ are always available. They are listed here in alphabetical order. sign: "+" | "-" infinity: "Infinity" | "inf" nan: "nan" - number: floatnumber [`exponent`] floatnumber: [`digitpart`] "." `digitpart` | `digitpart` ["."] digitpart: `digit` (["_"] `digit`)* exponent: ("e" | "E") ["+" | "-"] `digitpart` - numeric_value: `number` | `infinity` | `nan` numeric_string: [`sign`] `numeric_value` From b0714b267947c07e8e2bae945213af270ec3f63d Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 23 Dec 2022 16:03:09 -0600 Subject: [PATCH 3/8] reflow text --- Doc/library/functions.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 379f7a83a4e976..888d6843ef5f15 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -664,9 +664,8 @@ are always available. They are listed here in alphabetical order. numeric_value: `number` | `infinity` | `nan` numeric_string: [`sign`] `numeric_value` - Case is not significant, so, for example, - "inf", "Inf", "INFINITY", and "iNfINity" are all acceptable spellings for - positive infinity. + 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 From d655fae596ea8f156f847ae2f86cef51d757b4e7 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 23 Dec 2022 18:00:38 -0600 Subject: [PATCH 4/8] reorder based on dependence --- Doc/library/functions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 888d6843ef5f15..7b1db1eb983151 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -657,10 +657,10 @@ are always available. They are listed here in alphabetical order. sign: "+" | "-" infinity: "Infinity" | "inf" nan: "nan" - number: floatnumber [`exponent`] - floatnumber: [`digitpart`] "." `digitpart` | `digitpart` ["."] digitpart: `digit` (["_"] `digit`)* + floatnumber: [`digitpart`] "." `digitpart` | `digitpart` ["."] exponent: ("e" | "E") ["+" | "-"] `digitpart` + number: floatnumber [`exponent`] numeric_value: `number` | `infinity` | `nan` numeric_string: [`sign`] `numeric_value` From 10d5c0d4dec038a08d9b197908ac7202ec40f5c9 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 23 Dec 2022 20:56:11 -0600 Subject: [PATCH 5/8] match the names from lexical analysis a little better --- Doc/library/functions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 7b1db1eb983151..854368670c6f64 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -658,10 +658,10 @@ are always available. They are listed here in alphabetical order. infinity: "Infinity" | "inf" nan: "nan" digitpart: `digit` (["_"] `digit`)* - floatnumber: [`digitpart`] "." `digitpart` | `digitpart` ["."] + number: [`digitpart`] "." `digitpart` | `digitpart` ["."] exponent: ("e" | "E") ["+" | "-"] `digitpart` - number: floatnumber [`exponent`] - numeric_value: `number` | `infinity` | `nan` + floatnumber: number [`exponent`] + numeric_value: `floatnumber` | `infinity` | `nan` numeric_string: [`sign`] `numeric_value` Case is not significant, so, for example, "inf", "Inf", "INFINITY", and From 01c25f278cf27a224d946cf8ea6a36b066e540cc Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 23 Dec 2022 20:56:54 -0600 Subject: [PATCH 6/8] improve "conform to the following grammar" --- Doc/library/functions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 854368670c6f64..82f44c359778a0 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -650,8 +650,8 @@ 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 ``numeric_string`` production rule in the following + grammar, after leading and trailing whitespace characters are removed: .. productionlist:: float sign: "+" | "-" From 11ffd4d68319d7f1c14b1a56588c5486dabfe02e Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 23 Dec 2022 21:41:37 -0600 Subject: [PATCH 7/8] specify digit is unicode nd --- Doc/library/functions.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 82f44c359778a0..b44b0f244c273f 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -664,8 +664,10 @@ are always available. They are listed here in alphabetical order. numeric_value: `floatnumber` | `infinity` | `nan` numeric_string: [`sign`] `numeric_value` - Case is not significant, so, for example, "inf", "Inf", "INFINITY", and - "iNfINity" are all acceptable spellings for positive infinity. + Here ``digit`` is a Unicode decimal digit (characters 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 From 6f0c69995842e2dfba9b437610f61510599b6bc6 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 24 Dec 2022 13:43:19 -0600 Subject: [PATCH 8/8] tinker with the name --- Doc/library/functions.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index b44b0f244c273f..859692471b0866 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -650,7 +650,7 @@ 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 ``numeric_string`` production rule in the following + input must conform to the ``floatvalue`` production rule in the following grammar, after leading and trailing whitespace characters are removed: .. productionlist:: float @@ -661,10 +661,9 @@ are always available. They are listed here in alphabetical order. number: [`digitpart`] "." `digitpart` | `digitpart` ["."] exponent: ("e" | "E") ["+" | "-"] `digitpart` floatnumber: number [`exponent`] - numeric_value: `floatnumber` | `infinity` | `nan` - numeric_string: [`sign`] `numeric_value` + floatvalue: [`sign`] (`floatnumber` | `infinity` | `nan`) - Here ``digit`` is a Unicode decimal digit (characters in the Unicode general + 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.