Skip to content

gh-160268: Fix tokenize on a mismatched closing bracket in an f-string - #160272

Merged
lysnikolaou merged 2 commits into
python:mainfrom
lysnikolaou:fix-tokenize-fstring-unmatched-closer
Oct 22, 2026
Merged

lysnikolaou merged 2 commits into
python:mainfrom
lysnikolaou:fix-tokenize-fstring-unmatched-closer

Conversation

@lysnikolaou

@lysnikolaou lysnikolaou commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Since gh-105042, tokenize mode 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.

…-string

Since pythongh-105042, tokenize mode 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.
@lysnikolaou
lysnikolaou merged commit 86758d1 into python:main Oct 22, 2026
60 checks passed
@lysnikolaou
lysnikolaou deleted the fix-tokenize-fstring-unmatched-closer branch October 22, 2026 18:40
@zware zware added needs backport to 3.15 bugs and security fixes and removed needs backport to 3.15 bugs and security fixes labels Oct 22, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @lysnikolaou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @lysnikolaou, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 86758d1950ce2ed2626014b52d26d24c74dee55b 3.15

@lysnikolaou lysnikolaou added needs backport to 3.14 bugs and security fixes and removed needs backport to 3.14 bugs and security fixes labels Oct 22, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @lysnikolaou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @lysnikolaou, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 86758d1950ce2ed2626014b52d26d24c74dee55b 3.14

@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160335 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 22, 2026
@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160336 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 22, 2026
lysnikolaou added a commit that referenced this pull request Oct 22, 2026
…f-string (GH-160272) (#160336)

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)
lysnikolaou added a commit that referenced this pull request Oct 22, 2026
…f-string (GH-160272) (#160335)

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants