You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parts of strings that look like comments being stripped out of nested strings with debug specifier #135148
$ ./python -m ast
f'{""" # this is part of the string, it shouldn't be stripped out
"""=}'
Module(
body=[
Expr(
value=JoinedStr(
values=[
Constant(value='""" \n"""='),
FormattedValue(
value=Constant(value=" # this is part of the string, it shouldn't be stripped out\n"),
conversion=114)]))])
$ ./python -m ast
t'{""" # this is part of the string, it shouldn't be stripped out
"""=}'
Module(
body=[
Expr(
value=TemplateStr(
values=[
Constant(value='""" \n"""='),
Interpolation(
value=Constant(value=" # this is part of the string, it shouldn't be stripped out\n"),
str='""" \n"""',
conversion=114)]))])
changed the title [-]Parts of strings that look like comments being stripped out of multiline strings[/-][+]Parts of strings that look like comments being stripped out of nested strings with debug specifier[/+]on Jun 5, 2025
This is actually a regression in 3.12, likely due to PEP-701:
$ uv run --python=3.12 python
Python 3.12.2 (main, May 6 2024, 20:50:52) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f'{" # no "=}'
'" \' # no \''
>>>
$ uv run --python=3.11 python
Python 3.11.11 (main, Feb 12 2025, 15:06:01) [Clang 19.1.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f'{" # no "=}'
'" # no "=\' # no \''
$ ./python -m ast
t'{" # no "}'
Module(
body=[
Expr(
value=TemplateStr(
values=[
Interpolation(
value=Constant(value=' # no '),
str='"',
conversion=-1)]))])
Could this be problematic?
>>>t'{" ! important information ! "}'.interpolations
(Interpolation(' ! important information ! ', '" ! important information ! "', None, ''),)
>>>t'{" # important information # "}'.interpolations
(Interpolation(' # important information # ', '"', None, ''),)
Oof, yeah, this was probably introduced in #112284. We'll need to fix it, but the fix is not exactly straight-forward. I'll take a deeper look tomorrow.
Activity
JelleZijlstra commentedon Jun 5, 2025
Yeah this is clearly wrong. cc @pablogsal @lysnikolaou
[-]Parts of strings that look like comments being stripped out of multiline strings[/-][+]Parts of strings that look like comments being stripped out of nested strings with debug specifier[/+]JelleZijlstra commentedon Jun 5, 2025
This is actually a regression in 3.12, likely due to PEP-701:
Removing the release blocker label as it's old.
tom-pytel commentedon Jun 5, 2025
Not just debug specifier, note the
.strfield:Could this be problematic?
lysnikolaou commentedon Jun 5, 2025
Oof, yeah, this was probably introduced in #112284. We'll need to fix it, but the fix is not exactly straight-forward. I'll take a deeper look tomorrow.
tom-pytel commentedon Jun 5, 2025
Not sure if this would apply in the context of the parser but worked for me before I realized it wasn't matching up.
In range of interest exclude all lines which have multiline strings which do not end on the line.
For each remaining line store maximum end column of expressions that end on that line and restrict comment checks to past this column.
2 remaining items
pythongh-135148: Correctly handle f/t strings with comments and debug…
pythongh-135148: Correctly handle f/t strings with comments and debug…
pythongh-135148: Correctly handle f/t strings with comments and debug…
gh-135148: Correctly handle f/t strings with comments and debug expre…
pythongh-135148: Correctly handle f/t strings with comments and debug…
[3.14] gh-135148: Correctly handle f/t strings with comments and debu…
[3.13] gh-135148: Correctly handle f/t strings with comments and debu…
lysnikolaou commentedon Jul 21, 2025
All merged now.
pythongh-135148: Correctly handle f/t strings with comments and debug…
pythongh-135148: Correctly handle f/t strings with comments and debug…
[3.14] pythongh-135148: Correctly handle f/t strings with comments an…