`AddImportsVisitor`: Add the ability to import in an `if TYPE_CHECKING` block
Open
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 229
- PR merge metrics
- No merged PRs in 30d
Description
When using libcst to add types, we often want to add imports in a conditional `if TYPE_CHECKING` block, to avoid circular imports or improve performance.
It would be great to have an extra `if_type_checking: bool` parameter to `AddImportsVisitor`, that would add the import in the block (and import `TYPE_CHECKING` from `typing` if it is not already the case).
If you think this is a good idea, I may work on this.
Contributor guide
Assessment
This issue has not been assessed yet.