chore: enforce type-checking-only imports with ruff - #379
Draft
cloudsmith-iduffy wants to merge 1 commit into
Draft
chore: enforce type-checking-only imports with ruff#379cloudsmith-iduffy wants to merge 1 commit into
cloudsmith-iduffy wants to merge 1 commit into
Conversation
6 tasks
Select the FA and TC rule groups. Typing-only imports must sit in an if TYPE_CHECKING block, which pre-commit and CI both enforce through the ruff-check hook. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cloudsmith-iduffy
force-pushed
the
lint/enforce-type-checking-imports
branch
from
August 21, 2026 23:40
08f1df9 to
0cbbc94
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The perf work in this stack moved a lot of imports into
if TYPE_CHECKING:blocks by hand — imports that are only needed for type annotations don't have to be paid for at runtime. This makes that a rule so it can't quietly regress.Two ruff rule groups are now enabled:
TC) — if an import is only used in type annotations, it has to live in anif TYPE_CHECKING:block, which means the interpreter never actually imports itFA) — makes surefrom __future__ import annotationsis present where it's needed, so the moved imports stay safe without quoting every annotationThere's nothing to set up: the pre-commit ruff hook picks the rules up from
pyproject.toml, and CI runs pre-commit, so both enforce it.Turning the rules on found 8 leftover typing-only imports across 5 files, all moved in this PR. The only one that needed real thought was
EnvironmentDetectorin the OIDC detectors package__init__— moving it would break anything importing it from the package, but it turns out every subclass and test already imports it from.basedirectly, so the package-level name was dead weight.This mirrors how the main
cloudsmithrepo configures ruff (it selects the same two groups). Its stdlib-json-to-orjsonban wasn't carried over: that's a binary dependency to speed up JSON payloads that are tiny here, and imports — not parsing — were the CLI's actual bottleneck.Type of Change
Lint enforcement; no behaviour change.
Additional Notes
from __future__ import annotationsyet (e.g.core/mcp/server.py) are left alone — ruff only offers the move where it's provably safe, which is exactly what we want from a guard.🤖 Generated with Claude Code