Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 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

  1. Create a filebroken_fstring.py:
# broken_fstring.pydeffoo():# This *should* be a SyntaxError:x= {}yieldf"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 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

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp