mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
bpo-38870: Don't put unnecessary parentheses on class declarations in ast.parse (GH-20134)
This commit is contained in:
parent
ce4a753dcb
commit
25160cdc47
2 changed files with 15 additions and 2 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class Foo: pass
|
|||
|
||||
docstring_prefixes = [
|
||||
"",
|
||||
"class foo():\n ",
|
||||
"class foo:\n ",
|
||||
"def foo():\n ",
|
||||
"async def foo():\n ",
|
||||
]
|
||||
|
|
@ -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"""',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue