You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What I'm imagining is using ast to find and modify nodes, and when ready to emit (unparse) align with the FST so that only what the AST has changed will be modified.
Some caveats:
Cannot delete nodes (I assume)
Maybe difficulty in converting single line to multiline, and multiline to single line
What do you think?
I am modifying AST nodes, changing: docstrings; ast.Assign; ast.AnnAssign; and ast.FunctionDef/ast.AsyncFunctionDef. Inferring types, adding them as a type comment xor annotation; converting between docstring formats (incl. adding/remove types); and updating the return attribute of a function definition.
…but adding/removing type annotations, for example, has the [unexpected] side-effect of removing all comments and reducing whitespace.
Tossing up betwixt rewriting my library around redbaron | LibCST and hacking together a basic parser & emitter to replace ast.parse and ast.unparse with some line-aware copypasta.
What I'm imagining is using
ast
to find and modify nodes, and when ready to emit (unparse) align with the FST so that only what the AST has changed will be modified.Some caveats:
What do you think?
Currently my library only uses
ast
andinspect
for this… which means it can support 3.6, 3.7, 3.8, 3.9, 3.10 & 3.11. https://github.com/SamuelMarks/cdd-python…but adding/removing type annotations, for example, has the [unexpected] side-effect of removing all comments and reducing whitespace.
Tossing up betwixt rewriting my library around redbaron | LibCST and hacking together a basic parser & emitter to replace
ast.parse
andast.unparse
with some line-aware copypasta.Related: #207
Thanks for sharing your perspective
The text was updated successfully, but these errors were encountered: