Skip to content

Commit ec007cb

Browse files
asottilepablogsal
authored andcommitted
Fix SystemError when nested function has annotation on positional-only argument (GH-17826)
1 parent 7dc72b8 commit ec007cb

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Lib/test/test_positional_only_arg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def global_pos_only_and_normal(a, /, b):
1515
def global_pos_only_defaults(a=1, /, b=2):
1616
return a, b
1717

18+
def global_inner_has_pos_only():
19+
def f(x: int, /): ...
20+
return f
21+
1822

1923
class PositionalOnlyTestCase(unittest.TestCase):
2024

@@ -412,6 +416,9 @@ def method(self, /):
412416

413417
self.assertEqual(C().method(), sentinel)
414418

419+
def test_annotations(self):
420+
assert global_inner_has_pos_only().__annotations__ == {'x': int}
421+
415422

416423
if __name__ == "__main__":
417424
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``SystemError`` when nested function has annotation on positional-only
2+
argument - by Anthony Sottile.

Python/symtable.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,8 @@ static int
17171717
symtable_visit_annotations(struct symtable *st, stmt_ty s,
17181718
arguments_ty a, expr_ty returns)
17191719
{
1720+
if (a->posonlyargs && !symtable_visit_argannotations(st, a->posonlyargs))
1721+
return 0;
17201722
if (a->args && !symtable_visit_argannotations(st, a->args))
17211723
return 0;
17221724
if (a->vararg && a->vararg->annotation)

0 commit comments

Comments
 (0)