Skip to content

Error in Format Specification Mini-Language concerning precision_with_grouping in 3.14 #134449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonathanpoelen opened this issue May 21, 2025 · 4 comments
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@jonathanpoelen
Copy link

jonathanpoelen commented May 21, 2025

Documentation

On this page: https://docs.python.org/3.14/library/string.html#grammar-token-format-spec-format_spec

format_spec:             [options][width_and_precision][type]
options:                 [[fill]align][sign]["z"]["#"]["0"]
fill:                    <any character>
align:                   "<" | ">" | "=" | "^"
sign:                    "+" | "-" | " "
width_and_precision:     [width_with_grouping][precision_with_grouping]
width_with_grouping:     [width][grouping]
precision_with_grouping: "." [precision][grouping]
width:                   digit+
precision:               digit+
grouping:                "," | "_"
type:                    "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g"
                         | "G" | "n" | "o" | "s" | "x" | "X" | "%"

The precision_with_grouping syntaxe is wrong, because it accepts . without precision or grouping. But

>>> f'{1234.1234:.f}'
Traceback (most recent call last):
  File "<python-input-17>", line 1, in <module>
    f'{1234.1234:.f}'
      ^^^^^^^^^^^^^^
ValueError: Format specifier missing precision

(The error does not mention grouping either)

The right syntax should be

precision_with_grouping: "." precision [grouping] | "." grouping

Linked PRs

@jonathanpoelen jonathanpoelen added the docs Documentation in the Doc dir label May 21, 2025
@picnixz
Copy link
Member

picnixz commented May 23, 2025

cc @skirpichev This is something we did right? I don't remember the issue/PR

@picnixz picnixz added type-bug An unexpected behavior, bug, or error 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels May 23, 2025
@skirpichev
Copy link
Member

Yes, it's not accurate, see #125304 (review). I forgot that, lets fix this.

@jonathanpoelen, would you like to propose a pr?

@skirpichev skirpichev self-assigned this May 23, 2025
@jonathanpoelen
Copy link
Author

I'll let you do the pr :)

skirpichev added a commit to skirpichev/cpython that referenced this issue May 24, 2025
…scription

This amends f39a07b.  Thanks to Jonathan Poelen.
@skirpichev skirpichev removed their assignment May 25, 2025
@skirpichev
Copy link
Member

PR is ready to review: #134608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
Projects
Status: Todo
Development

No branches or pull requests

3 participants