Repository navigation
chore: bump ruff to v0.16.5, and clear its new default rules - #1101
Conversation
ruff 0.16.0 expanded the default rule set from 59 rules to 413 and 0.15.0 moved the formatter to the 2026 style guide, so a repo with no ruff config picks up 64 findings. All fixes preserve behaviour: PLW1510 becomes an explicit check=False rather than a semantic change. Two findings are suppressed with reasons inline.
tend-agent
left a comment
There was a problem hiding this comment.
One finding, in shared/steps/_common.py.
That module documents its own floor — "an adopter can select an older image through the documented runs-on override, so these modules stay 3.10-compatible" — and UP017 rewrote datetime.timezone.utc to datetime.UTC, which is 3.11+. utcnow() is reached from rate_limit_preflight.main(), the first step of every job on both harnesses, so an adopter who has overridden runs-on to ubuntu-22.04 (system python3 is 3.10) gets AttributeError: module 'datetime' has no attribute 'UTC' before the agent boots. CI can't see it: the step bodies only ever execute under the dev env's 3.12.
Worth noting the mechanism, because it will recur. Ruff infers target-version from the nearest requires-python, which for shared/steps/ is the workspace root's >=3.12 — so every future ruff --fix will keep proposing 3.11+-only rewrites in a directory that has to run on 3.10, and only a reader who remembers the docstring will catch them. A shared/steps/.ruff.toml holding target-version = "py310" states the floor where ruff reads it; I confirmed the hierarchical config resolves for that path and that the UP017 finding disappears under it. That is new config in a repo that has deliberately carried none, so the inline suggestion below is the minimal alternative instead — the same # noqa + inline-reason pattern this PR already uses for LOG015 and PLW1509. Either closes this instance; only the config file closes the next one.
The rest of the behaviour-preserving claim holds where I traced it: check=False matches the implicit default at all 19 sites, and the two runtime insertions in sandbox_setup.py were already branching on returncode; UP037's unquoting is safe because test_token_report.py carries from __future__ import annotations; PLR1730's max(since, at) keeps the original tie-break; PIE810 and FURB167 are constant-for-constant. Nothing in the repo manipulates sys.path and none of the reordered modules has an import-time side effect, so the I001 churn is inert.
`datetime.UTC` is 3.11+, but shared/steps/ modules run on the runner's system python3 and are documented as 3.10-compatible so an adopter can pin an older `runs-on` image. `utcnow()` is on rate_limit_preflight's main path, so the rewrite would raise AttributeError before the agent boots on ubuntu-22.04. Restore `datetime.timezone.utc` with a `# noqa: UP017` and the reason inline. Also drop the discarded tuple in test_token_report where both elements are unused, and use the file's existing `_` idiom for the two sites that keep only `output`.
Moves `ruff-pre-commit` from v0.14.11 to v0.16.5, held out of #1099 because it isn't an ordinary rev bump: ruff 0.16.0 expanded the default rule set from 59 rules to 413, and 0.15.0 moved the formatter to the 2026 style guide. The repo carries no ruff configuration, so it takes those defaults directly — 64 findings appear on a codebase that reports `All checks passed!` under the old pin. Every change here is behaviour-preserving; the point is to move the pin without smuggling in a semantic change. Three findings are suppressed rather than fixed, each with the reason inline. Each is in code where satisfying the rule would be a real change: the mitmproxy addon's root-logger call (`LOG015`) sits in the credential-injection path and follows mitmproxy's documented addon pattern, `preexec_fn` in the OAuth helper (`PLW1509`) is what gives the child its controlling terminal, and `UP017` in `shared/steps/_common.py` would rewrite `datetime.timezone.utc` to the 3.11+ `datetime.UTC` in a directory documented as 3.10-compatible (those step bodies run on the runner's system `python3`, which is 3.10 on an `ubuntu-22.04` `runs-on` override). Say the word and either can become a named logger / restructured spawn instead. <details><summary>What the 64 findings were, and how each was handled</summary> | Rule | n | Handling | |---|---|---| | `I001` unsorted-imports | 27 | ruff's own safe fix | | `PLW1510` subprocess-run-without-check | 19 | explicit `check=False` at every site — this is the current behaviour spelled out, not a change to it | | `RUF059` unused-unpacked-variable | 5 | ruff's fix (`rows` → `_rows`) | | `UP037` quoted-annotation | 3 | ruff's fix; the file carries `from __future__ import annotations`, so unquoting is safe | | `UP017` datetime-timezone-utc | 2 | one ruff's fix (a test); one suppressed in `shared/steps/`, reason inline | | `PIE810` multiple-starts-ends-with | 2 | ruff's fix (tuple argument) | | `FURB167` regex-flag-alias | 2 | ruff's fix | | `PLR1730` if-stmt-min-max | 1 | ruff's fix | | `PERF102` incorrect-dict-iterator | 1 | ruff's fix; the discarded key was genuinely unused | | `LOG015` root-logger-call | 1 | suppressed, reason inline | | `PLW1509` subprocess-popen-preexec-fn | 1 | suppressed, reason inline | `PLW1510` has no autofix in ruff, so `check=False` was inserted at each call's closing paren via an AST pass that refused to write any file it couldn't re-parse, then normalised by `ruff format`. **Formatting.** 14 files are reformatted. One is the 2026 style guide's own doing — it is the only file `ruff format --check` rewrites against `main` at v0.16.5. The other 13 are the `check=False` insertions being wrapped back onto their lines. **Verification.** `pre-commit run --all-files` passes at the new rev, and `uv run pytest` passes (763), including the regtest snapshots — so no generated workflow output moved. `worker/` and `site/` are untouched. **The alternative, not taken.** Pinning `select = ["E4", "E7", "E9", "F"]` would reproduce the pre-0.16 default exactly and drop the diff to one line. That trades a config-free repo for a frozen rule set, which reads like the wrong direction for a repo that has deliberately carried no ruff config — but it is a one-line change if you'd rather have it. </details> --------- Co-authored-by: tend-agent <[email protected]>
Moves
ruff-pre-commitfrom v0.14.11 to v0.16.5, held out of #1099 because it isn't an ordinary rev bump: ruff 0.16.0 expanded the default rule set from 59 rules to 413, and 0.15.0 moved the formatter to the 2026 style guide. The repo carries no ruff configuration, so it takes those defaults directly — 64 findings appear on a codebase that reportsAll checks passed!under the old pin. Every change here is behaviour-preserving; the point is to move the pin without smuggling in a semantic change.Three findings are suppressed rather than fixed, each with the reason inline. Each is in code where satisfying the rule would be a real change: the mitmproxy addon's root-logger call (
LOG015) sits in the credential-injection path and follows mitmproxy's documented addon pattern,preexec_fnin the OAuth helper (PLW1509) is what gives the child its controlling terminal, andUP017inshared/steps/_common.pywould rewritedatetime.timezone.utcto the 3.11+datetime.UTCin a directory documented as 3.10-compatible (those step bodies run on the runner's systempython3, which is 3.10 on anubuntu-22.04runs-onoverride). Say the word and either can become a named logger / restructured spawn instead.What the 64 findings were, and how each was handled
I001unsorted-importsPLW1510subprocess-run-without-checkcheck=Falseat every site — this is the current behaviour spelled out, not a change to itRUF059unused-unpacked-variablerows→_rows)UP037quoted-annotationfrom __future__ import annotations, so unquoting is safeUP017datetime-timezone-utcshared/steps/, reason inlinePIE810multiple-starts-ends-withFURB167regex-flag-aliasPLR1730if-stmt-min-maxPERF102incorrect-dict-iteratorLOG015root-logger-callPLW1509subprocess-popen-preexec-fnPLW1510has no autofix in ruff, socheck=Falsewas inserted at each call's closing paren via an AST pass that refused to write any file it couldn't re-parse, then normalised byruff format.Formatting. 14 files are reformatted. One is the 2026 style guide's own doing — it is the only file
ruff format --checkrewrites againstmainat v0.16.5. The other 13 are thecheck=Falseinsertions being wrapped back onto their lines.Verification.
pre-commit run --all-filespasses at the new rev, anduv run pytestpasses (763), including the regtest snapshots — so no generated workflow output moved.worker/andsite/are untouched.The alternative, not taken. Pinning
select = ["E4", "E7", "E9", "F"]would reproduce the pre-0.16 default exactly and drop the diff to one line. That trades a config-free repo for a frozen rule set, which reads like the wrong direction for a repo that has deliberately carried no ruff config — but it is a one-line change if you'd rather have it.