Skip to content

[3.15] gh-160268: Fix tokenize on a mismatched closing bracket in an f-string (GH-160272) - #160335

Merged
lysnikolaou merged 2 commits into
python:3.15from
lysnikolaou:backport-86758d1-3.15
Oct 22, 2026
Merged

lysnikolaou merged 2 commits into
python:3.15from
lysnikolaou:backport-86758d1-3.15

Conversation

@lysnikolaou

@lysnikolaou lysnikolaou commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Since gh-105042, tokenize tolerates mismatched brackets. That also let a mismatched closing bracket pop the brace that opened an f-string replacement field, which the f-string state relies on. In f'{]a', this triggered an assertion failure in _PyLexer_scan_string.

Check the replacement field brace in both modes.
(cherry picked from commit 86758d1)

…in an f-string (pythonGH-160272)

Since pythongh-105042, `tokenize` tolerates mismatched brackets. That also let
a mismatched closing bracket pop the brace that opened an f-string
replacement field, which the f-string state relies on. In `f'{]a'`, this
triggered an assertion failure in _PyLexer_scan_string.

Check the replacement field brace in both modes.
(cherry picked from commit 86758d1)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
@lysnikolaou
lysnikolaou merged commit 90d0d66 into python:3.15 Oct 22, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant