diff options
author | Batuhan Taskaya <batuhanosmantaskaya@gmail.com> | 2020-05-16 21:53:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-16 21:53:25 (GMT) |
commit | 25160cdc4775a1ddb4e37c8bf5a6e31ad9c146ed (patch) | |
tree | 5a119888dfcc85339ce279d352a05def90865431 | |
parent | ce4a753dcb3eef3d68e892a6515490b1aa219651 (diff) | |
download | cpython-25160cdc4775a1ddb4e37c8bf5a6e31ad9c146ed.zip cpython-25160cdc4775a1ddb4e37c8bf5a6e31ad9c146ed.tar.gz cpython-25160cdc4775a1ddb4e37c8bf5a6e31ad9c146ed.tar.bz2 |
bpo-38870: Don't put unnecessary parentheses on class declarations in ast.parse (GH-20134)
-rw-r--r-- | Lib/ast.py | 2 | ||||
-rw-r--r-- | Lib/test/test_unparse.py | 15 |
2 files changed, 15 insertions, 2 deletions
@@ -930,7 +930,7 @@ class _Unparser(NodeVisitor): 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: diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py index 1393bcc..410df7d 100644 --- a/Lib/test/test_unparse.py +++ b/Lib/test/test_unparse.py @@ -110,7 +110,7 @@ with f() as x, g() as y: docstring_prefixes = [ "", - "class foo():\n ", + "class foo:\n ", "def foo():\n ", "async def foo():\n ", ] @@ -367,6 +367,19 @@ class CosmeticTestCase(ASTTestCase): 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"""', |