This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: ast.unparse: Simplify buffering logic
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.10
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: BTaskaya Nosy List: BTaskaya
Priority: normal Keywords: patch

Created on 2021-03-06 11:55 by BTaskaya, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24772 merged BTaskaya, 2021-03-06 11:59
Messages (1)
msg388197 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2021-03-06 11:55
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:
return self._write_str_avoiding_backslashes("".join(buffer))
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87583
2021-05-08 23:33:03BTaskayasetstatus: open -> closed
stage: patch review -> resolved
2021-03-06 11:59:18BTaskayasetkeywords: + patch
stage: patch review
pull_requests: + pull_request23540
2021-03-06 11:55:57BTaskayacreate