]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix SystemError when nested function has annotation on positional-only argument ...
authorAnthony Sottile <asottile@umich.edu>
Sun, 5 Jan 2020 01:57:21 +0000 (20:57 -0500)
committerPablo Galindo <Pablogsal@gmail.com>
Sun, 5 Jan 2020 01:57:21 +0000 (01:57 +0000)
Lib/test/test_positional_only_arg.py
Misc/NEWS.d/next/Core and Builtins/2020-01-04-17-25-34.bpo-39215.xiqiIz.rst [new file with mode: 0644]
Python/symtable.c

index 59b0b8fb55621c4dabe8de88e7476cae7c967f47..63dee7ca434b21f601b3545db0f43c6ff0b770b2 100644 (file)
@@ -15,6 +15,10 @@ def global_pos_only_and_normal(a, /, b):
 def global_pos_only_defaults(a=1, /, b=2):
     return a, b
 
+def global_inner_has_pos_only():
+    def f(x: int, /): ...
+    return f
+
 
 class PositionalOnlyTestCase(unittest.TestCase):
 
@@ -412,6 +416,9 @@ class PositionalOnlyTestCase(unittest.TestCase):
 
         self.assertEqual(C().method(), sentinel)
 
+    def test_annotations(self):
+        assert global_inner_has_pos_only().__annotations__ == {'x': int}
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-01-04-17-25-34.bpo-39215.xiqiIz.rst b/Misc/NEWS.d/next/Core and Builtins/2020-01-04-17-25-34.bpo-39215.xiqiIz.rst
new file mode 100644 (file)
index 0000000..9a3178f
--- /dev/null
@@ -0,0 +1,2 @@
+Fix ``SystemError`` when nested function has annotation on positional-only
+argument - by Anthony Sottile.
index b8713588b9a91495c9c9a0702fa03d1970cfee36..30482d99b3ca927c2034c0e3e84fb202179b2756 100644 (file)
@@ -1717,6 +1717,8 @@ static int
 symtable_visit_annotations(struct symtable *st, stmt_ty s,
                            arguments_ty a, expr_ty returns)
 {
+    if (a->posonlyargs && !symtable_visit_argannotations(st, a->posonlyargs))
+        return 0;
     if (a->args && !symtable_visit_argannotations(st, a->args))
         return 0;
     if (a->vararg && a->vararg->annotation)