summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2007-04-23 11:05:01 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2007-04-23 11:05:01 (GMT)
commit71011e2c2b6511e14099d0a02d8c137bb22784ad (patch)
tree647b4874e1b4b0360b7f314038e7ffe3317c4e36
parent4138bfec0a189d180b7bcb89e7c8ce8a456a6b55 (diff)
downloadcpython-71011e2c2b6511e14099d0a02d8c137bb22784ad.zip
cpython-71011e2c2b6511e14099d0a02d8c137bb22784ad.tar.gz
cpython-71011e2c2b6511e14099d0a02d8c137bb22784ad.tar.bz2
Allow decorators and return annotations to be used together (fixes SF#1697248)
-rw-r--r--Lib/test/test_grammar.py7
-rw-r--r--Python/ast.c2
2 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index bd04735..85be05b 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -322,7 +322,12 @@ class GrammarTests(unittest.TestCase):
self.assertEquals(f.__annotations__,
{'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9,
'k': 11, 'return': 12})
-
+ # Check for SF Bug #1697248 - mixing decorators and a return annotation
+ def null(x): return x
+ @null
+ def f(x) -> list: pass
+ self.assertEquals(f.__annotations__, {'return': list})
+
# test MAKE_CLOSURE with a variety of oparg's
closure = 1
def f(): return closure
diff --git a/Python/ast.c b/Python/ast.c
index 1bd1430..f8bcdf2 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -983,7 +983,7 @@ ast_for_funcdef(struct compiling *c, const node *n)
REQ(n, funcdef);
- if (NCH(n) == 6) { /* decorators are present */
+ if (NCH(n) == 6 || NCH(n) == 8) { /* decorators are present */
decorator_seq = ast_for_decorators(c, CHILD(n, 0));
if (!decorator_seq)
return NULL;