Repository navigation
Labels
effort/lowEffort Low: little workpriority/p2-mediumPriority P2: standard worksource/agentFiled by an agenttype/refactorType refactor: a new structure, same behaviorvalue/mediumValue Medium
Description
Friction
- Ruff
PLR1702is a preview rule, andlint.preview = truealso 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).
F822undefined-export: 139 findings in 8 lazy-export__init__.pymodules. Each serves its exports through a module-level__getattr__, and its__all__lists names that no import in the module binds. The modules areai/review,core,config,ai/models,ai/rag,ai/benchmark,tests/support/fakesand the package rootdevops_cli.src/devops_cli/security/__init__.pyandsrc/devops_cli/telemetry/__init__.pyalready import their names underTYPE_CHECKING, and Ruff reports nothing there.UP046:AbstractToolset(src/devops_cli/ai/toolsets/__init__.py:33) andFunctionToolset(:107) useGeneric[DepsT].RUF001: the micro sign atsrc/devops_cli/output/formatters/scalars.py:209andtests/test_output.py:378.F401: the two plain imports attests/test_exceptions.py:145-146, which exist for their side effect.- ci(lint): Ruff PLR1702 caps nesting and the structural-invariants hook is deleted #1876 lists this change as its Part 1. After the split, ci(lint): Ruff PLR1702 caps nesting and the structural-invariants hook is deleted #1876 only tracks its child issues, and no pull request closes ci(lint): Ruff PLR1702 caps nesting and the structural-invariants hook is deleted #1876 itself. So this candidate asks for a change that no other issue holds.
Existing tool considered
- Ruff itself finds each problem. The fixes use the standard forms:
if TYPE_CHECKING:imports, PEP 695 type parameters, the escape\u00b5, andimportlib.import_module. lint.per-file-ignores(Fix B of ci(lint): Ruff PLR1702 caps nesting and the structural-invariants hook is deleted #1876) would turn a lint rule off for 8 files and break the ceiling of 0, so the owner decided against it.
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
UP046classes with PEP 695 type parameters. - Write the micro sign as the escape
\u00b5in the source ofscalars.pyandtests/test_output.py. - Replace the two test imports with
importlib.import_module, with nonoqamarker. - Change no setting. The gate stays green.
Acceptance criteria
- With the Ruff settings of
pyproject.tomlpluspreview = true,ruff checkreports 0 findings forF822,UP046,RUF001andF401. The pull request shows that run. - Each of the 8 modules imports its exported names under
TYPE_CHECKING, andpython -X importtime -c "import devops_cli"shows that the runtime stays lazy. -
uv run mypy srcpasses in strict mode after the rewrite. -
format_duration(0.0005)still returns"500µs". -
tests/test_exceptions.pyimports the two modules withimportlib.import_moduleand has no newnoqamarker. - No Ruff, mypy or ceiling setting changes.
uv run devops cipasses.
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: Runruff check --select F822,UP046,RUF001,F401 --previewand confirm 0 findings. Show the output in the pull request. - Criterion 2: Each of the 8 modules imports its exported names under
TYPE_CHECKINGand the runtime stays lazy.
Verification: Runpython -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: Runuv run mypy srcand confirm it exits 0. - Criterion 4:
format_duration(0.0005)still returns"500μs".
Verification: Runuv run pytest tests/test_output.py -k format_durationand confirm the test passes. - Criterion 5:
tests/test_exceptions.pyimports the two modules withimportlib.import_moduleand has no newnoqamarker.
Verification: Inspecttests/test_exceptions.pylines 145-146 forimportlib.import_moduleand confirm nonoqastring is present. - Criterion 6: No Ruff, mypy or ceiling setting changes. The full CI gate passes.
Verification: Runuv run devops ciand confirm it exits 0. Diffpyproject.tomlagainst 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_MAPdict that maps each name to a (module, attribute) tuple. On first access,importlib.import_moduleloads the submodule andgetattrretrieves 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__.pyandsrc/devops_cli/telemetry/__init__.pyalready import their names underTYPE_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.
Metadata
Metadata
Assignees
Labels
effort/lowEffort Low: little workpriority/p2-mediumPriority P2: standard worksource/agentFiled by an agenttype/refactorType refactor: a new structure, same behaviorvalue/mediumValue Medium
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 23, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The candidate proposes a refactor of linting and code structure.The change improves code quality and enables future tooling improvements.The change helps with linting and code maintainability for a subset of modules.The changes involve standard refactoring patterns and are well-defined.dan-petty commentedon Oct 28, 2026
Status set to Ready at bb46660 (see proposed design in issue body).
chore(main): release 0.13.0 (#2581)