mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-18 04:41:56 +00:00
chore: ruff auto-fix PLR6201 — tuple → set in membership tests (#23937)
Replace with for all literal-tuple membership tests. Set lookup is O(1) vs O(n) for tuple — consistent micro-optimization across the codebase. 608 instances fixed via `ruff --fix --unsafe-fixes`, 0 remaining. 133 files, +626/-626 (net zero).
This commit is contained in:
parent
8c11710314
commit
2ec8d2b42f
133 changed files with 626 additions and 626 deletions
|
|
@ -9,7 +9,7 @@ if _src_root and _src_root not in sys.path:
|
|||
sys.path.insert(0, _src_root)
|
||||
# Strip '' and '.' — both resolve to CWD at import time and can let a local
|
||||
# directory shadow installed packages.
|
||||
sys.path = [p for p in sys.path if p not in ("", ".")]
|
||||
sys.path = [p for p in sys.path if p not in {"", "."}]
|
||||
|
||||
import json
|
||||
import signal
|
||||
|
|
|
|||
|
|
@ -1706,7 +1706,7 @@ def _available_personalities(cfg: dict | None = None) -> dict:
|
|||
def _validate_personality(value: str, cfg: dict | None = None) -> tuple[str, str]:
|
||||
raw = str(value or "").strip()
|
||||
name = raw.lower()
|
||||
if not name or name in ("none", "default", "neutral"):
|
||||
if not name or name in {"none", "default", "neutral"}:
|
||||
return "", ""
|
||||
|
||||
personalities = _available_personalities(cfg)
|
||||
|
|
@ -2053,7 +2053,7 @@ def _history_to_messages(history: list[dict]) -> list[dict]:
|
|||
if not isinstance(m, dict):
|
||||
continue
|
||||
role = m.get("role")
|
||||
if role not in ("user", "assistant", "tool", "system"):
|
||||
if role not in {"user", "assistant", "tool", "system"}:
|
||||
continue
|
||||
content_text = _content_display_text(m.get("content"))
|
||||
if role == "assistant" and m.get("tool_calls"):
|
||||
|
|
@ -2496,7 +2496,7 @@ def _(rid, params: dict) -> dict:
|
|||
removed = 0
|
||||
with session["history_lock"]:
|
||||
history = session.get("history", [])
|
||||
while history and history[-1].get("role") in ("assistant", "tool"):
|
||||
while history and history[-1].get("role") in {"assistant", "tool"}:
|
||||
history.pop()
|
||||
removed += 1
|
||||
if history and history[-1].get("role") == "user":
|
||||
|
|
@ -3668,7 +3668,7 @@ def _(rid, params: dict) -> dict:
|
|||
{"key": key, "value": "fast" if current_fast else "normal"},
|
||||
)
|
||||
|
||||
if raw in ("", "toggle"):
|
||||
if raw in {"", "toggle"}:
|
||||
nv = "normal" if current_fast else "fast"
|
||||
elif raw in {"fast", "on"}:
|
||||
nv = "fast"
|
||||
|
|
@ -3716,7 +3716,7 @@ def _(rid, params: dict) -> dict:
|
|||
|
||||
if key == "busy":
|
||||
raw = str(value or "").strip().lower()
|
||||
if raw in ("", "status"):
|
||||
if raw in {"", "status"}:
|
||||
return _ok(rid, {"key": key, "value": _load_busy_input_mode()})
|
||||
if raw not in {"queue", "steer", "interrupt"}:
|
||||
return _err(rid, 4002, f"unknown busy mode: {value}")
|
||||
|
|
@ -3781,7 +3781,7 @@ def _(rid, params: dict) -> dict:
|
|||
from hermes_constants import parse_reasoning_effort
|
||||
|
||||
arg = str(value or "").strip().lower()
|
||||
if arg in ("show", "on"):
|
||||
if arg in {"show", "on"}:
|
||||
cfg = _load_cfg()
|
||||
display = (
|
||||
cfg.get("display") if isinstance(cfg.get("display"), dict) else {}
|
||||
|
|
@ -3799,7 +3799,7 @@ def _(rid, params: dict) -> dict:
|
|||
if session:
|
||||
session["show_reasoning"] = True
|
||||
return _ok(rid, {"key": key, "value": "show"})
|
||||
if arg in ("hide", "off"):
|
||||
if arg in {"hide", "off"}:
|
||||
cfg = _load_cfg()
|
||||
display = (
|
||||
cfg.get("display") if isinstance(cfg.get("display"), dict) else {}
|
||||
|
|
@ -3894,7 +3894,7 @@ def _(rid, params: dict) -> dict:
|
|||
cfg0 = _load_cfg()
|
||||
d0 = cfg0.get("display") if isinstance(cfg0.get("display"), dict) else {}
|
||||
cur_b = bool(d0.get("tui_compact", False))
|
||||
if raw in ("", "toggle"):
|
||||
if raw in {"", "toggle"}:
|
||||
nv_b = not cur_b
|
||||
elif raw == "on":
|
||||
nv_b = True
|
||||
|
|
@ -3911,7 +3911,7 @@ def _(rid, params: dict) -> dict:
|
|||
d0 = display if isinstance(display, dict) else {}
|
||||
current = _coerce_statusbar(d0.get("tui_statusbar", "top"))
|
||||
|
||||
if raw in ("", "toggle"):
|
||||
if raw in {"", "toggle"}:
|
||||
nv = "top" if current == "off" else "off"
|
||||
elif raw == "on":
|
||||
nv = "top"
|
||||
|
|
@ -3929,7 +3929,7 @@ def _(rid, params: dict) -> dict:
|
|||
display = cfg.get("display") if isinstance(cfg.get("display"), dict) else {}
|
||||
current = _display_mouse_tracking(display)
|
||||
|
||||
if raw in ("", "toggle"):
|
||||
if raw in {"", "toggle"}:
|
||||
nv = not current
|
||||
elif raw == "on":
|
||||
nv = True
|
||||
|
|
@ -3955,7 +3955,7 @@ def _(rid, params: dict) -> dict:
|
|||
_write_config_key("display.tui_status_indicator", raw)
|
||||
return _ok(rid, {"key": key, "value": raw})
|
||||
|
||||
if key in ("prompt", "personality", "skin"):
|
||||
if key in {"prompt", "personality", "skin"}:
|
||||
try:
|
||||
cfg = _load_cfg()
|
||||
if key == "prompt":
|
||||
|
|
@ -4518,7 +4518,7 @@ def _(rid, params: dict) -> dict:
|
|||
# In the TUI the slash worker subprocess has no reader for that queue,
|
||||
# so we handle them here and return a structured payload.
|
||||
|
||||
if name in ("queue", "q"):
|
||||
if name in {"queue", "q"}:
|
||||
if not arg:
|
||||
return _err(rid, 4004, "usage: /queue <prompt>")
|
||||
return _ok(rid, {"type": "send", "message": arg})
|
||||
|
|
@ -4617,7 +4617,7 @@ def _(rid, params: dict) -> dict:
|
|||
),
|
||||
},
|
||||
)
|
||||
if lower in ("clear", "stop", "done"):
|
||||
if lower in {"clear", "stop", "done"}:
|
||||
had = mgr.has_goal()
|
||||
mgr.clear()
|
||||
return _ok(
|
||||
|
|
@ -4648,7 +4648,7 @@ def _(rid, params: dict) -> dict:
|
|||
{"type": "send", "notice": notice, "message": state.goal},
|
||||
)
|
||||
|
||||
if name in ("snapshot", "snap"):
|
||||
if name in {"snapshot", "snap"}:
|
||||
subcommand = arg.split(maxsplit=1)[0].lower() if arg else ""
|
||||
if subcommand in {"restore", "rewind"}:
|
||||
return _ok(
|
||||
|
|
@ -4893,7 +4893,7 @@ def _(rid, params: dict) -> dict:
|
|||
# Accept both `@folder:path` and the bare `@folder` form so the user
|
||||
# sees directory listings as soon as they finish typing the keyword,
|
||||
# without first accepting the static `@folder:` hint.
|
||||
if is_context and query in ("file", "folder"):
|
||||
if is_context and query in {"file", "folder"}:
|
||||
prefix_tag, path_part = query, ""
|
||||
elif is_context and query.startswith(("file:", "folder:")):
|
||||
prefix_tag, _, tail = query.partition(":")
|
||||
|
|
@ -5637,7 +5637,7 @@ def _(rid, params: dict) -> dict:
|
|||
|
||||
return _ok(rid, payload)
|
||||
|
||||
if action in ("on", "off"):
|
||||
if action in {"on", "off"}:
|
||||
enabled = action == "on"
|
||||
# Runtime-only flag (CLI parity) — no _write_config_key, so the
|
||||
# next TUI launch starts with voice OFF instead of auto-REC from a
|
||||
|
|
@ -5870,7 +5870,7 @@ def _(rid, params: dict) -> dict:
|
|||
removed = 0
|
||||
with session["history_lock"]:
|
||||
history = session.get("history", [])
|
||||
while history and history[-1].get("role") in ("assistant", "tool"):
|
||||
while history and history[-1].get("role") in {"assistant", "tool"}:
|
||||
history.pop()
|
||||
removed += 1
|
||||
if history and history[-1].get("role") == "user":
|
||||
|
|
@ -6428,7 +6428,7 @@ def _(rid, params: dict) -> dict:
|
|||
)
|
||||
),
|
||||
)
|
||||
if action in ("remove", "pause", "resume"):
|
||||
if action in {"remove", "pause", "resume"}:
|
||||
return _ok(rid, json.loads(cronjob(action=action, job_id=jid)))
|
||||
return _err(rid, 4016, f"unknown cron action: {action}")
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue