[flake8-type-checking] Add include-modules option (Feature Request)
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 458
Description
Hi, thank you for the work on ruff and lint/auto-fix rules!
I've added the flake8-type-checking (TCH) rules to my codebase to automatically move type-only imports to an `if TYPE_CHECKING` block. Super helpful to build lean, production images without superfluous type-shed libraries.
Ruff allows me to disable the `TCH001` and `TCH003` rules to ignore first-party and standard library type-only imports. However, the `TCH002` rule treats all third-party typing-only imports the same. Since some third-party libraries ship with type annotations, these are available in the production build. These types could be imported directly and avoid the additional stringified, forward references throughout the code.
I feel this would be a smaller migration step for teams to introduce, easing the experience for people less familiar with type hints (since IMO the quotes do add some additional visual clutter).
I've used the [exempt-modules](https://docs.astral.sh/ruff/settings/#lint_flake8-type-checking_exempt-modules) option to exclude common third-party libraries so they can be imported directly, but it would be simpler to specify specifically which third-party libraries to fix, i.e., the type shed ones.
Thanks a lot
Contributor guide
Research direction
Start by reading the linked exempt-modules setting documentation and the TCH001–TCH003 rule behavior described in the issue. Determine how an include-modules setting should limit third-party imports handled by TCH002, and verify that the resulting configuration distinguishes the requested modules while preserving existing exemptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100