3 ms·
> 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 actua
by oefrha 5y ago
> 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 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 https://bugs.python.org/issue33337