From f3233fd4a2489b4b5b2b24d8ef134785daad87ab Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 8 May 2022 18:06:12 -0700 Subject: [PATCH 1/5] ast: FormattedValue.conversion cannot be None ``` 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). --- stdlib/_ast.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_ast.pyi b/stdlib/_ast.pyi index cb13c7452081..1305b0c94d9b 100644 --- a/stdlib/_ast.pyi +++ b/stdlib/_ast.pyi @@ -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): From ced7fbce31803345a903a8d26eee790bd987eaf3 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 8 May 2022 18:15:23 -0700 Subject: [PATCH 2/5] ignore stubtest --- tests/stubtest_allowlists/py3_common.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 89f80407514d..b0e8f261b3ee 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -685,6 +685,9 @@ pkgutil.ImpLoader.is_package pkgutil.ImpLoader.load_module pkgutil.ImpLoader.source +# None on the class, but never None on instances +_ast.FormattedValue.conversion + # ========== # Exists at runtime, but missing from stubs # ========== From 9f879540089122c05d7e1c6d039caa5b268525c9 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 8 May 2022 18:47:40 -0700 Subject: [PATCH 3/5] Update tests/stubtest_allowlists/py3_common.txt --- tests/stubtest_allowlists/py3_common.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index b0e8f261b3ee..53d44b4614f9 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -686,7 +686,7 @@ pkgutil.ImpLoader.load_module pkgutil.ImpLoader.source # None on the class, but never None on instances -_ast.FormattedValue.conversion +ast.FormattedValue.conversion # ========== # Exists at runtime, but missing from stubs From ed7f2769365cf7dae854ec92f35bd7fb5492b0f7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 8 May 2022 18:52:14 -0700 Subject: [PATCH 4/5] Update tests/stubtest_allowlists/py3_common.txt --- tests/stubtest_allowlists/py3_common.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 53d44b4614f9..7807d7a81ea6 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -687,6 +687,7 @@ pkgutil.ImpLoader.source # None on the class, but never None on instances ast.FormattedValue.conversion +_ast.FormattedValue.conversion # ========== # Exists at runtime, but missing from stubs From ecea14d7be7c14f8756b2e281845dad7073076cb Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 8 May 2022 19:07:41 -0700 Subject: [PATCH 5/5] only on 3.9 --- tests/stubtest_allowlists/py39.txt | 4 ++++ tests/stubtest_allowlists/py3_common.txt | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index 47992c880177..b947ee091b55 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -164,3 +164,7 @@ typing._SpecialForm.__mro_entries__ unicodedata.UCD.is_normalized xml.parsers.expat.XMLParserType.SkippedEntityHandler xml.parsers.expat.XMLParserType.intern + +# None on the class, but never None on instances +ast.FormattedValue.conversion +_ast.FormattedValue.conversion diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 7807d7a81ea6..89f80407514d 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -685,10 +685,6 @@ pkgutil.ImpLoader.is_package pkgutil.ImpLoader.load_module pkgutil.ImpLoader.source -# None on the class, but never None on instances -ast.FormattedValue.conversion -_ast.FormattedValue.conversion - # ========== # Exists at runtime, but missing from stubs # ==========