mirror of
https://github.com/Instagram/LibCST.git
synced 2025-12-23 10:35:53 +00:00
* Codemod for PEP 484 Assign w / type comments -> PEP 526 AnnAssign Summary: This codemod is intended to eventually handle all type comments from PEP 484. This is a partial implementation specifically handling assignment type comments, which as of PEP 526 are better dealt with using AnnAssign nodes. There is more work to do because there are two other kinds of comments to support: function heading comments and function parameter inline comments. But the PEP 526 functionality is complete so I feel like it's worth havign a PR / CI signals / code review at this stage. Test Plan: ``` python -m unittest libcst.codemod.commands.tests.test_convert_type_comments ``` * Disable on python 3.6, 3.7 The ast module didn't get the `type_comment` information we need until python 3.8. It is possible but not a priority right now to enable 3.6 and 3.7 via the typed_ast library, for now I just throw a NotImplementedError with a nice description. There's a note in the code about where to look for a typed_ast example in case anyone wants to add support in the future. * Fix type errors on the 3.8+ testing fix * Do a better job of complaining on Python < 3.8 * Updates based on code review Summary: Do not strip type comments in the visitor pattern; instead, reach down from the parent to do it because this makes it much more reliable that we won't accidentally remove other comments in a codemod (using visitor state to do this isn't really feasible once we handle complex statements like FunctionDef, With, For). Handle multi-statement statement lines; this works since the trailing whitespace can only apply to the final statement on the line. It's not really a critical edge case to handle, but the code is no more complicated so we might as well. * Prevent comment stripping for multi-assign * Note in the docstring that this is a limited WIP * Reorder checks so the next step will be cleaner |
||
|---|---|---|
| .. | ||
| _nodes | ||
| _parser | ||
| codegen | ||
| codemod | ||
| helpers | ||
| matchers | ||
| metadata | ||
| testing | ||
| tests | ||
| __init__.py | ||
| _add_slots.py | ||
| _batched_visitor.py | ||
| _exceptions.py | ||
| _flatten_sentinel.py | ||
| _maybe_sentinel.py | ||
| _metadata_dependent.py | ||
| _position.py | ||
| _removal_sentinel.py | ||
| _tabs.py | ||
| _type_enforce.py | ||
| _typed_visitor.py | ||
| _typed_visitor_base.py | ||
| _types.py | ||
| _visitors.py | ||
| py.typed | ||
| tool.py | ||