tweag/FawltyDeps

Imports protected by TYPE_CHECKING are treated as mandatory

开放

#390 创建于 2023年11月3日

 (1 条评论) (0 个反应) (0 位负责人)Python (18 个派生)auto 404
P3good first issueparsing-imports

仓库指标

星标
 (288 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Describe the bug

Code which is protected by TYPE_CHECKING is listed as a required import. I'm not sure if to class this as a bug or a feature request but this template fits better.

For example:

from typing import TYPE_CHECKING
import foo
if TYPE_CHECKING:
    import bar

To Reproduce

bash-5.2$ echo $'from typing import TYPE_CHECKING\nimport foo\nif TYPE_CHECKING:\n    import bar' | fawltydeps --list-imports --code - --detailed
<stdin>:2: foo
<stdin>:4: bar

Expected behavior

Import protected by TYPE_CHECKING can be ignored.

Environment

  • Version of the code: 0.13.2

Additional context

贡献者指南