gh-121130: Fix f-string format specifiers with debug expressions
- Issue: gh-121130
@lysnikolaou do you mind taking a look at this approach? I think is not too bad and it solidifies a bit more the concept of being in a format spec
@lysnikolaou Ugh... this is much more complicated indeed. We need to restructure how we propagate the format specifier and how we capture the f-string expressions on format specifiers :(
Also the AST is so weird because it removes {. Check this out:
python3.11 -m ast <<< 'f"{datetime.datetime.now():h1{y2=}}"'
Module(
body=[
Expr(
value=JoinedStr(
values=[
FormattedValue(
value=Call(
func=Attribute(
value=Attribute(
value=Name(id='datetime', ctx=Load()),
attr='datetime',
ctx=Load()),
attr='now',
ctx=Load()),
args=[],
keywords=[]),
conversion=-1,
format_spec=JoinedStr(
values=[
Constant(value='h1y2='),
FormattedValue(
value=Name(id='y2', ctx=Load()),
conversion=114)]))]))],
type_ignores=[])
notice that the node is h1y2 without the { in the middle :S
I think this should do the trick. Boy this was hard to fix :S
Hummm I will investigate the failure soon
@lysnikolaou can you take another look so we can get this into rc1?
I'm landing so this gets into the last 3.13 beta to get some coverage. We can fix anything @lysnikolaou doesn't like later
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. 🐍🍒⛏🤖
Sorry, @pablogsal, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker c46d64e0ef8e92a6b4ab4805d813d7e4d6663380 3.13
Sorry, @pablogsal, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker c46d64e0ef8e92a6b4ab4805d813d7e4d6663380 3.12
GH-121868 is a backport of this pull request to the 3.13 branch.
GH-122063 is a backport of this pull request to the 3.12 branch.