]> granicus.if.org Git - python/commitdiff
Merged revisions 82537 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Sun, 4 Jul 2010 16:39:03 +0000 (16:39 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 4 Jul 2010 16:39:03 +0000 (16:39 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r82537 | mark.dickinson | 2010-07-04 17:37:31 +0100 (Sun, 04 Jul 2010) | 2 lines

  Issue #9128: Fix validation of class decorators in parser module.
........

Lib/test/test_parser.py
Misc/NEWS
Modules/parsermodule.c

index 9c73b99d4652dd041693be7d32d62ab2f6fa3341..3a7bbe95e4e36e74d057843472efa9fca164783b 100644 (file)
@@ -150,6 +150,13 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
     def test_class_defs(self):
         self.check_suite("class foo():pass")
         self.check_suite("class foo(object):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 d630751de8df7ff5a675e69a678a7ed2063de0b8..b2a316062c984dffae480481058fe838622f944f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -75,6 +75,8 @@ C-API
 Library
 -------
 
+- Issue #9128: Fix validation of class decorators in parser module.
+
 - Issue #5468: urlencode to handle bytes type and other encodings in its query
   parameter. Patch by Dan Mahn.
 
index dce85c24ab4c6552e9667380f5a3d63ccd44d037..b00037db53c5979c56ea68ba9d47f1c09c92bfbc 100644 (file)
@@ -2507,14 +2507,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