Skip to content

Commit 5c13f8b

Browse files
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).
1 parent 32f474d commit 5c13f8b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

stdlib/_ast.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class FormattedValue(expr):
319319
if sys.version_info >= (3, 10):
320320
__match_args__ = ("value", "conversion", "format_spec")
321321
value: expr
322-
conversion: int | None
322+
conversion: int
323323
format_spec: expr | None
324324

325325
class JoinedStr(expr):

tests/stubtest_allowlists/py39.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,7 @@ typing._SpecialForm.__mro_entries__
164164
unicodedata.UCD.is_normalized
165165
xml.parsers.expat.XMLParserType.SkippedEntityHandler
166166
xml.parsers.expat.XMLParserType.intern
167+
168+
# None on the class, but never None on instances
169+
ast.FormattedValue.conversion
170+
_ast.FormattedValue.conversion

0 commit comments

Comments
 (0)