Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def visit_ClassDef(self, node):
self.fill("@")
self.traverse(deco)
self.fill("class " + node.name)
with self.delimit("(", ")"):
with self.delimit_if("(", ")", condition = node.bases or node.keywords):
comma = False
for e in node.bases:
if comma:
Expand Down
15 changes: 14 additions & 1 deletion Lib/test/test_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Foo: pass

docstring_prefixes = [
"",
"class foo():\n ",
"class foo:\n ",
"def foo():\n ",
"async def foo():\n ",
]
Expand Down Expand Up @@ -367,6 +367,19 @@ def test_simple_expressions_parens(self):
self.check_src_roundtrip("call((yield x))")
self.check_src_roundtrip("return x + (yield x)")


def test_class_bases_and_keywords(self):
self.check_src_roundtrip("class X:\n pass")
self.check_src_roundtrip("class X(A):\n pass")
self.check_src_roundtrip("class X(A, B, C, D):\n pass")
self.check_src_roundtrip("class X(x=y):\n pass")
self.check_src_roundtrip("class X(metaclass=z):\n pass")
self.check_src_roundtrip("class X(x=y, z=d):\n pass")
self.check_src_roundtrip("class X(A, x=y):\n pass")
self.check_src_roundtrip("class X(A, **kw):\n pass")
self.check_src_roundtrip("class X(*args):\n pass")
self.check_src_roundtrip("class X(*args, **kwargs):\n pass")

def test_docstrings(self):
docstrings = (
'"""simple doc string"""',
Expand Down