{"id":21348,"library":"flake8-typing-imports","title":"flake8-typing-imports","description":"Flake8 plugin enforcing that typing imports are guarded by `if TYPE_CHECKING` to avoid runtime import overhead and circular imports. Current version 1.17.0, requires Python >=3.9. Maintained by asottile, stable release cadence.","status":"active","version":"1.17.0","language":"python","source_language":"en","source_url":"https://github.com/asottile/flake8-typing-imports","tags":["flake8","plugin","typing","import","type-checking"],"install":[{"cmd":"pip install flake8-typing-imports","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Plugin is loaded by flake8; must be installed alongside flake8.","package":"flake8","optional":false}],"imports":[{"note":"flaek8 loads plugins automatically; no manual import needed.","symbol":"flake8_typing_imports","correct":""}],"quickstart":{"code":"cat > example.py << 'EOF'\nfrom typing import TYPE_CHECKING\nif TYPE_CHECKING:\n    from collections import abc\n\nfoo: abc.Iterable\nEOF\npip install flake8 flake8-typing-imports\nflake8 example.py --select=TYP\n","lang":"python","description":"Create a file with a guarded import and run flake8 with the TYP selector to check typing imports."},"warnings":[{"fix":"Update your flake8 configuration to use the new codes (TYP001, TYP002, etc. are still supported but deprecated). See changelog.","message":"In version 1.6.0, the default codes changed from TYP001, TYP002 etc. to a new scheme. Old codes may no longer be valid.","severity":"breaking","affected_versions":"<1.6.0"},{"fix":"Manually guard imports from modules like `types` if needed.","message":"The plugin checks for `TYPE_CHECKING` guard on imports of `typing` and `collections.abc`, but it does not flag other modules like `types`. You must manually guard them.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure all typing imports use `from ... import ...` syntax if guarding.","message":"The plugin only detects `from foo import bar` guarded imports; bare imports like `import foo` inside `if TYPE_CHECKING` are not flagged if they are not from typing-related modules.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to Python >=3.9.","message":"Support for Python 3.7 ended in version 1.15.0; Python 3.8 ended in 1.16.0. Running on older Python versions will not work.","severity":"deprecated","affected_versions":">=1.15.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Put the import inside an `if TYPE_CHECKING:` block: `if TYPE_CHECKING: from typing import List`","cause":"A `typing` import (e.g., `from typing import List`) is placed at module level without an `if TYPE_CHECKING:` guard.","error":"TYP001: Import `typing` is not guarded by `TYPE_CHECKING`"},{"fix":"Guard the import with `if TYPE_CHECKING:`.","cause":"A `collections.abc` import is not guarded.","error":"TYP002: Import `collections.abc` is not guarded by `TYPE_CHECKING`"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}