-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
AST: FomattedValue conversion's default value should be -1 #90447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
An unexpected behavior lookup: >>> ast.FormattedValue(ast.Str('ss')).conversion
>>> ast.unparse(ast.FormattedValue(ast.Str('ss')))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/ast.py", line 1564, in unparse
return unparser.visit(ast_obj)
File "/usr/local/lib/python3.9/ast.py", line 801, in visit
self.traverse(node)
File "/usr/local/lib/python3.9/ast.py", line 795, in traverse
super().visit(node)
File "/usr/local/lib/python3.9/ast.py", line 407, in visit
return visitor(node)
File "/usr/local/lib/python3.9/ast.py", line 1153, in visit_FormattedValue
self._fstring_FormattedValue(node, self.buffer_writer)
File "/usr/local/lib/python3.9/ast.py", line 1178, in _fstring_FormattedValue
conversion = chr(node.conversion)
TypeError: an integer is required (got type NoneType)
>>> ast.unparse(ast.FormattedValue(ast.Str('ss'), -1))
'f"{\'ss\'}"' ast.FormattedValue conversion's default value is expected to be -1 but not None See: https://docs.python.org/3/library/ast.html#ast.FormattedValue Other: If certainly, it's also a bug on typeshed. |
ASDL technically allows it to be None though neither compiler nor ast.unparse can work with it at this moment.
>>> 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: I'd say A, since this was always broken. @pablogsal @lys.nikolaou WDYT? |
I agree that A is probably the way to go. |
I think A is the best option |
Should we backport this? On Sat, Jan 8, 2022, 12:05 AM miss-islington <[email protected]> wrote:
|
I would say yes, for consistency. It doesn't have any effects on user code that I am aware |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: