]> granicus.if.org Git - python/commitdiff
Issue #9128: Fix validation of class decorators in parser module.
authorMark Dickinson <dickinsm@gmail.com>
Sun, 4 Jul 2010 16:28:57 +0000 (16:28 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 4 Jul 2010 16:28:57 +0000 (16:28 +0000)
Lib/test/test_parser.py
Misc/NEWS
Modules/parsermodule.c

index ca5f43fa9a73cb0ba3aa300b2c2016304efebc40..85e39c79746c953e2ec72200cccacab26072e3bc 100644 (file)
@@ -156,6 +156,14 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
 
     def test_class_defs(self):
         self.check_suite("class foo():pass")
+        self.check_suite("@class_decorator\n"
+                         "class foo():pass")
+        self.check_suite("@class_decorator(arg)\n"
+                         "class foo():pass")
+        self.check_suite("@decorator1\n"
+                         "@decorator2\n"
+                         "class foo():pass")
+
 
     def test_import_from_statement(self):
         self.check_suite("from sys.path import *")
index cc5ba32189ea9e55a1654022f51387d24d02c147..f605050c0705e7222a6dc376a0d755ee6fa41ae6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,8 @@ C-API
 Library
 -------
 
+- Issue #9128: Fix validation of class decorators in parser module.
+
 - Issue #7673: Fix security vulnerability (CVE-2010-2089) in the audioop
   module, ensure that the input string length is a multiple of the frame size
 
index 365ec901df12cf8edb7a5d6e1137b5ef0cd34bfd..097c450d90298069d56063100cbf72b4330e4f64 100644 (file)
@@ -2679,14 +2679,15 @@ validate_funcdef(node *tree)
 static int
 validate_decorated(node *tree)
 {
-  int nch = NCH(tree);
-  int ok = (validate_ntype(tree, decorated)
-            && (nch == 2)
-            && validate_decorators(RCHILD(tree, -2))
-            && (validate_funcdef(RCHILD(tree, -1))
-                || validate_class(RCHILD(tree, -1)))
-            );
-  return ok;
+    int nch = NCH(tree);
+    int ok = (validate_ntype(tree, decorated)
+              && (nch == 2)
+              && validate_decorators(RCHILD(tree, -2)));
+    if (TYPE(RCHILD(tree, -1)) == funcdef)
+        ok = ok && validate_funcdef(RCHILD(tree, -1));
+    else
+        ok = ok && validate_class(RCHILD(tree, -1));
+    return ok;
 }
 
 static int