]> granicus.if.org Git - python/commitdiff
Issue #24687: Plug refleak on SyntaxError in function parameters annotations.
authorYury Selivanov <yselivanov@sprymix.com>
Thu, 23 Jul 2015 06:10:44 +0000 (09:10 +0300)
committerYury Selivanov <yselivanov@sprymix.com>
Thu, 23 Jul 2015 06:10:44 +0000 (09:10 +0300)
Lib/test/test_coroutines.py
Lib/test/test_grammar.py
Misc/NEWS
Python/compile.c

index 94994e548bd3df3ebd5a7782802615e93c372849..14682ca6047b3d2abb7ec9e909ccb8fc43c7eca9 100644 (file)
@@ -211,6 +211,10 @@ class AsyncBadSyntaxTest(unittest.TestCase):
                    pass
             """,
 
+            """async def foo(a:await b):
+                   pass
+            """,
+
             """def baz():
                    async def foo(a=await b):
                        pass
index ca6b5d0c385f5095ad0e2ce299693358dae99567..9b41df1ad864b731a2b514bc2cab3cac4a193c30 100644 (file)
@@ -534,7 +534,8 @@ class GrammarTests(unittest.TestCase):
         # Not allowed at class scope
         check_syntax_error(self, "class foo:yield 1")
         check_syntax_error(self, "class foo:yield from ()")
-
+        # Check annotation refleak on SyntaxError
+        check_syntax_error(self, "def g(a:(yield)): pass")
 
     def test_raise(self):
         # 'raise' test [',' test]
index bbd8e92d65548b10ccc6c1f5c92aed17498fe06d..98b60e8718cf0527cc558e0185ff482bb42e9f5e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,9 @@ Core and Builtins
 - Issue #24619: New approach for tokenizing async/await. As a consequence,
   is is now possible to have one-line 'async def foo(): await ..' functions.
 
+- Issue #24687: Plug refleak on SyntaxError in function parameters
+  annotations.
+
 Library
 -------
 
index 33cc8c22cb86399415a905cdea4c960e57d39a97..027e3abe6813f481c23710297b91bd6e7185717e 100644 (file)
@@ -1559,32 +1559,31 @@ compiler_visit_argannotation(struct compiler *c, identifier id,
         VISIT(c, expr, annotation);
         mangled = _Py_Mangle(c->u->u_private, id);
         if (!mangled)
-            return -1;
+            return 0;
         if (PyList_Append(names, mangled) < 0) {
             Py_DECREF(mangled);
-            return -1;
+            return 0;
         }
         Py_DECREF(mangled);
     }
-    return 0;
+    return 1;
 }
 
 static int
 compiler_visit_argannotations(struct compiler *c, asdl_seq* args,
                               PyObject *names)
 {
-    int i, error;
+    int i;
     for (i = 0; i < asdl_seq_LEN(args); i++) {
         arg_ty arg = (arg_ty)asdl_seq_GET(args, i);
-        error = compiler_visit_argannotation(
+        if (!compiler_visit_argannotation(
                         c,
                         arg->arg,
                         arg->annotation,
-                        names);
-        if (error)
-            return error;
+                        names))
+            return 0;
     }
-    return 0;
+    return 1;
 }
 
 static int
@@ -1604,16 +1603,16 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,
     if (!names)
         return -1;
 
-    if (compiler_visit_argannotations(c, args->args, names))
+    if (!compiler_visit_argannotations(c, args->args, names))
         goto error;
     if (args->vararg && args->vararg->annotation &&
-        compiler_visit_argannotation(c, args->vararg->arg,
+        !compiler_visit_argannotation(c, args->vararg->arg,
                                      args->vararg->annotation, names))
         goto error;
-    if (compiler_visit_argannotations(c, args->kwonlyargs, names))
+    if (!compiler_visit_argannotations(c, args->kwonlyargs, names))
         goto error;
     if (args->kwarg && args->kwarg->annotation &&
-        compiler_visit_argannotation(c, args->kwarg->arg,
+        !compiler_visit_argannotation(c, args->kwarg->arg,
                                      args->kwarg->annotation, names))
         goto error;
 
@@ -1622,7 +1621,7 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,
         if (!return_str)
             goto error;
     }
-    if (compiler_visit_argannotation(c, return_str, returns, names)) {
+    if (!compiler_visit_argannotation(c, return_str, returns, names)) {
         goto error;
     }