Instagram / LibCST

A concrete syntax tree parser and serializer library for Python that preserves many aspects of Python's abstract syntax tree
https://libcst.readthedocs.io/
Other
1.56k stars 192 forks source link

Add validation for `with` nodes to match `if`, `while`, `assert` #1224

Open sirosen opened 1 month ago

sirosen commented 1 month ago

I believe that after v1.5.0 , with nodes are the only case of a keyword followed by an expression with


I have some codepaths in my fixer for removing extra parens. I found that after 1.5.0, if(x()) fixing failed because it removes the parens first, then adds the space. It generates ifx() in an intermediate state and is rejected.

The same path works for with(x()), removing parens (producing withx()) and then adding the space (with x()).

This isn't a problem for me, but I think it would be better for these APIs to be as consistent as we can have them! :slightly_smiling_face: