]> granicus.if.org Git - python/commitdiff
Allow decorators and return annotations to be used together (fixes SF#1697248)
authorNick Coghlan <ncoghlan@gmail.com>
Mon, 23 Apr 2007 11:05:01 +0000 (11:05 +0000)
committerNick Coghlan <ncoghlan@gmail.com>
Mon, 23 Apr 2007 11:05:01 +0000 (11:05 +0000)
Lib/test/test_grammar.py
Python/ast.c

index bd04735dab018df9e24151da367d55ec349bb856..85be05bc810b9f3faf372d2e7e6196985bb8c0f4 100644 (file)
@@ -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
index 1bd1430fdffcc2d697d9aaef313dd0a20c50f89d..f8bcdf291abc3268d71b087c1013e162b0ebc017 100644 (file)
@@ -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;