ast: FormattedValue.conversion cannot be None (#7810)

```
In [4]: ast.dump(ast.parse('f"{x!r}"'))
Out[4]: "Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=114)]))], type_ignores=[])"

In [5]: ast.dump(ast.parse('f"{x}"'))
Out[5]: "Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1)]))], type_ignores=[])"
```
(On 3.9 but I don't think this has changed since 3.6.)

The stdlib also assumes this: https://github.com/python/cpython/blob/main/Lib/ast.py#L1211 (`chr(None)` doesn't work).
This commit is contained in:
Jelle Zijlstra
2022-05-08 19:42:38 -07:00
committed by GitHub
parent 32f474d6ef
commit 5c13f8bbce
2 changed files with 5 additions and 1 deletions

View File

@@ -319,7 +319,7 @@ class FormattedValue(expr):
if sys.version_info >= (3, 10):
__match_args__ = ("value", "conversion", "format_spec")
value: expr
conversion: int | None
conversion: int
format_spec: expr | None
class JoinedStr(expr):