Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71011e2

Browse files
committed
Allow decorators and return annotations to be used together (fixes SF#1697248)
1 parent 4138bfe commit 71011e2

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/test/test_grammar.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6, h:7, i=8, j:9=10,
322322
self.assertEquals(f.__annotations__,
323323
{'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9,
324324
'k': 11, 'return': 12})
325-
325+
# Check for SF Bug #1697248 - mixing decorators and a return annotation
326+
def null(x): return x
327+
@null
328+
def f(x) -> list: pass
329+
self.assertEquals(f.__annotations__, {'return': list})
330+
326331
# test MAKE_CLOSURE with a variety of oparg's
327332
closure = 1
328333
def f(): return closure

Python/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ ast_for_funcdef(struct compiling *c, const node *n)
983983

984984
REQ(n, funcdef);
985985

986-
if (NCH(n) == 6) { /* decorators are present */
986+
if (NCH(n) == 6 || NCH(n) == 8) { /* decorators are present */
987987
decorator_seq = ast_for_decorators(c, CHILD(n, 0));
988988
if (!decorator_seq)
989989
return NULL;

0 commit comments

Comments
 (0)