[issue46289] AST: FomattedValue conversion's default value should be -1
Batuhan Taskaya
report at bugs.python.org
Fri Jan 7 11:10:06 EST 2022
Batuhan Taskaya <isidentical at gmail.com> added the comment:
ASDL technically allows it to be None though neither compiler nor ast.unparse can work with it at this moment.
> FormattedValue(expr value, int? conversion, expr? format_spec)
https://github.com/python/cpython/blob/b127e70a8a682fe869c22ce04c379bd85a00db67/Parser/Python.asdl#L78
>>> import ast
>>> tree = ast.parse("f'{x + 1}'")
>>> tree.body[0].value.values[0].conversion = None
>>> compile(tree, "<test>", "exec")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: Unrecognized conversion character 0
We can either:
A) change ASDL to reflect it is an integer (since it always has been treated that way)
B) Support this on both the compiler as well as in the ast.unparse
I'd say A, since this was always broken. @pablogsal @lys.nikolaou WDYT?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46289>
_______________________________________
More information about the Python-bugs-list
mailing list