Skip to content

gh-146448: fix t-string parser truncating expression at != with format spec#146614

Open
joshuaswanson wants to merge 1 commit intopython:mainfrom
joshuaswanson:fix/tstring-exclamation-parser
Open

gh-146448: fix t-string parser truncating expression at != with format spec#146614
joshuaswanson wants to merge 1 commit intopython:mainfrom
joshuaswanson:fix/tstring-exclamation-parser

Conversation

@joshuaswanson
Copy link
Copy Markdown

Fixes #146448.

The lexer treats ! inside f-string/t-string expressions as a conversion specifier marker, which causes the expression text to be truncated at !. For !=, this incorrectly sets Interpolation.str to just the part before ! (e.g. t'{0!=0:}' produces str='0' instead of str='0!=0'). The bug only triggers when a format spec follows (:) because without it, the expression end is determined by } instead.

The fix peeks at the character following ! using tok_nextc/tok_backup and only treats it as f-string punctuation when it's not followed by =.

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.

parser: cpython parser bug in template strings t'{0!=0:}'

1 participant