[issue39760] ast.FormattedValue.format_spec unnecessarily wrapped in JoinedStr
Eric V. Smith
report at bugs.python.org
Wed Feb 26 10:22:03 EST 2020
Eric V. Smith <eric at trueblade.com> added the comment:
I agree that could probably be simplified, if the format_spec is constant (which it need not be).
>>> ast.dump(ast.parse('f"is {x:d}"'))
"Module(body=[Expr(value=JoinedStr(values=[Str(s='is '), FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1, format_spec=JoinedStr(values=[Str(s='d')]))]))])"
But:
ast.dump(ast.parse('f"is {x:{length+1}d}"'))
"Module(body=[Expr(value=JoinedStr(values=[Str(s='is '), FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1, format_spec=JoinedStr(values=[FormattedValue(value=BinOp(left=Name(id='length', ctx=Load()), op=Add(), right=Num(n=1)), conversion=-1, format_spec=None), Str(s='d')]))]))])"
----------
nosy: +eric.smith
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39760>
_______________________________________
More information about the Python-bugs-list
mailing list