From a7ee59b3d33327ec6f9f34da97d16344a1121199 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 4 Jul 2010 16:23:54 +0000 Subject: [PATCH] Issue #9128: Validate class decorator syntax correctly in parser module. --- Lib/test/test_parser.py | 8 ++++++++ Misc/NEWS | 1 + Modules/parsermodule.c | 17 +++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index dca904cb63d..a964877e317 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -180,6 +180,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 *") diff --git a/Misc/NEWS b/Misc/NEWS index 3eb67a388d6..3a867a5d62b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,7 @@ Core and Builtins Library ------- +- Issue #9128: Fix validation of class decorators in parser module. Extension Modules ----------------- diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 5d1bfb6674e..4a581d75867 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -2682,14 +2682,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