GeezerVison is showing github.com — Floating point syntax specification is incorrect · Issue #114070 · python/cpython
Floating point syntax specification is incorrect #114070DescriptionDocumentation
The floating point syntax spec is incorrect, and can be found in /Doc/library/functions.rst:
The syntax rendered currently is the following:
sign ::= "+" | "-"
infinity ::= "Infinity" | "inf"
nan ::= "nan"
digitpart ::= `!digit` (["_"] `!digit`)*
number ::= [digitpart] "." digitpart | digitpart ["."]
exponent ::= ("e" | "E") ["+" | "-"] digitpart
floatnumber ::= number [exponent]
floatvalue ::= [sign] (floatnumber | infinity | nan)
digitpart should not include an exclamation point or backtick quotes. The backticks appear to be the underlying syntax failing to render, but the exclamation points have a meaning, which is an issue. This is the underlying syntax:
sign: "+" | "-"
infinity: "Infinity" | "inf"
nan: "nan"
digitpart: `!digit` (["_"] `!digit`)*
number: [`digitpart`] "." `digitpart` | `digitpart` ["."]
exponent: ("e" | "E") ["+" | "-"] `digitpart`
floatnumber: number [`exponent`]
EBNF includes a "Special Sequences" syntax, that would be appropriate for this situation, but I'm uncertain if it is possible to use in the underlying YAML format. It should be rendered like this:
sign ::= "+" | "-"
infinity ::= "Infinity" | "inf"
nan ::= "nan"
digit ::= ? Any character in the unicode digit class ?
digitpart ::= digit (["_"] digit)*
number ::= [digitpart] "." digitpart | digitpart ["."]
exponent ::= ("e" | "E") ["+" | "-"] digitpart
floatnumber ::= number [exponent]
floatvalue ::= [sign] (floatnumber | infinity | nan)
Linked PRs
Activityskirpichev commented on Jan 15, 2024
It should be rendered like this
In other places - angle brackets are used to surround RHS's of digit-like definitions. For example:
hugovk commented on Jan 15, 2024
This one has a clickable digit link, which takes us to:
In YAML:
Would it be appropriate to add something like that here? skirpichev commented on Jan 15, 2024 @hugovk, no - that will be incorrect in this case. This is valid, for example, in case of floating-point literals.
But the float() constructor (int() too) supports more (not sure for good or evil): "Here digit is a Unicode decimal digit (character in the Unicode general category Nd)." (c)
For example:
>>> float('١٢٣') # arabic decimals: U+0661-3
123.0
>>> int('١٢٣')
123hugovk commented on Jan 15, 2024 OK, then shall we use angle brackets here? skirpichev commented on Jan 15, 2024 I think so. The documentation says it's using "a modified Backus–Naur form (BNF) grammar notation", where: "A phrase between angular brackets (<...>) gives an informal description of the symbol defined; e.g., this could be used to describe the notion of ‘control character’ if needed." hauntsaninja commented on Jan 15, 2024 skirpichev commented on Jan 15, 2024 added a commit that references this issue on Jan 15, 2024gh-114070: correct the specification of ``digit`` in the float() docs (… hauntsaninja commented on Jan 15, 2024 Thanks knotapun, skirpichev and hugovk!! Reacted by Hugo van Kemenade hugovk commented on Jan 16, 2024 Yes, thanks!
If people are interested, there's some other productionlist items that are causing token reference warnings that need fixing one way or another:
make -C Doc html SPHINXERRORHANDLING=-n SOURCES="reference/compound_stmts.rst reference/expressions.rst"
Doc/reference/compound_stmts.rst:601: WARNING: 'token' reference target not found: python-grammar:star_named_expression
Doc/reference/compound_stmts.rst:601: WARNING: 'token' reference target not found: python-grammar:star_named_expressions
Doc/reference/compound_stmts.rst:601: WARNING: 'token' reference target not found: python-grammar:named_expression
Doc/reference/compound_stmts.rst:601: WARNING: 'token' reference target not found: python-grammar:block
Doc/reference/compound_stmts.rst:693: WARNING: 'token' reference target not found: python-grammar:named_expression
Doc/reference/compound_stmts.rst:835: WARNING: 'token' reference target not found: python-grammar:signed_number
Doc/reference/compound_stmts.rst:835: WARNING: 'token' reference target not found: python-grammar:signed_number
Doc/reference/compound_stmts.rst:835: WARNING: 'token' reference target not found: python-grammar:signed_number
Doc/reference/compound_stmts.rst:835: WARNING: 'token' reference target not found: python-grammar:strings
Doc/reference/compound_stmts.rst:835: WARNING: 'token' reference target not found: python-grammar:signed_number
Doc/reference/expressions.rst:16: WARNING: 'token' reference target not found: python-grammar:othername
Doc/reference/expressions.rst:518: WARNING: 'token' reference target not found: python-grammar:yield_from
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|