Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-139516: Fix lambda colon start format spec in f-string in tokenizer#139657
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
tom-pytel commentedOct 6, 2025
Ping@pablogsal. I added the test to |
pablogsal commentedOct 6, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Please add a rest for the f-string test file as well as this will be a semantic test that needs to hold true even if we change the tokenizer of some other implementation doesn't have the same tokenizer |
Lib/test/test_fstring.py Outdated
| # gh-139516 | ||
| # The '\n' is explicit to ensure no trailing whitespace which would invalidate the test. | ||
| # Must use tokenize instead of compile so that source is parsed by line which exposes the bug. | ||
| list(tokenize.tokenize(BytesIO('''f"{f(a=lambda: 'à'\n)}"'''.encode()).readline)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I am confused. Isn't it possible to trigger this in anexec oreval call? Or perhaps a file with an encoding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
See below VVV
tom-pytel commentedOct 6, 2025
Done. But I had to use Let me know if this test is good enough or if you want something else. |
pablogsal commentedOct 6, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
yes, going via the tokenizer makes no sense here. The pourpose of what I asked is that alternative implementations will still run these tests files to check if they are compliant and we need to provide a way to run a file or exec some code and say "this is what we expect". You are triggering the bug via a specific aspect of CPython but I would prefer if we could trigger it end-to-end via a file. There are more tests executing python over files, check in |
tom-pytel commentedOct 6, 2025
Running error as script. |
pablogsal commentedOct 7, 2025
LGTM Thank you very much@tom-pytel ! |
539461d intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@tom-pytel for the PR, and@pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…kenizer (pythonGH-139657)(cherry picked from commit539461d)Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
Sorry,@tom-pytel and@pablogsal, I could not cleanly backport this to |
GH-139701 is a backport of this pull request to the3.14 branch. |
pablogsal commentedOct 7, 2025
@tom-pytel can you make the backport following the instructions? |
tom-pytel commentedOct 7, 2025
Sure, in a bit. |
GH-139726 is a backport of this pull request to the3.13 branch. |
Uh oh!
There was an error while loading.Please reload this page.
A
=followed by a:in an f-string expression could cause the tokenizer to erroneously think it was starting a format spec, leading to incorrect internal state and possible decode errors if this results in split unicode characters on copy. This PR fixes this by disallowing=to setin_debugstate unless it is encountered at the top level of an f-string expression.This problem exists back to py 3.13 and this PR can probably be backported easily enough.