classification
Title: f-string error description seems wrong
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, han-solo, miss-islington
Priority: normal Keywords: patch

Created on 2020-08-31 18:40 by han-solo, last changed 2020-09-02 06:09 by han-solo. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22036 merged han-solo, 2020-08-31 20:51
PR 22041 merged miss-islington, 2020-09-01 14:35
PR 22059 merged han-solo, 2020-09-02 06:09
Messages (6)
msg376160 - (view) Author: Hanish (han-solo) * Date: 2020-08-31 18:40
There seems to an error in the `f-string` error description when one do:


>>> f'{1:,,}'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Cannot specify both ',' and '_'.
>>> 

The error seems to be that, i am not specifying both ',' and '_', but it does seem to think so.

This also seems to be happening for `str.format`:

>>> '{:,,}'.format(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Cannot specify both ',' and '_'.


So i was just wondering if this is an issue worth raising :)


Thank you
msg376161 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-08-31 18:43
It has to do with how the specification for the mini-language is parsed and how the defaults work. It could probably be fixed, but I'm personally not super motivated to track it down. But I'd look at a patch!

I'm going to remove versions that we wouldn't backport this to.
msg376162 - (view) Author: Hanish (han-solo) * Date: 2020-08-31 18:46
Sure. Thanks for the quick response :)

Let me see if i can try to come up with something :)
msg376170 - (view) Author: Hanish (han-solo) * Date: 2020-08-31 22:13
I have raised a pull request for the fix https://github.com/python/cpython/pull/22036. Your review is appreciated :)
msg376192 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-09-01 14:34
New changeset 0d6aa7f0ee38eb453bc8f73bf4830e6172be2f35 by han-solo in branch 'master':
bpo-41681: Fix for `f-string/str.format` error description when using 2 `,` in format specifier (GH-22036)
https://github.com/python/cpython/commit/0d6aa7f0ee38eb453bc8f73bf4830e6172be2f35
msg376195 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-09-01 15:46
New changeset c16a2a1b643d3e04f86780e2c9e66c3f9f322560 by Miss Islington (bot) in branch '3.9':
bpo-41681: Fix for `f-string/str.format` error description when using 2 `,` in format specifier (GH-22036) (GH-22041)
https://github.com/python/cpython/commit/c16a2a1b643d3e04f86780e2c9e66c3f9f322560
History
Date User Action Args
2020-09-02 06:09:55han-solosetpull_requests: + pull_request21150
2020-09-01 15:56:39eric.smithsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-09-01 15:46:06eric.smithsetmessages: + msg376195
2020-09-01 14:35:18miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request21138
2020-09-01 14:34:37eric.smithsetmessages: + msg376192
2020-08-31 22:13:25han-solosetmessages: + msg376170
2020-08-31 20:51:39han-solosetkeywords: + patch
stage: patch review
pull_requests: + pull_request21134
2020-08-31 18:47:07eric.smithsetversions: - Python 3.6, Python 3.7
2020-08-31 18:46:00han-solosetmessages: + msg376162
versions: + Python 3.6, Python 3.7
2020-08-31 18:43:30eric.smithsetmessages: + msg376161
versions: - Python 3.6, Python 3.7
2020-08-31 18:40:25han-solocreate