summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-01-05 02:14:58 (GMT)
committerGitHub <noreply@github.com>2020-01-05 02:14:58 (GMT)
commit859525590c7aad210ae5f2557140a52033c498cd (patch)
tree6a61c52faf673b88e8fcb9537c47c19b7ab20af3
parent867d8333ce6a7f74191ad464acc609d4a04e4acb (diff)
downloadcpython-859525590c7aad210ae5f2557140a52033c498cd.zip
cpython-859525590c7aad210ae5f2557140a52033c498cd.tar.gz
cpython-859525590c7aad210ae5f2557140a52033c498cd.tar.bz2
Fix SystemError when nested function has annotation on positional-only argument (GH-17826)
(cherry picked from commit ec007cb43faf5f33d06efbc28152c7fdcb2edb9c) Co-authored-by: Anthony Sottile <asottile@umich.edu>
-rw-r--r--Lib/test/test_positional_only_arg.py7
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2020-01-04-17-25-34.bpo-39215.xiqiIz.rst2
-rw-r--r--Python/symtable.c2
3 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_positional_only_arg.py b/Lib/test/test_positional_only_arg.py
index 59b0b8f..63dee7c 100644
--- a/Lib/test/test_positional_only_arg.py
+++ b/Lib/test/test_positional_only_arg.py
@@ -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
index 0000000..9a3178f
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-01-04-17-25-34.bpo-39215.xiqiIz.rst
@@ -0,0 +1,2 @@
+Fix ``SystemError`` when nested function has annotation on positional-only
+argument - by Anthony Sottile.
diff --git a/Python/symtable.c b/Python/symtable.c
index b871358..30482d9 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -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)