Skip to content

(style) ruff pass: import sorting, unused imports, typing-stub cleanup - #71

Closed
rhoadesScholar wants to merge 1 commit into
v2.0from
v2.0_patch_ruff
Closed

(style) ruff pass: import sorting, unused imports, typing-stub cleanup#71
rhoadesScholar wants to merge 1 commit into
v2.0from
v2.0_patch_ruff

Conversation

@rhoadesScholar

Copy link
Copy Markdown
Contributor

Split out of #70 so the functional changes there stay reviewable. No behavior changes — this is a ruff --fix pass over the Python sources.

Stacked on v2.0_patch: merge #70 first, or retarget this to v2.0 afterwards.

What's here

44 files, all Python/stubs (no Rust, no docs, no test logic):

  • Import sorting (I001) — stdlib / third-party / first-party grouping across daisy-py/python/daisy/, tests/, benchmarks/, examples/.
  • 3 duplicate-import dedupsbenchmarks/bench_dependency_graph.py, benchmarks/bench_worker_scaling.py, tests/test_worker_restarts.py each imported the same module twice.
  • 9 unused-import removals (F401) — pytest from tests/daisy_compat/test_clients_close.py, tests/daisy_compat/test_dead_workers.py, tests/test_tcp_client.py; threading from examples/mws.py and tests/test_tcp_client.py; subprocess/sys from tests/test_context_passing.py; tempfile from tests/test_done_marker.py; Block from tests/test_tcp_client.py.
  • 2 now-redundant # noqa removals (RUF100) — the suppressed rules no longer fire on those lines.
  • Callable moved typingcollections.abc (UP035) in _daisy.pyi.
  • Stub cleanups in _daisy.pyi — three redundant __repr__ declarations dropped (PYI029: stubs inherit object.__repr__), and timeout: float | int | object | Nonefloat | object | None (PYI041: int is redundant beside float under the numeric tower).

Verification that it's semantically neutral

An AST-level comparison of every changed file's import set (name + alias, order-insensitive) before vs. after confirms the only net changes are the 9 removals, the 3 dedups, and the Callable module move — everything else is pure reordering. Each removed name was checked to have zero remaining references (the one lingering Block match in tests/test_tcp_client.py is inside a comment).

Full suites pass on this branch and on v2.0_patch identically: pytest tests/ 204 passed / 1 xfailed, cargo test -p daisy-core 46 passed.

Not in scope

The tree is not lint-clean after this — ruff check . still reports 74 findings, dominated by BLE001 (18 blind excepts) and S110 (15 try/except/pass), most of which are deliberate best-effort cleanup paths in the logging and worker-teardown code. There's also no ruff config in pyproject.toml and no lint CI job, so none of this is enforced going forward. Happy to follow up with a pinned [tool.ruff] section plus a CI check if you want the invariant to hold.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KxYd8bCjgZLoESSe3smbwF

Pure `ruff --fix` pass over the Python sources with
--select I001,F401,F811,RUF100,UP035,PYI029,PYI041. No behaviour changes:
import sorting, unused-import removals, duplicate-import dedups, redundant
noqa removals, typing.Callable -> collections.abc.Callable, and two .pyi stub
cleanups (redundant __repr__ declarations; float|int -> float).

Rebased from v2.0_patch onto v2.0 now that #70 is closed in favour of #72/#73/#74.
Regenerated rather than cherry-picked, so the two hunks that only existed via #70
(build_wrapper.py, tests/test_worker_serialization.py) are simply absent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rhoadesScholar

Copy link
Copy Markdown
Contributor Author

Rebased onto v2.0 and retargeted, now that #70 is closed in favour of #72 / #73 / #74. This is no
longer stacked on anything.

Two corrections to my original description, both found while doing this:

1. "or retarget this to v2.0 afterwards" was not actually possible as written. Two of the 44 files
existed only via #70build_wrapper.py and tests/test_worker_serialization.py — so a plain retarget
would have left hunks against files that aren't on v2.0. Regenerated the pass against v2.0 instead of
cherry-picking, so those two are simply absent: 42 files, +56/-99 (was 44 files, +59/-102).

2. The "74 findings" figure in my "Not in scope" section is not reproducible, and I should not have
quoted a bare number. There is no [tool.ruff] section and no pinned ruff version in this repo, so the
count depends entirely on the reviewer's local ruff default — an independent run with ruff 0.16.0
--isolated over comparable paths reports 143. Neither number is wrong; there is simply no shared
definition of "lint-clean" here yet.

This pass is now explicit about its rule set rather than relying on a default:

ruff@0.16.0 check --isolated --select I001,F401,F811,RUF100,UP035,PYI029,PYI041 --fix \
  daisy-py/python tests benchmarks examples
Found 69 errors (66 fixed, 3 remaining).

The 3 remaining need --unsafe-fixes (an F811 re-export in an __init__), which would change the
public API surface — out of scope for a lint pass.

Behaviour-neutrality, checked rather than asserted

Same environment, same deselect, with and without this commit:

with    3 failed, 194 passed, 1 deselected, 1 xfailed
without 3 failed, 194 passed, 1 deselected, 1 xfailed

Identical, so the pass changes nothing.

I also checked each removal that could plausibly have been load-bearing, since an unused-import removal
is only safe if the import had no side effect:

  • tests/test_context_passing.pypytest is still imported; only subprocess and sys go. (In
    the diff it looks removed because it moved.)
  • tests/test_tcp_client.pyBlock really is removed, and the only remaining Block match in that
    file is inside a comment (# Block 0 should have been retried).
  • examples/mws.pydaisy.v2 and daisy.logging are still imported, just reordered; only
    threading goes. The file's argparse block runs before its main import cell, and there is no
    matplotlib.use() or equivalent, so the reordering is inert.

On those 3 pre-existing failures

They are on v2.0, not from this PR, and worth knowing since they will show up in anyone's local run:
daisy_compat/test_client.py::test_basic_migrated,
test_block_compat.py::test_status_mutation_propagates_from_compat_block, and
test_context_passing.py::test_shim_workers_get_distinct_identitiesall three are fixed by #73
(they are the editable-install dill failure). Plus
test_run_stats.py::test_slowing_workload_reports_positive_slope, deselected above and fixed by #74.

So #73 + #74 together take the suite green; this PR is neutral on all of it.

The standing offer from the original description still holds: happy to follow up with a pinned
[tool.ruff] section plus a lint CI job, which is what would make this invariant actually hold going
forward.

@pattonw

pattonw commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

I think we both fixed this independently. I also added github action CI tools to cover this now so this should be much better going forward 🙏

@pattonw pattonw closed this Aug 3, 2026
@rhoadesScholar
rhoadesScholar deleted the v2.0_patch_ruff branch August 3, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants