Flush out support for ``class B(): pass`` syntax by adding support to the
'parser' module and 'compiler' package.
Closes patch #1176012. Thanks logistix.
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index 0c6d148..dfa25b8 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -280,12 +280,14 @@
return Lambda(names, defaults, flags, code, lineno=nodelist[1][2])
def classdef(self, nodelist):
- # classdef: 'class' NAME ['(' testlist ')'] ':' suite
+ # classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
name = nodelist[1][1]
doc = self.get_docstring(nodelist[-1])
if nodelist[2][0] == token.COLON:
bases = []
+ elif nodelist[3][0] == token.RPAR:
+ bases = []
else:
bases = self.com_bases(nodelist[3])
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py
index 9976a47..d9a3cb8 100644
--- a/Lib/test/test_compiler.py
+++ b/Lib/test/test_compiler.py
@@ -33,6 +33,9 @@
else:
compiler.compile(buf, basename, "exec")
+ def testNewClassSyntax(self):
+ compiler.compile("class foo():pass\n\n","<string>","exec")
+
def testLineNo(self):
# Test that all nodes except Module have a correct lineno attribute.
filename = __file__
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index 0f8c1d0..bd81aca 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -127,6 +127,9 @@
self.check_suite("@funcattrs()\n"
"def f(): pass")
+ def test_class_defs(self):
+ self.check_suite("class foo():pass")
+
def test_import_from_statement(self):
self.check_suite("from sys.path import *")
self.check_suite("from sys.path import dirname")