Skip to content

chore: enforce type-checking-only imports with ruff - #379

Merged
cloudsmith-iduffy merged 1 commit into
masterfrom
lint/enforce-type-checking-imports
Aug 25, 2026
Merged

chore: enforce type-checking-only imports with ruff#379
cloudsmith-iduffy merged 1 commit into
masterfrom
lint/enforce-type-checking-imports

Conversation

@cloudsmith-iduffy

@cloudsmith-iduffy cloudsmith-iduffy commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

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:

  • flake8-type-checking (TC) — if an import is only used in type annotations, it has to live in an if TYPE_CHECKING: block, which means the interpreter never actually imports it
  • flake8-future-annotations (FA) — makes sure from __future__ import annotations is present where it's needed, so the moved imports stay safe without quoting every annotation

There'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 EnvironmentDetector in 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 .base directly, so the package-level name was dead weight.

This mirrors how the main cloudsmith repo configures ruff (it selects the same two groups). Its stdlib-json-to-orjson ban 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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Other (please describe)

Lint enforcement; no behaviour change.

Additional Notes

  • Files that don't have from __future__ import annotations yet (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.
  • The existing pre-commit excludes for the test directories still apply.
  • Full suite passes (801 passed, 40 skipped).

🤖 Generated with Claude Code

@cloudsmith-iduffy cloudsmith-iduffy changed the title chore(no-ticket): enforce type-checking-only imports with ruff chore: enforce type-checking-only imports with ruff Aug 21, 2026
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 08f1df9 to 0cbbc94 Compare August 21, 2026 23:40
@cloudsmith-iduffy
cloudsmith-iduffy marked this pull request as ready for review August 24, 2026 06:52
@cloudsmith-iduffy
cloudsmith-iduffy requested a review from a team as a code owner August 24, 2026 06:52
Copilot AI lite review requested due to automatic review settings August 24, 2026 06:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enforces Ruff rules for future annotations and type-checking-only imports.

Changes:

  • Enables Ruff FA and TC rule groups.
  • Moves annotation-only imports into TYPE_CHECKING blocks.
  • Removes the runtime EnvironmentDetector package export.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Summary
pyproject.toml Enables Ruff type-checking and future-annotations rules.
cloudsmith_cli/credential_helpers/docker/installer.py Defers the CredentialResult import.
cloudsmith_cli/core/credentials/provider.py Defers credential model imports.
cloudsmith_cli/core/credentials/oidc/detectors/__init__.py Defers EnvironmentDetector; this breaks the existing package-level runtime export and requires a compatibility export or documented breaking change.
cloudsmith_cli/core/credentials/chain.py Defers credential type imports.
cloudsmith_cli/core/cache_utils.py Defers the Callable import.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cloudsmith_cli/core/credentials/oidc/detectors/__init__.py
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 0cbbc94 to 403dd19 Compare August 24, 2026 10:21
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 403dd19 to 86445db Compare August 24, 2026 13:15
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 86445db to 19b54e1 Compare August 24, 2026 15:45
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 19b54e1 to 3c12b55 Compare August 24, 2026 17:58
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 3c12b55 to bde5144 Compare August 25, 2026 11:21
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from bde5144 to 2dc5dd7 Compare August 25, 2026 11:30
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 2dc5dd7 to 7eca5e4 Compare August 25, 2026 11:40
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 7eca5e4 to 0c48895 Compare August 25, 2026 11:50
Base automatically changed from perf/trim-remaining-eager-imports to master August 25, 2026 12:07
@cloudsmith-iduffy
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 0c48895 to 69b5fac Compare August 25, 2026 12:08
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
cloudsmith-iduffy force-pushed the lint/enforce-type-checking-imports branch from 69b5fac to 3a9c299 Compare August 25, 2026 13:23
@cloudsmith-iduffy
cloudsmith-iduffy merged commit cfd592f into master Aug 25, 2026
22 checks passed
@cloudsmith-iduffy
cloudsmith-iduffy deleted the lint/enforce-type-checking-imports branch August 25, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants