[issue43417] ast.unparse: Simplify buffering logic

Batuhan Taskaya report at bugs.python.org
Sat Mar 6 06:55:57 EST 2021


New submission from Batuhan Taskaya <isidentical at gmail.com>:

Currently, buffer is just an instance-level list that is used in various places to avoid directly writing stuff into the real source buffer, though the design is pretty complicated and hard to use.

There are various use cases (like omitting the empty space when unparsing argument-less lambdas, e.g: lambda : 2 + 2) we could've use this buffer system if it was offering a stackable version (like multiple levels of buffers).

What I think is we should probably do this with a proper context manager and in the context capture all writings into a list where we would return after the context is closed;

with self.buffered() as buffer:
    self._write_fstring_inner(node)
return self._write_str_avoiding_backslashes("".join(buffer))

----------
assignee: BTaskaya
components: Library (Lib)
messages: 388197
nosy: BTaskaya
priority: normal
severity: normal
status: open
title: ast.unparse: Simplify buffering logic
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43417>
_______________________________________


More information about the Python-bugs-list mailing list