Browse Source

Fix SystemError when nested function has annotation on positional-only argument (GH-17826)

pull/17828/head
Anthony Sottile 6 years ago
committed by Pablo Galindo
parent
commit
ec007cb43f
  1. 7
      Lib/test/test_positional_only_arg.py
  2. 2
      Misc/NEWS.d/next/Core and Builtins/2020-01-04-17-25-34.bpo-39215.xiqiIz.rst
  3. 2
      Python/symtable.c

7
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()

2
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.

2
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)

Loading…
Cancel
Save