Commit a7ee59b3 authored by Mark Dickinson's avatar Mark Dickinson

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

parent 96c4df45
...@@ -180,6 +180,14 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase): ...@@ -180,6 +180,14 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
def test_class_defs(self): def test_class_defs(self):
self.check_suite("class foo():pass") 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): def test_import_from_statement(self):
self.check_suite("from sys.path import *") self.check_suite("from sys.path import *")
......
...@@ -16,6 +16,7 @@ Core and Builtins ...@@ -16,6 +16,7 @@ Core and Builtins
Library Library
------- -------
- Issue #9128: Fix validation of class decorators in parser module.
Extension Modules Extension Modules
----------------- -----------------
......
...@@ -2682,14 +2682,15 @@ validate_funcdef(node *tree) ...@@ -2682,14 +2682,15 @@ validate_funcdef(node *tree)
static int static int
validate_decorated(node *tree) validate_decorated(node *tree)
{ {
int nch = NCH(tree); int nch = NCH(tree);
int ok = (validate_ntype(tree, decorated) int ok = (validate_ntype(tree, decorated)
&& (nch == 2) && (nch == 2)
&& validate_decorators(RCHILD(tree, -2)) && validate_decorators(RCHILD(tree, -2)));
&& (validate_funcdef(RCHILD(tree, -1)) if (TYPE(RCHILD(tree, -1)) == funcdef)
|| validate_class(RCHILD(tree, -1))) ok = ok && validate_funcdef(RCHILD(tree, -1));
); else
return ok; ok = ok && validate_class(RCHILD(tree, -1));
return ok;
} }
static int static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment