News for hackers. Stuff that matters.
Re:Abstract Syntax Tree for Patching Code and Assessing Code... by oefrha on Monday June 07, 2021 @05:26AM (#27420603)
> One of the problems of patching code using ast package of Python is that it loses all the formatting and comments of the original source code.

What you actually want here is a concrete syntax tree preserving all the comments and whitespace. There’s a sort of built-in one as part of lib2to3 used by the likes of black and yapf. There’s also a good third party options now in the form of https://github.com/Instagram/LibCST.

There’s been talks about adding a CST module to PSL, but I don’t think the proposal went anywhere.

https://bugs.python.org/issue33337

There are no comments on this comment yet.