Skip to content

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

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

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

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 25328b3 into python:3.14 Oct 22, 2026
49 checks passed
@lysnikolaou
lysnikolaou deleted the backport-86758d1-3.14 branch October 22, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant