Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Closed as not planned
Description
Bug report
Bug description:
Bug Report: f-string Regression in Python 3.13 Parser
Python Versions
- 3.11 – correctly rejects inner/outer matching‐quote f-strings
- 3.13 – silently accepts invalid f-string syntax
Issue Type
Parser / grammar regression
Description
In Python 3.11 and earlier, an f-string whose inner quotes match the outer quotes (for examplef"…{x.get("inner")}…"
) raises aSyntaxError
. In Python 3.13, however, the same invalid code is accepted at compile time, leading to silent misparsing.
Steps to Reproduce
- Create a file
broken_fstring.py
:
# broken_fstring.pydeffoo():# This *should* be a SyntaxError:x= {}yieldf"Hello,{x.get("inner")}!"
- Under Python 3.11:
python3.11 -m py_compile broken_fstring.py
Expected:
File "reportlib/report_generator/python_bug.py", line 7 yield f"Hello, {x.get("inner")}!" ^^^^^SyntaxError: f-string: unmatched '('
- Under Python 3.13:
python3.13 -m py_compile broken_fstring.py
Actual: no error, exit code 0.
Expected Behavior
The compiler should reject the invalid f-string syntax in all supported versions, consistent with PEP 498.
Minimal Test Case
# Create the test filecat> broken_fstring.py<< 'EOF'def foo(): x = {} yield f"Hello, {x.get("inner")}!"EOF
Under 3.11:
python3.11 -m py_compile broken_fstring.py # raises SyntaxError
Under 3.13:
python3.13 -m py_compile broken_fstring.py # silently succeeds
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Metadata
Metadata
Assignees
Labels
No labels