diff options
author | Batuhan Taskaya <isidentical@gmail.com> | 2021-05-15 12:55:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-15 12:55:53 (GMT) |
commit | e4e931a67e49cf3c61263dc94fb0806c34f972cd (patch) | |
tree | 0ee2654289c0e1607123e8b17f52f857581c1352 /Lib/ast.py | |
parent | 4aa63d65a9971d14f1a2131b989dca0dab514a9d (diff) | |
download | cpython-e4e931a67e49cf3c61263dc94fb0806c34f972cd.zip cpython-e4e931a67e49cf3c61263dc94fb0806c34f972cd.tar.gz cpython-e4e931a67e49cf3c61263dc94fb0806c34f972cd.tar.bz2 |
bpo-44081: improve ast.unparse() for lambdas with no parameters (GH-26000)
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -716,9 +716,9 @@ class _Unparser(NodeVisitor): self.maybe_newline() self.write(" " * self._indent + text) - def write(self, text): - """Append a piece of text""" - self._source.append(text) + def write(self, *text): + """Add new source parts""" + self._source.extend(text) @contextmanager def buffered(self, buffer = None): @@ -1566,8 +1566,11 @@ class _Unparser(NodeVisitor): def visit_Lambda(self, node): with self.require_parens(_Precedence.TEST, node): - self.write("lambda ") - self.traverse(node.args) + self.write("lambda") + with self.buffered() as buffer: + self.traverse(node.args) + if buffer: + self.write(" ", *buffer) self.write(": ") self.set_precedence(_Precedence.TEST, node.body) self.traverse(node.body) |