Skip to content

f string with outer and inner double quotes produce no syntax issue in python 3.13, but it does on previous versions. #134111

Closed as not planned
@orlando-fbn

Description

@orlando-fbn

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 example f"…{x.get("inner")}…") raises a SyntaxError. In Python 3.13, however, the same invalid code is accepted at compile time, leading to silent misparsing.


Steps to Reproduce

  1. Create a file broken_fstring.py:
# broken_fstring.py

def foo():
    # This *should* be a SyntaxError:
    x = {}
    yield f"Hello, {x.get("inner")}!"
  1. 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 '('
  1. 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 file
cat > 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions