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

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.

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 #23937 ([tracker: #23972](https://github.com/NousResearch/hermes-agent/issues/23972)).
This commit is contained in:
kshitij 2026-05-17 02:29:41 -07:00 committed by GitHub
parent ad00777f04
commit 5fba236644
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
119 changed files with 244 additions and 244 deletions

View file

@ -68,10 +68,10 @@ class TestDiscoverHomebrewNodeDirs:
if p == "/opt/homebrew/opt":
return True
# node@20/bin and node@24/bin exist
if p in (
if p in {
"/opt/homebrew/opt/node@20/bin",
"/opt/homebrew/opt/node@24/bin",
):
}:
return True
return False
@ -171,10 +171,10 @@ class TestFindAgentBrowser:
real_isdir = os.path.isdir
def selective_isdir(path):
if path in (
if path in {
"/data/data/com.termux/files/usr/bin",
"/data/data/com.termux/files/usr/sbin",
):
}:
return True
return real_isdir(path)
@ -486,10 +486,10 @@ class TestRunBrowserCommandPathConstruction:
real_isdir = os.path.isdir
def selective_isdir(path):
if path in (
if path in {
"/data/data/com.termux/files/usr/bin",
"/data/data/com.termux/files/usr/sbin",
):
}:
return True
if path.startswith(str(tmp_path)):
return True

View file

@ -125,7 +125,7 @@ class TestResolveChildPython(unittest.TestCase):
def test_project_with_no_venv_falls_back(self):
"""Project mode without VIRTUAL_ENV or CONDA_PREFIX → sys.executable."""
env = {k: v for k, v in os.environ.items()
if k not in ("VIRTUAL_ENV", "CONDA_PREFIX")}
if k not in {"VIRTUAL_ENV", "CONDA_PREFIX"}}
with patch.dict(os.environ, env, clear=True):
self.assertEqual(_resolve_child_python("project"), sys.executable)

View file

@ -633,7 +633,7 @@ class TestToolsetInclusion:
def test_discord_tools_not_in_other_toolsets(self):
from toolsets import TOOLSETS
for name, ts in TOOLSETS.items():
if name in ("hermes-discord", "hermes-gateway", "discord", "discord_admin"):
if name in {"hermes-discord", "hermes-gateway", "discord", "discord_admin"}:
continue
tools = ts.get("tools", [])
assert "discord" not in tools or name == "discord", (

View file

@ -24,7 +24,7 @@ def _new_filter_matches(path: Path) -> bool:
Returns True when the path SHOULD be filtered out.
"""
return any(part in ('.git', '.github', '.hub') for part in path.parts)
return any(part in {'.git', '.github', '.hub'} for part in path.parts)
class TestOldFilterBrokenOnWindows:

View file

@ -33,7 +33,7 @@ def _restore_tool_and_agent_modules():
original_modules = {
name: module
for name, module in sys.modules.items()
if name in ("tools", "agent", "hermes_cli")
if name in {"tools", "agent", "hermes_cli"}
or name.startswith("tools.")
or name.startswith("agent.")
or name.startswith("hermes_cli.")

View file

@ -62,7 +62,7 @@ class TestCancelledErrorPropagation:
return "clean_return"
outcome = asyncio.run(drive())
assert outcome in ("cancelled_cleanly", "clean_return"), (
assert outcome in {"cancelled_cleanly", "clean_return"}, (
f"MCPServerTask.run wedged on cancel (outcome={outcome}) — "
f"#9930 regression"
)

View file

@ -23,7 +23,7 @@ class TestFindSingularityExecutable:
def test_prefers_apptainer(self):
"""When both are available, apptainer should be preferred."""
def which_both(name):
return f"/usr/bin/{name}" if name in ("apptainer", "singularity") else None
return f"/usr/bin/{name}" if name in {"apptainer", "singularity"} else None
with patch("shutil.which", side_effect=which_both):
assert _find_singularity_executable() == "apptainer"

View file

@ -547,7 +547,7 @@ class TestSkillManageDispatcher:
# No provenance marker on a foreground create — record either missing
# entirely (telemetry best-effort) or present with created_by unset.
rec = usage.get("test-skill") or {}
assert rec.get("created_by") in (None, "", False)
assert rec.get("created_by") in {None, "", False}
def test_create_from_background_review_marks_agent_created(self, tmp_path):
"""Background-review fork creates ARE marked as agent-created."""

View file

@ -101,7 +101,7 @@ class TestTrustLevelFor:
src = self._source()
result = src.trust_level_for("owner/repo")
# No path part — still resolves repo correctly
assert result in ("trusted", "community")
assert result in {"trusted", "community"}
# ---------------------------------------------------------------------------