Summary
For me, TC004 fairly consistently gives false positives when the guarded import is used for return types.
For example:
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import abc
def bar() -> abc.ABC | None:
return None
Running ruff check --isolated --select TC004 gives the following output:
main.py:4:12: TC004 Move import `abc` out of type-checking block. Import is used for more than type hinting.
|
3 | if TYPE_CHECKING:
4 | import abc
| ^^^ TC004
|
= help: Move out of type-checking block
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
Version
ruff 0.9.9 (091d0af 2025-02-28)