Skip to content

[3.13] gh-154711: Strip comments after escaped quotes in f-string debug text - #158310

Merged
pablogsal merged 1 commit into
python:3.13from
ArneshBanerjee:gh-154711-3.13
Sep 29, 2026
Merged

pablogsal merged 1 commit into
python:3.13from
ArneshBanerjee:gh-154711-3.13

Conversation

@ArneshBanerjee

Copy link
Copy Markdown

When a replacement field ended with a string that had an escaped quote and was followed by a comment, the comment leaked into the debug f-string output.

The comment detection loop in set_fstring_expr skips escaped characters, but the comment stripping loop did not. So an escaped quote left the scanner thinking it was still inside a string, and the comment was never removed.

This makes the stripping loop skip escaped characters the same way the detection loop does. 3.14 and 3.15 already have the same fix from the gh-154719 backports, and main is not affected after gh-153569, so this is 3.13 only. The tests for main are in #158220.

Replaces #154914.

…ng debug text

When a replacement field ended with a string that had an escaped quote and
was followed by a comment, the comment leaked into the debug f-string output.

The comment detection loop in set_fstring_expr skips escaped characters, but
the comment stripping loop did not. So an escaped quote left the scanner
thinking it was still inside a string, and the comment was never removed.

This makes the stripping loop skip escaped characters the same way the
detection loop does. 3.14 and later already have this fix from pythongh-154719.
@Yhg1s

Yhg1s commented Sep 29, 2026

Copy link
Copy Markdown
Member

@pablogsal this is a continuation of #154914, do you want this in tomorrow's 3.13?

@pablogsal

Copy link
Copy Markdown
Member

@pablogsal this is a continuation of #154914, do you want this in tomorrow's 3.13?

yes pls

@pablogsal
pablogsal merged commit 4192ead into python:3.13 Sep 29, 2026
44 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.

3 participants