Instagram / Instagram/LibCST

`AddImportsVisitor`: Add the ability to import in an `if TYPE_CHECKING` block

Open
#1,052 2 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.