runtime-import-in-type-checking-block (TCH004)#
Derived from the flake8-type-checking linter.
Fix is sometimes available.
What it does#
Checks for runtime imports defined in a type-checking block.
Why is this bad?#
The type-checking block is not executed at runtime, so the import will not be available at runtime.
Example#
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import foo
def bar() -> None:
foo.bar() # raises NameError: name 'foo' is not defined
Use instead: