LibCST
LibCST copied to clipboard
A concrete syntax tree parser and serializer library for Python that preserves many aspects of Python's abstract syntax tree
The version of libcst I am using is 0.3.21. Following is the code snippet to reproduce the bug: ```python import libcst as cst import libcst.matchers as m s = """...
The document of `MatchMetadataIfTrue` [suggests an example code](https://libcst.readthedocs.io/en/latest/matchers.html#libcst.matchers.MatchMetadataIfTrue) to `match against any Name node for the identifier foo as long as that identifier is found at the beginning of an...
The type definitions for `CSTTransform.on_leave` https://github.com/Instagram/LibCST/blob/df231f3fa5ac3dfa7b14a30103249e5da79509e3/libcst/_visitors.py#L50-L52 is too strict, as it requires that the return type is exactly the same as the original_node, which is not correct. For example, you...
I'm looking at shipping some codemods in https://github.com/HypothesisWorks/hypothesis/issues/2705, to automatically upgrade uses of deprecated or just plain inefficient APIs, making it easier to migrate to newer versions of Hypothesis. One...
Given `a.py` that looks like ``` x = ( "a" "a" "a" ... 397 more of that line ... ) ``` `python -m usort check a.py` fails. The transformer is...
I am building a metadata provider and running into a pretty strange bug. If I declare my provider: ```Python class Provider(cst.BatchableMetadataProvider[bool]): def _visit_simple_block(self, node: Union[cst.SimpleStatementLine, cst.SimpleStatementSuite] ) -> Optional[bool]: ......
Thanks for the really useful library! I was expecting the `@leave` decorator to match against the version of the node that has already been transformed by deeper-nested leave functions, but...
The `matchers` module have functions that operate either just on the given node (`extract`), or in the node and its children (`findall`, `extractall`). However for `replace` there's no such distinction....
This way you do not need to run LibCST from the same directory in which you have the configuration. This is helpful if you want to commit a per-team LibCST...
This is probably easier to explain with a demo that I extracted from https://github.com/HypothesisWorks/hypothesis/pull/2712 ```python import libcst as cst from libcst.codemod import VisitorBasedCodemodCommand code = """ from example import decorator...