You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But the whole point of this typing-only-standard-library-import TC003 check is to avoid imports that are only needed for type checking:
Unused imports add a performance overhead at runtime, and risk creating import cycles. If an import is only used in typing-only contexts, it can instead be imported conditionally under an if TYPE_CHECKING: block to minimize runtime overhead.
Does this still repro if you use --preview? #15719 only changed the behaviour in preview mode for now, since it's technically a breaking change. We might be able to stabilise it in v0.10; if not, it'll probably be stabilised in v0.11 :-)
Description
TC003:
https://docs.astral.sh/ruff/rules/typing-only-standard-library-import/#typing-only-standard-library-import-tc003
TYPE_CHECKING = False
Ruff doesn't allow it:
But upstream https://pypi.org/project/flake8-type-checking/ does:
from typing import TYPE_CHECKING
Both are fine with this:
❯ ruff check --select TC --isolated 1.py All checks passed! ❯ flake8 1.py --statistics ❯
But the whole point of this
typing-only-standard-library-import
TC003 check is to avoid imports that are only needed for type checking:See also:
TYPE_CHECKING
with__future__.annotations
#15681TYPE_CHECKING
forin_type_checking_block
#15719Which look like it should have fixed it in 0.9.5, but I can repro in 0.9.4-0.9.6.
The text was updated successfully, but these errors were encountered: