GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Floating point syntax specification is incorrect · Issue #114070 · python/cpython

Floating point syntax specification is incorrect #114070

New issue
Copy link
New issue
Copy link
Closed
Closed
Floating point syntax specification is incorrect#114070
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir

Description

@knotapun
knotapun
opened on Jan 15, 2024
Issue body actions

Documentation

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

  • gh-114070: correct the specification of digit in the float() docs #114080
  • [3.12] gh-114070: correct the specification of digit in the float() docs (GH-114080) #114094
  • [3.11] gh-114070: correct the specification of digit in the float() docs (GH-114080) #114095
  • gh-114070: fix token reference warnings in expressions.rst #114169
  • [3.12] gh-114070: fix token reference warnings in expressions.rst (GH-114169) #114192
  • [3.11] gh-114070: fix token reference warnings in expressions.rst (GH-114169) #114193

Activity

  1. knotapun
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Jan 15, 2024
  2. skirpichev commented on Jan 15, 2024

    @skirpichev
    skirpichev
    on Jan 15, 2024
    Member
    More actions

    It should be rendered like this

    In other places - angle brackets are used to surround RHS's of digit-like definitions. For example:

    • https://docs.python.org/3/reference/lexical_analysis.html#identifiers
    • https://docs.python.org/3/library/string.html#format-string-syntax
  3. hugovk commented on Jan 15, 2024

    @hugovk
    hugovk
    on Jan 15, 2024
    Member
    More actions
    • docs.python.org/3/library/string.html#format-string-syntax

    This one has a clickable digit link, which takes us to:

    digit        ::=  "0"..."9"

    In YAML:

       digit: "0"..."9"

    Would it be appropriate to add something like that here?

  4. skirpichev commented on Jan 15, 2024

    @skirpichev
    skirpichev
    on Jan 15, 2024
    Member
    More actions

    @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('١٢٣')
    123
  5. hugovk commented on Jan 15, 2024

    @hugovk
    hugovk
    on Jan 15, 2024
    Member
    More actions

    OK, then shall we use angle brackets here?

  6. skirpichev commented on Jan 15, 2024

    @skirpichev
    skirpichev
    on Jan 15, 2024
    Member
    More actions

    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."

  7. hauntsaninja commented on Jan 15, 2024

    @hauntsaninja
    hauntsaninja
    on Jan 15, 2024
    Contributor
    More actions

    I think the markup got regressed in https://github.com/python/cpython/pull/112669/files#diff-6a7a07ac473fdd76734669b1b70626ad2176011129902f6add017810f54d0439L667

    I improved the grammar here in #100437 , let me know if there's anything I can help with. Moving the description of digit into angle brackets within the grammar rule sounds reasonable to me.

  8. skirpichev
    added a commit that references this issue on Jan 15, 2024

    pythongh-114070: correct the specification of ``digit`` in the float(…

    1b3156e
  9. skirpichev commented on Jan 15, 2024

    @skirpichev
    skirpichev
    on Jan 15, 2024
    Member
    More actions

    @hauntsaninja, see #114080

  10. hauntsaninja
    added a commit that references this issue on Jan 15, 2024

    gh-114070: correct the specification of ``digit`` in the float() docs (…

    4f24b92
  11. miss-islington
    added 2 commits that reference this issue on Jan 15, 2024

    pythongh-114070: correct the specification of ``digit`` in the float(…

    1d4fbaf

    pythongh-114070: correct the specification of ``digit`` in the float(…

    ced0c59
  12. hauntsaninja
    added 2 commits that reference this issue on Jan 15, 2024

    [3.12] gh-114070: correct the specification of ``digit`` in the float…

    f6315ed

    [3.11] gh-114070: correct the specification of ``digit`` in the float…

    76433f8
  13. hauntsaninja commented on Jan 15, 2024

    @hauntsaninja
    hauntsaninja
    on Jan 15, 2024
    Contributor
    More actions

    Thanks knotapun, skirpichev and hugovk!!

    Reacted by Hugo van Kemenade
  14. hauntsaninja
    closed this as completedon Jan 15, 2024
  15. hugovk commented on Jan 16, 2024

    @hugovk
    hugovk
    on Jan 16, 2024
    Member
    More actions

    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
    
    Reacted by Alex Waygood
  16. skirpichev
    added a commit that references this issue on Jan 17, 2024

    pythongh-114070: fix token reference warnings in expressions.rst

    376323c
  17. hugovk
    added a commit that references this issue on Jan 17, 2024

    gh-114070: fix token reference warnings in expressions.rst (#114169)

    029ecee
  18. miss-islington
    added 2 commits that reference this issue on Jan 17, 2024

    pythongh-114070: fix token reference warnings in expressions.rst (pyt…

    1b385ab

    pythongh-114070: fix token reference warnings in expressions.rst (pyt…

    a2a3769
  19. hugovk
    added 2 commits that reference this issue on Jan 17, 2024

    [3.12] gh-114070: fix token reference warnings in expressions.rst (GH…

    74a6b7f

    [3.11] gh-114070: fix token reference warnings in expressions.rst (GH…

    654c70a
  20. kulikjak
    added 2 commits that reference this issue on Jan 22, 2024

    pythongh-114070: correct the specification of ``digit`` in the float(…

    3ac8cc6

    pythongh-114070: fix token reference warnings in expressions.rst (pyt…

    3c1a8e6
  21. aisk
    added 2 commits that reference this issue on Feb 11, 2024

    pythongh-114070: correct the specification of ``digit`` in the float(…

    a7faebe

    pythongh-114070: fix token reference warnings in expressions.rst (pyt…

    4c7772e
  22. Glyphack
    added 2 commits that reference this issue on Sep 2, 2024

    pythongh-114070: correct the specification of ``digit`` in the float(…

    6f5b90d

    pythongh-114070: fix token reference warnings in expressions.rst (pyt…

    0a6c106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.