Skip to content

chore: ruff auto-fix PLR6201 resweep — tuple → set in membership tests#27355

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:chore/ruff-plr6201-resweep
May 17, 2026
Merged

chore: ruff auto-fix PLR6201 resweep — tuple → set in membership tests#27355
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:chore/ruff-plr6201-resweep

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Six days after #23937 (608 fixes) the codebase had accumulated 241 new PLR6201 violations. Same mechanical x in (...)x in {...} fix, same zero-risk profile: set lookup is O(1) vs O(n) for tuple and the two are semantically equivalent for hashable scalar membership tests.

This is the resweep cadence noted in tracker #23972 — Phase 1 mechanical auto-fixes need periodic re-runs as the codebase grows.

241 instances fixed via ruff check --select PLR6201 --fix --unsafe-fixes, zero remaining.

What changed

  • 119 files, +244/-244 — every change is a one-line (...){...} swap on the right side of an in / not in comparison
  • Sampled the diff for risky patterns (unhashable values, dict-key semantics, ordering dependencies) — every changed value is a hashable scalar: strings, ints, None, enum members, signal.SIGTERM constants, computed .lower() results

Examples from the diff:

-        if self._state in ("running", "starting"):
+        if self._state in {"running", "starting"}:

-        if msg.type not in (discord.MessageType.default, discord.MessageType.reply):
+        if msg.type not in {discord.MessageType.default, discord.MessageType.reply}:

-    _allow_all = os.getenv("GATEWAY_ALLOW_ALL_USERS", "").lower() in ("true", "1", "yes")
+    _allow_all = os.getenv("GATEWAY_ALLOW_ALL_USERS", "").lower() in {"true", "1", "yes"}

Test plan

  • ruff check clean after the sweep (0 PLR6201 remaining)
  • ✅ Compile checks pass on the largest touched files (cli.py, run_agent.py, gateway/run.py, gateway/platforms/discord.py, model_tools.py)
  • ✅ Broad subset run on tests/gateway/ tests/hermes_cli/ tests/agent/ tests/tools/: 18,187 passed, 59 pre-existing failures
  • Empirically verified against origin/main with the same test shape — identical 59 failure count, identical category. All 59 are xdist test-order flakes unrelated to this change (they pass when re-run in isolation; same set passes/fails on baseline). Apples-to-apples diff: 2 different transcription tests flaked on the PR branch while 2 different approval/hangup tests flaked on baseline — net zero.

Follows

Same template as #23937 (tracker: #23972).

Six days after NousResearch#23937 (608 fixes) the codebase had accumulated 241 new
PLR6201 violations. Same mechanical `x in (...)` → `x in {...}` fix,
same zero-risk profile: set lookup is O(1) vs O(n) for tuple and the
two are semantically equivalent for hashable scalar membership tests.

All 241 instances fixed via `ruff check --select PLR6201 --fix
--unsafe-fixes`, zero remaining. Every changed value is a hashable
scalar (str/int/None/enum/signal); no risk of unhashable runtime
errors. No behavior change.

Test plan:
- 119 files changed, +244/-244 (net zero) — exactly one-line edits
- `ruff check` clean afterward
- Compile checks pass on the largest touched files (cli.py, run_agent.py,
  gateway/run.py, gateway/platforms/discord.py, model_tools.py)
- Subset broad test run on tests/gateway/ tests/hermes_cli/ tests/agent/
  tests/tools/: 18187 passed, 59 pre-existing failures (verified against
  origin/main with the same shape — identical failure count, identical
  category — all xdist test-order flakes unrelated to this change)

Follows the same template as PR NousResearch#23937 ([tracker: NousResearch#23972](NousResearch#23972)).
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P3 Low — cosmetic, nice to have labels May 17, 2026
@NousResearch NousResearch deleted a comment from cardtest15-coder May 17, 2026
@kshitijk4poor kshitijk4poor merged commit 5fba236 into NousResearch:main May 17, 2026
15 of 16 checks passed
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
NousResearch#27355)

Six days after NousResearch#23937 (608 fixes) the codebase had accumulated 241 new
PLR6201 violations. Same mechanical `x in (...)` → `x in {...}` fix,
same zero-risk profile: set lookup is O(1) vs O(n) for tuple and the
two are semantically equivalent for hashable scalar membership tests.

All 241 instances fixed via `ruff check --select PLR6201 --fix
--unsafe-fixes`, zero remaining. Every changed value is a hashable
scalar (str/int/None/enum/signal); no risk of unhashable runtime
errors. No behavior change.

Test plan:
- 119 files changed, +244/-244 (net zero) — exactly one-line edits
- `ruff check` clean afterward
- Compile checks pass on the largest touched files (cli.py, run_agent.py,
  gateway/run.py, gateway/platforms/discord.py, model_tools.py)
- Subset broad test run on tests/gateway/ tests/hermes_cli/ tests/agent/
  tests/tools/: 18187 passed, 59 pre-existing failures (verified against
  origin/main with the same shape — identical failure count, identical
  category — all xdist test-order flakes unrelated to this change)

Follows the same template as PR NousResearch#23937 ([tracker: NousResearch#23972](NousResearch#23972)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants