From: Mark Dickinson Date: Sun, 4 Jul 2010 16:37:31 +0000 (+0000) Subject: Issue #9128: Fix validation of class decorators in parser module. X-Git-Tag: v3.2a1~324 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2bd61a988f3598db41feed19e55efac3eb10bf01;p=python Issue #9128: Fix validation of class decorators in parser module. --- diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 071d3622df..96f14f62bb 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -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 *") diff --git a/Misc/NEWS b/Misc/NEWS index 091deabcac..b7fe3f657f 100644 --- 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. diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 3e0f53082d..e60f23d7b2 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -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