tweag/FawltyDeps

Imports protected by TYPE_CHECKING are treated as mandatory

Open

#390 opened on Nov 3, 2023

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Python (18 forks)auto 404
P3good first issueparsing-imports

Repository metrics

Stars
 (288 stars)
PR merge metrics
 (PR metrics pending)

Description

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

Contributor guide