[Python-checkins] r82532 - in python/branches/release27-maint: Lib/test/test_parser.py Misc/NEWS Modules/parsermodule.c

mark.dickinson python-checkins at python.org
Sun Jul 4 18:23:54 CEST 2010


Author: mark.dickinson
Date: Sun Jul  4 18:23:54 2010
New Revision: 82532

Log:
Issue #9128:  Validate class decorator syntax correctly in parser module.


Modified:
   python/branches/release27-maint/Lib/test/test_parser.py
   python/branches/release27-maint/Misc/NEWS
   python/branches/release27-maint/Modules/parsermodule.c

Modified: python/branches/release27-maint/Lib/test/test_parser.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_parser.py	(original)
+++ python/branches/release27-maint/Lib/test/test_parser.py	Sun Jul  4 18:23:54 2010
@@ -180,6 +180,14 @@
 
     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 *")

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Sun Jul  4 18:23:54 2010
@@ -16,6 +16,7 @@
 Library
 -------
 
+- Issue #9128: Fix validation of class decorators in parser module.
 
 Extension Modules
 -----------------

Modified: python/branches/release27-maint/Modules/parsermodule.c
==============================================================================
--- python/branches/release27-maint/Modules/parsermodule.c	(original)
+++ python/branches/release27-maint/Modules/parsermodule.c	Sun Jul  4 18:23:54 2010
@@ -2682,14 +2682,15 @@
 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


More information about the Python-checkins mailing list