Skip to content

refactor(lint): the lazy-export modules import their names under TYPE_CHECKING, and the code that Ruff preview flags is rewritten with no setting changed #2010

Description

@dan-petty

Friction

  • Ruff PLR1702 is a preview rule, and lint.preview = true also turns on the preview behavior of the stable rules. The survey of 2026-10-22 found 145 findings of other rules with preview on.
  • Until that code is rewritten, preview cannot be switched on, and the nesting hook cannot be replaced by Ruff.

Evidence

Checked at main a752a14. The counts come from the survey in #1876 (Ruff 0.16.8, a scratch copy of the settings).

Existing tool considered

Proposed remedy

The decisions 1 and 2 of 2026-10-22 in #1876 apply:

  • Give each of the 8 modules an if TYPE_CHECKING: block that imports its exported names. The runtime stays lazy.
  • Rewrite the two UP046 classes with PEP 695 type parameters.
  • Write the micro sign as the escape \u00b5 in the source of scalars.py and tests/test_output.py.
  • Replace the two test imports with importlib.import_module, with no noqa marker.
  • Change no setting. The gate stays green.

Acceptance criteria

  • With the Ruff settings of pyproject.toml plus preview = true, ruff check reports 0 findings for F822, UP046, RUF001 and F401. The pull request shows that run.
  • Each of the 8 modules imports its exported names under TYPE_CHECKING, and python -X importtime -c "import devops_cli" shows that the runtime stays lazy.
  • uv run mypy src passes in strict mode after the rewrite.
  • format_duration(0.0005) still returns "500µs".
  • tests/test_exceptions.py imports the two modules with importlib.import_module and has no new noqa marker.
  • No Ruff, mypy or ceiling setting changes. uv run devops ci passes.

Source: #1876

Proposed design

Problem statement

Eight lazy-export modules list names in __all__ that no import in the module binds. Ruff F822 reports 139 findings for them. Two classes use Generic[DepsT] (UP046). A micro sign appears in source (RUF001). Two test imports exist for side effect (F401). Until this code is rewritten, lint.preview = true cannot be enabled and the nesting hook cannot be replaced by Ruff.

Acceptance criteria

  • Criterion 1: Ruff reports 0 findings for F822, UP046, RUF001 and F401 with preview = true.
    Verification: Run ruff check --select F822,UP046,RUF001,F401 --preview and confirm 0 findings. Show the output in the pull request.
  • Criterion 2: Each of the 8 modules imports its exported names under TYPE_CHECKING and the runtime stays lazy.
    Verification: Run python -X importtime -c "import devops_cli" and confirm the submodules are not loaded at top level.
  • Criterion 3: mypy passes in strict mode after the rewrite.
    Verification: Run uv run mypy src and confirm it exits 0.
  • Criterion 4: format_duration(0.0005) still returns "500μs".
    Verification: Run uv run pytest tests/test_output.py -k format_duration and confirm the test passes.
  • Criterion 5: tests/test_exceptions.py imports the two modules with importlib.import_module and has no new noqa marker.
    Verification: Inspect tests/test_exceptions.py lines 145-146 for importlib.import_module and confirm no noqa string is present.
  • Criterion 6: No Ruff, mypy or ceiling setting changes. The full CI gate passes.
    Verification: Run uv run devops ci and confirm it exits 0. Diff pyproject.toml against the base and confirm no setting lines changed.

Key questions

  • What pattern do the 8 lazy-export modules use to serve their exports?: They use a module-level __getattr__ with an _ATTR_MAP dict that maps each name to a (module, attribute) tuple. On first access, importlib.import_module loads the submodule and getattr retrieves the attribute. [sources: src/devops_cli/security/init.py, src/devops_cli/telemetry/init.py]
  • Do any existing modules already follow the TYPE_CHECKING import pattern?: Yes. src/devops_cli/security/__init__.py and src/devops_cli/telemetry/__init__.py already import their names under TYPE_CHECKING, and Ruff reports no F822 findings there. [sources: src/devops_cli/security/init.py, src/devops_cli/telemetry/init.py]
  • Should per-file-ignores suppress the findings instead of rewriting the code?: No. The owner decided against it because it would turn a lint rule off for 8 files and break the ceiling of 0 findings. (proposed)
  • Should any Ruff, mypy, or ceiling setting be changed as part of this work?: No. The gate stays green with no setting change. The code is rewritten to match the rules. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/refactor
    on Oct 23, 2026
  2. dan-petty commented on Oct 23, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/refactor. The candidate proposes a refactor of linting and code structure.
    • Priority: P2-Medium. The change improves code quality and enables future tooling improvements.
    • Value: Medium. The change helps with linting and code maintainability for a subset of modules.
    • Effort: Low. The changes involve standard refactoring patterns and are well-defined.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at bb46660 (see proposed design in issue body).

  4. added
    priority/p2-medium
    status/ready
    value/medium
    effort/low
    on Oct 28, 2026
  5. added a commit that references this issue on Oct 29, 2026
  6. removed
    status/ready
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumsource/agenttype/refactorvalue/medium

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions