]> 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:37:31 +0000 (16:37 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 4 Jul 2010 16:37:31 +0000 (16:37 +0000)
Lib/test/test_parser.py
Misc/NEWS
Modules/parsermodule.c

index 071d3622df567429f34bdcc8a7181ec278a63f4c..96f14f62bb1d223648073d132c68a078a82b5708 100644 (file)
@@ -149,6 +149,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 091deabcac4f082da6a2be04c5608ee770defbd4..b7fe3f657fb3ccbce24b9691102f06742a8813af 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -468,6 +468,8 @@ C-API
 Library
 -------
 
+- Issue #9128: Fix validation of class decorators in parser module.
+
 - Issue #9094: python -m pickletools will now disassemble pickle files
   listed in the command line arguments.  See output of python -m
   pickletools -h for more details.
index 3e0f53082d74f2ff74b3396738d29d1a03134b9f..e60f23d7b2c408379eb4b0f9f499c52ead59ae7a 100644 (file)
@@ -2509,14 +2509,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