Skip to content
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

It's undocumented, that comma is invalid as separator for "b", "o" and "x" integer types #127852

Closed
skirpichev opened this issue Dec 12, 2024 · 2 comments
Labels
docs Documentation in the Doc dir

Comments

@skirpichev
Copy link
Member

skirpichev commented Dec 12, 2024

>>> format(12347834, '_x')
'bc_69ba'
>>> format(12347834, ',x')
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    format(12347834, ',x')
    ~~~~~~^^^^^^^^^^^^^^^^
ValueError: Cannot specify ',' with 'x'.
>>> format(12347834, ',b')
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    format(12347834, ',b')
    ~~~~~~^^^^^^^^^^^^^^^^
ValueError: Cannot specify ',' with 'b'.
>>> format(12347834, ',o')
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    format(12347834, ',o')
    ~~~~~~^^^^^^^^^^^^^^^^
ValueError: Cannot specify ',' with 'o'.
>>> format(12347834, ',d')
'12,347,834'
>>> format(12347111111111834, ',f')
'12,347,111,111,111,834.000000'

Linked PRs

@skirpichev skirpichev added the docs Documentation in the Doc dir label Dec 12, 2024
@skirpichev skirpichev self-assigned this Dec 12, 2024
skirpichev added a commit to skirpichev/cpython that referenced this issue Dec 12, 2024
@skirpichev skirpichev removed their assignment Dec 12, 2024
@terryjreedy
Copy link
Member

Same when using format strings.
f'{12347834:,x}' Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> f'{12347834:,x}' ValueError: Cannot specify ',' with 'x'.
As I remember, the f-string doc refers to the Format Specification Mini-Language section modified by the patch.

@skirpichev
Copy link
Member Author

the f-string doc refers to the Format Specification Mini-Language section modified by the patch.

Yes: https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals

Top-level format specifiers may include nested replacement fields. These nested fields may include their own conversion fields and format specifiers, but may not include more deeply nested replacement fields. The format specifier mini-language is the same as that used by the str.format() method.

terryjreedy added a commit that referenced this issue Dec 14, 2024
Specify that it is valid for floats and ints with 'd' presentation and an error otherwise.

Co-authored-by: Terry Jan Reedy <[email protected]>

---------

Co-authored-by: Terry Jan Reedy <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 14, 2024
Specify that it is valid for floats and ints with 'd' presentation and an error otherwise.

Co-authored-by: Terry Jan Reedy <[email protected]>

---------

(cherry picked from commit e2325c9)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 14, 2024
Specify that it is valid for floats and ints with 'd' presentation and an error otherwise.

Co-authored-by: Terry Jan Reedy <[email protected]>

---------

(cherry picked from commit e2325c9)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
terryjreedy added a commit that referenced this issue Dec 14, 2024
Specify that it is valid for floats and ints with 'd' presentation and an error otherwise.
---------

(cherry picked from commit e2325c9)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
terryjreedy added a commit that referenced this issue Dec 14, 2024
Specify that it is valid for floats and ints with 'd' presentation and an error otherwise.
---------

(cherry picked from commit e2325c9)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
Specify that it is valid for floats and ints with 'd' presentation and an error otherwise.

Co-authored-by: Terry Jan Reedy <[email protected]>

---------

Co-authored-by: Terry Jan Reedy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

2 participants