Skip to content

Fix Ruff's smaller-rule findings (ISC, PT, RET, ARG, PTH, E, SIM, RUF, FBT, C4, PERF, PLW, A) - #69

Merged
anth-volk merged 3 commits into
mainfrom
claude/ruff-smaller-rules
Nov 3, 2026
Merged

anth-volk merged 3 commits into
mainfrom
claude/ruff-smaller-rules

Conversation

@anth-volk

@anth-volk anth-volk commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #68

Part of #53.

What this does

The fifth of the pull requests stacked on #55 that fix the Ruff findings #55 leaves ignored: the 261 findings here (262 on #55) in the smaller-rule families, after which only C90 and PLR stay on the temporary list. Stacked on #67. Behaviour is unchanged in package code; some tests become stricter.

  • ISC004 (108): implicit string concatenations inside lists, tuples and sets are wrapped in parentheses (Ruff's fix), which keeps each value. I read each one for a missing comma between two items; none looked like one. This rule is stable in Ruff 0.16 and a preview rule in the services' Ruff 0.15 (Select every Ruff rule, configured as the simulation API and the Public API configure it #55).
  • Tests (PT, 72):
    • PT018 (58): one assert per condition.
    • PT011 (9): pytest.raises gets a match= for the message the code raises on that path.
    • PT006 (3): tuple parametrize names.
    • PT017 (2): pytest.raises instead of asserting inside an except block.
  • Equivalent rewrites:
    • RET501, RET502, RET503 (15): an explicit return None.
    • SIM105 (6): contextlib.suppress, with the same exception types.
    • SIM102, SIM117: combined if and with statements.
    • C408, C416, C419, C420: comprehensions. C419 makes the Hugging Face module's shutdown all(...) a generator, which stops at the first worker still running. That has the same result, because wait only acquires and releases a lock, and once one worker's wait has used up the deadline, the rest would be non-blocking.
    • PERF401 (3), RUF005 (4), RUF022, RUF036, RUF059, FBT003.
    • E501 (9, plus 15 lines that ISC004's parentheses pushed past 88 columns): wrapped. Three docstrings were rewrapped or reworded, and the Python inside two test scripts' strings was rewrapped; those tests pass.
    • 9 of the 10 PTH findings: the pathlib equivalent where it is exact.
  • 15 # noqa, each with its reason above it (20 before round 1):
    • ARG002 ×12 and ARG001: signatures fixed by their callers (redirect_request, SQLAlchemy's TypeDecorator, the ServiceModule protocol, the ReleaseChangePolicy type).
    • A002 ×2: overrides of log_message(format).
  • Round 1 removed five suppressions:
    • _run_files_to_commit takes run_files and at_shutdown as keyword-only arguments, as its sibling methods do (FBT001).
    • The fake collector builds its socket path with str(Path(directory) / "tls.sock"), which gives the same string as os.path.join (PTH118).
    • CollectorDelivery passes _http_post and huggingface_token directly instead of through lambdas (PLW0108). I checked every test that replaces either function on the collector module: each does so before it builds a delivery. The one that replaces huggingface_token afterwards builds no further delivery.
  • Renames: one unused unpacked name in a test (_errors). Two test-local parameters are now keyword-only; both are only passed by keyword.
  • Ruff no longer ignores these families, and no # noqa in the tree is unused (RUF100).

A helper agent made these changes from a brief I gave it, with the decisions above. I reviewed every package-code change. Of the 68 changed Python files, 24 differ only in layout or docstrings; 12 package modules and 32 test and tool files have code changes.

Test-first record

There is no red step, since nothing changes behaviour in package code.

Commit Result
eb82bc2 The fixes ruff check ., ruff format --check . and the five guards pass. The 63 test functions whose code changed pass by node ID (164 cases), including every match=, the two rewrapped scripts and the keyword-only changes. The changed helper in tests/test_collector_contract.py needs the pinned collector, so CI's collector job runs it.
Merge of #67's round 1, and the fragment ruff check . and ruff format --check . pass.

Review round 1:

Commit Result
ab2efa5 Five suppressions dropped, and the fragment's count ruff check ., ruff format --check . and the guards pass. The one test that uses the fake collector's TLS upload socket passes by node ID. Ruff prints no invalid-noqa warning since the merge of #67's fix.

No other test was run; CI runs them.

CI

No workflow, trigger or script changes, and no environment variable or secret is read differently.

Release

The fragment is changelog.d/ruff-smaller-rules.changed.md. With #65's added fragment below it in the stack, merging releases a minor version (0.12.0); on its own this fragment would give a patch bump.

🤖 Generated with Claude Code

@anth-volk
anth-volk added this pull request to stack #46 October 30, 2026 21:18
@anth-volk anth-volk changed the title claude/ruff smaller rules Fix Ruff's smaller-rule findings (ISC, PT, RET, ARG, PTH, E, SIM, RUF, FBT, C4, PERF, PLW, A) Oct 30, 2026
@anth-volk
anth-volk removed this pull request from stack #46 November 2, 2026 14:03
@anth-volk
anth-volk added this pull request to stack #72 November 2, 2026 14:04
@anth-volk
anth-volk force-pushed the claude/ruff-smaller-rules branch 2 times, most recently from 181225f to 7ba6b1f Compare November 2, 2026 15:07
anth-volk added a commit that referenced this pull request Nov 2, 2026
#58 to #69 were rebased onto main after #55 merged, so this merge
conflicted in the 18 files this branch had changed on top of #69. Each
keeps this branch's side, plus the version commit's bump in
pyproject.toml; python -m scripts.rules render regenerated the rules
view. The tree differs from e0cfd8e exactly by main's version commit
d732aab (2b88444..d732aab).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk force-pushed the claude/ruff-smaller-rules branch from 0825c5b to f5bcfa7 Compare November 2, 2026 16:49
anth-volk added a commit that referenced this pull request Nov 2, 2026
#63 to #69 were rebased onto main after #58 merged, so this merge
conflicted in the 14 files this branch had changed on top of #69. Each
keeps this branch's side, plus the release's version bump in
pyproject.toml; python -m scripts.rules render left the rules views as
they were. The tree differs from 8776389 exactly by main's release
(ff7d34b..a837a06).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk force-pushed the claude/ruff-smaller-rules branch from 1bb66e5 to d82d720 Compare November 2, 2026 17:47
anth-volk added a commit that referenced this pull request Nov 3, 2026
#65 to #69 were rebased onto main after #63 merged, so this merge
conflicted in the 13 files this branch had changed on top of #69. Each
keeps this branch's side, plus the release's version bump in
pyproject.toml; python -m scripts.rules render left the rules views as
they were. The tree differs from 746e71e exactly by main's release
(213b093..ed06bc2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk force-pushed the claude/ruff-smaller-rules branch from 6b76595 to 26583bb Compare November 3, 2026 14:22
anth-volk added a commit that referenced this pull request Nov 3, 2026
#67 and #69 were rebased onto main after #65 merged, so this merge
conflicted in the 9 files this branch had changed on top of #69. Each
keeps this branch's side, plus the release's version bump in
pyproject.toml; python -m scripts.rules render left the rules views as
they were. The tree differs from 54f2464 exactly by main's release
(e233d97..d79aa4d).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from claude/ruff-safety to main November 3, 2026 16:32
@anth-volk
anth-volk force-pushed the claude/ruff-smaller-rules branch from adb4457 to 6518881 Compare November 3, 2026 16:32
@anth-volk
anth-volk marked this pull request as ready for review November 3, 2026 18:56
anth-volk and others added 3 commits November 3, 2026 22:56
- ISC004 (108): implicit concatenations in collection literals are
  wrapped in parentheses; none looked like a missing comma.
- PT018, PT011, PT006, PT017 (tests): one assert per condition, match=
  on the broad pytest.raises, tuple parametrize names, pytest.raises
  instead of asserting in an except block.
- RET, SIM, C4, PERF, RUF005, RUF022, RUF036, RUF059, FBT003, E501 and 9
  of 10 PTH findings: the equivalent rewrites (explicit return None,
  contextlib.suppress, combined if and with statements, comprehensions,
  unpacking, sorted __all__, wrapped lines, pathlib).
- 20 `# noqa`, each with its reason: ARG for signatures fixed by their
  callers (redirect_request, TypeDecorator, the ServiceModule protocol),
  FBT001 where callers pass flags positionally, PLW0108 where a lambda
  must look up a function tests replace, A002 on log_message(format),
  PTH118 where httpx's uds option takes a str.
- Ruff no longer ignores the smaller-rule families.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- _run_files_to_commit takes run_files and at_shutdown as keyword-only
  arguments, as its sibling methods do, and both calls pass them by
  name, so FBT001 needs no suppression.
- The fake collector builds the upload socket path with
  str(Path(directory) / "tls.sock"), the same string as os.path.join.
- CollectorDelivery passes _http_post and huggingface_token directly:
  every test replaces them before it builds a delivery, so the lambdas
  that looked them up at each call were not needed.
- The changelog fragment says 15 findings keep a `# noqa` with a reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk force-pushed the claude/ruff-smaller-rules branch from 6518881 to 88c4cc6 Compare November 3, 2026 18:56
anth-volk added a commit that referenced this pull request Nov 3, 2026
#69 was rebased onto main after #67 merged, so this merge conflicted in
the 5 files this branch had changed on top of #69. Each keeps this
branch's side, plus the release's version bump in pyproject.toml;
python -m scripts.rules render left the rules views as they were. The
tree differs from ca655a7 exactly by main's release (6625a18..72205e8).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk merged commit a330bb7 into main Nov 3, 2026
12 checks passed
@anth-volk
anth-volk deleted the claude/ruff-smaller-rules branch November 3, 2026 20:34
anth-volk added a commit that referenced this pull request Nov 3, 2026
Brings in #69's merge and the release commit after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Nov 3, 2026
Carries main (with #69's merge) up the stack. No Python file changes, so the
noqa baseline is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Fix Ruff's smaller-rule findings (ISC, PT, RET, ARG, PTH, E, SIM, RUF, FBT, C4, PERF, PLW, A)

1 participant