-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
GH-95088: Clarified rules for parsing an item key for format strings. #103779
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
Conversation
|
Hold on, this isn't actually true: >>> "{[0a]}".format([1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers or slices, not str
>>> "{[0a]}".format({"0a": "x"})
'x'This is implemented in cpython/Objects/stringlib/unicode_format.h Line 110 in fbf3596
key.isdecimal(), treat it as an int, else treat it as a string.
That's different from what the PEP said, but it's probably a better idea, so I'd prefer to document this behavior. |
Ah, interesting! Okay updated it to be:
|
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
|
Thanks @achhina for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
|
Sorry @achhina and @JelleZijlstra, I had trouble checking out the |
|
GH-105418 is a backport of this pull request to the 3.11 branch. |
…ngs (pythonGH-103779) (cherry picked from commit 3e7316d) Co-authored-by: achhina <amanschhina@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
|
Thanks @achhina for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…ngs (pythonGH-103779) (cherry picked from commit 3e7316d) Co-authored-by: achhina <amanschhina@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
|
GH-105419 is a backport of this pull request to the 3.12 branch. |
Fixes GH-95088.