pre-commit: adopt ruff 0.17.3 #6743
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #6743"
general
weight: 0.35
RoniKishner
##### What this PR does / why we need it:
Second half of the pre-commit autoupdate from #6639 (the flake8/mypy/check-jsonschema bumps landed in #6742): adopts ruff v0.16.4 → v0.17.3. Rebased on main after #6742 merged. With
preview = true, ruff 0.17's newly promoted rules flagged 80 violations, ruff-format started formatting markdown code blocks (touching generateddocs/site), and ruff RUF100 stripped the flake8-forkFCN001noqas. This PR resolves all of it:docs/siteexcluded from ruff entirely (pyproject.toml) — generated docs must never be modified in PRsforce-exclude = truein[tool.ruff]:extend-excludeonly applies when ruff walks the tree, so directruff check <file>invocations (and any hook not passing--force-exclude) silently still linted the excluded paths; making it explicit keeps the config self-containedFCN001noqas inlibs/vm/vm.pythat RUF100 stripped;external = ["FCN"]added so ruff leaves flake8-fork codes alonePLW0108ignored: TimeoutSamplerfunc=lambda: x.instance.to_dict()lambdas rely on late binding of the dynamic.instanceattribute — ruff's suggested inline would freeze a stale snapshotFURB113(append-in-loop→extend),FURB142(add-in-loop→update),C420(dict comprehension→fromkeys),RUF055(re.sub with plain pattern→replace),PLC0207(split→maxsplit),FURB156(hardcoded charset),SIM110(for-loop→any),FURB145(slice→copy),UP042((str, Enum)→StrEnum)RUF075fixed: 11 fallible context managers wrapped in plain try/finally (the two verification-type CMs,_confirm_status_success_on_updateandwait_for_resize, keep their post-yield wait unconditional for simplicity)PT012fixed without losing diagnostics: ruff 0.17 tightened the rule — it now also flags a single trailing statement after the expected-to-fail call, which the five negative tests below had. A bareLOGGER.errorinside the block does not satisfy it (verified with 0.17.3: two statements are still flagged), so each site is nowtry/except/elsewith the original wording inpytest.fail: the message stops being unreachable dead code and becomes the failure reason in the report, with no suppression and noignoreentry:-
tests/virt/cluster/common_templates/custom_namespace/test_custom_namespace.py(theLOGGER.errorabout a template that unexpectedly reconciled post-revert)-
tests/virt/cluster/migration_and_maintenance/rbac_hardening/test_migration_rights.py-
tests/virt/node/hotplug/test_cpu_memory_hotplug.py(CPU and memory above the max value)-
tests/virt/node/migration_and_maintenance/test_node_maintenance.py-
tests/storage/cdi_import/test_import_http.pyconsumes itsTimeoutSamplerwith an intentionally empty loop body, so the rule is satisfied without any suppression and the reason sits next to the code in a plain commentPLC2801:utilities/unittestsis excluded from linting only ([tool.ruff.lint] exclude = ["utilities/unittests/"]), mirroring the flake8 hook exclusion — those hook unit tests embed intentionally non-compliant fixtures and drive mock context managers'__enter__directly (PLC2801), plus deliberately loose pytest patterns (RUF043, PLR0133, PT012): 13 findings, none of them introduced or in scope of a revision bump.ruff formatreports every file there already formatted, so there is no formatting exclusion. The/suffix is load-bearing: section-levelexcludepatterns are matched against files, so a bare directory name is silently ignored (verified with ruff 0.17.3). The paramiko FIPS monkey-patch now assigns throughcast(Any, ...)and needs no directive at all (a plain assignment fails mypy method-assign,setattrtrips B010, andtype.__setattr__trips PLC2801 — the cast satisfies all three while staying an ordinary attribute assignment)RUF027: 5 assertion messages were missing theirfprefix (they printed literal{placeholders}on failure) — fixed; the shared.format()log template intests/network/utils.pykeeps its eager.format()call sites, with only the placeholder names decoupled from in-scope variables ({iface}/{address}) — RUF027 fires when placeholders shadow local variable namesUP052(context-managerGeneratorannotations),RUF043(rawmatch=patterns),RUF045(dataclass field annotations),RUF069,FURB110(or-operator),D301(raw docstrings) fixed inline (production/test code only;utilities/unittestsis ruff-excluded, see above)There are no suppressions in this change at all:
scripts/pre_commit_hooks/exceptions.tomlstaysexceptions = [], no file carries anoqaortype: ignore, and no per-file-ignore was added — every site is handled by config or by restructuring the code.Verification: all pre-commit hooks pass at commit time on this branch (including
check-linter-directives, also validated against the workflow's net-diff staging semantics);tox -e utilities-unittests— 931 passed, 99.33% coverage (threshold 95%);scripts/tests_analyzer— 136 passed. ruff 0.17.3 was verified to be a no-op for this repo:ruff check .andruff format --check .report zero findings on it (its only behavioural additions are the preview ruleshared-clock-mock, a more conservativeUP032fix, and speedups), and all hooks pass with the bumped rev. On the review-fix commit (97dc91ac):ruff check .andruff format --check .clean, all pre-commit hooks pass for the touched files,utilities/unittestsfingerprint/prompt tests pass, and thetry/except/elseshape was probed in isolation (expected exception → pass; no exception →Failed: <original message>).##### Which issue(s) this PR fixes:
##### Special notes for reviewer:
Split 2/2 of #6639 (supersedes it); #6742 already merged — this PR is rebased on main and its diff is exactly the ruff adoption. Contains no
docs/sitechanges (the bot's markdown reformat was dropped, not reverted file-by-file) and no changes toutilities/unittests(lint-excluded, see above). Utilities unit-test note: touchedutilities/modules (virt.py,infra.py,storage.py— coverage-omitted;pytest_utils.py,console.py— docstring/or-operator and monkey-patch refactor) carry no behavior change beyond lint-mandated try/finally wrapping. The two non-omitted spots CodeRabbit flagged are covered by existing tests, which pass:test_get_fingerprint_returns_fips_safe_md5(exercises thepatch_paramiko_for_fipsrefactor through the patchedPKey.get_fingerprint) and thetest_default_promptcases inutilities/unittests/test_console.py(theprompt if prompt else ...→prompt or ...rewrite).##### jira-ticket:
---
Assisted-by: PI (rits/zai-org/glm-5-3)
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Improved cleanup and state restoration in test helpers, including when operations fail or are interrupted.
Ensured status checks run after updates and improved several test failure messages to display relevant values.
Chores
Updated linting and formatting configuration and refreshed the Ruff pre-commit version.
* Made minor documentation and test-maintenance updates; no user-facing product behavior changes are included.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->