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:
@@ -592,7 +592,7 @@ def _http_once(
|
||||
# Build a new request with cleaned headers
|
||||
clean_headers = {
|
||||
k: v for k, v in req2.header_items()
|
||||
if k.lower() not in ("x-api-key", "authorization", "cookie")
|
||||
if k.lower() not in {"x-api-key", "authorization", "cookie"}
|
||||
}
|
||||
new_req = urllib.request.Request(newurl, headers=clean_headers, method="GET")
|
||||
return new_req
|
||||
@@ -743,13 +743,13 @@ def safe_path_join(base: Path, *parts: str) -> Path:
|
||||
|
||||
def media_type_from_filename(filename: str) -> str:
|
||||
ext = Path(filename).suffix.lower()
|
||||
if ext in (".mp4", ".webm", ".avi", ".mov", ".mkv", ".gif", ".webp"):
|
||||
if ext in {".mp4", ".webm", ".avi", ".mov", ".mkv", ".gif", ".webp"}:
|
||||
return "video"
|
||||
if ext in (".wav", ".mp3", ".flac", ".ogg", ".m4a"):
|
||||
if ext in {".wav", ".mp3", ".flac", ".ogg", ".m4a"}:
|
||||
return "audio"
|
||||
if ext in (".glb", ".obj", ".ply", ".gltf"):
|
||||
if ext in {".glb", ".obj", ".ply", ".gltf"}:
|
||||
return "3d"
|
||||
if ext in (".json", ".txt", ".md"):
|
||||
if ext in {".json", ".txt", ".md"}:
|
||||
return "text"
|
||||
return "image"
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ def trace_to_node(workflow: dict, link: list, *, max_hops: int = 8) -> str | Non
|
||||
return None
|
||||
cls = node.get("class_type", "")
|
||||
# Reroute / Primitive / passthrough wrappers
|
||||
if cls in ("Reroute", "PrimitiveNode", "Note", "easy showAnything"):
|
||||
if cls in {"Reroute", "PrimitiveNode", "Note", "easy showAnything"}:
|
||||
inputs = node.get("inputs", {}) or {}
|
||||
# Find first link-shaped input and follow it
|
||||
next_link = next((v for v in inputs.values() if is_link(v)), None)
|
||||
@@ -105,7 +105,7 @@ def find_negative_prompt_node(workflow: dict) -> str | None:
|
||||
src = trace_to_node(workflow, neg)
|
||||
if src and isinstance(workflow.get(src), dict):
|
||||
cls = workflow[src].get("class_type", "")
|
||||
if cls.startswith("CLIPTextEncode") or cls in ("smZ CLIPTextEncode", "BNK_CLIPTextEncodeAdvanced"):
|
||||
if cls.startswith("CLIPTextEncode") or cls in {"smZ CLIPTextEncode", "BNK_CLIPTextEncodeAdvanced"}:
|
||||
return src
|
||||
return None
|
||||
|
||||
@@ -121,7 +121,7 @@ def find_positive_prompt_node(workflow: dict) -> str | None:
|
||||
src = trace_to_node(workflow, pos)
|
||||
if src and isinstance(workflow.get(src), dict):
|
||||
cls = workflow[src].get("class_type", "")
|
||||
if cls.startswith("CLIPTextEncode") or cls in ("smZ CLIPTextEncode", "BNK_CLIPTextEncodeAdvanced"):
|
||||
if cls.startswith("CLIPTextEncode") or cls in {"smZ CLIPTextEncode", "BNK_CLIPTextEncodeAdvanced"}:
|
||||
return src
|
||||
return None
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
diag["source"] = res.get("source")
|
||||
diag["prompt_id"] = args.prompt_id
|
||||
emit_json(diag)
|
||||
return 0 if diag.get("status_str") not in ("error",) else 1
|
||||
return 0 if diag.get("status_str") not in {"error",} else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -203,7 +203,7 @@ def detect_apple_silicon() -> dict | None:
|
||||
|
||||
|
||||
def detect_intel_arc() -> dict | None:
|
||||
if platform.system() not in ("Linux", "Windows"):
|
||||
if platform.system() not in {"Linux", "Windows"}:
|
||||
return None
|
||||
if shutil.which("clinfo"):
|
||||
out = _run(["clinfo", "--list"])
|
||||
|
||||
@@ -204,7 +204,7 @@ class ComfyRunner:
|
||||
s = data.get("status")
|
||||
if s == "completed":
|
||||
return {"status": "success", "data": data}
|
||||
if s in ("failed",):
|
||||
if s in {"failed",}:
|
||||
return {"status": "error", "data": data}
|
||||
if s == "cancelled":
|
||||
return {"status": "cancelled", "data": data}
|
||||
@@ -386,7 +386,7 @@ class ComfyRunner:
|
||||
# local path; otherwise put the file in output_dir flat.
|
||||
target_parts: list[str] = []
|
||||
if preserve_subfolder and subfolder:
|
||||
target_parts.extend(p for p in subfolder.split("/") if p and p not in (".", ".."))
|
||||
target_parts.extend(p for p in subfolder.split("/") if p and p not in {".", ".."})
|
||||
target_parts.append(filename)
|
||||
out_path = safe_path_join(output_dir, *target_parts)
|
||||
|
||||
@@ -467,7 +467,7 @@ def inject_params(
|
||||
# Auto-randomize seed when it's -1 in args, or when randomize_seed_if_unset
|
||||
# and user didn't pass a seed.
|
||||
if "seed" in params:
|
||||
if "seed" in args and args["seed"] in (None, -1, "-1"):
|
||||
if "seed" in args and args["seed"] in {None, -1, "-1"}:
|
||||
args = dict(args)
|
||||
args["seed"] = coerce_seed(args["seed"])
|
||||
warnings.append(f"seed=-1 expanded to {args['seed']}")
|
||||
|
||||
@@ -170,7 +170,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
parsed = parse_binary_frame(msg)
|
||||
if parsed is None:
|
||||
continue
|
||||
if parsed["kind"] in ("preview", "preview_with_metadata") and preview_dir:
|
||||
if parsed["kind"] in {"preview", "preview_with_metadata"} and preview_dir:
|
||||
img_bytes = parsed.get("image_bytes", b"")
|
||||
if img_bytes:
|
||||
ext = parsed.get("ext", "png")
|
||||
|
||||
@@ -53,7 +53,7 @@ class TestCloudEndpointsLive:
|
||||
url = resolve_url("https://cloud.comfy.org", "/object_info")
|
||||
r = http_get(url, headers={"X-API-Key": cloud_key})
|
||||
# Should be either 200 (paid) or 403 (free) — not 404 / 500
|
||||
assert r.status in (200, 403)
|
||||
assert r.status in {200, 403}
|
||||
if r.status == 403:
|
||||
# Body should mention the limitation
|
||||
assert "free tier" in r.text().lower() or "subscription" in r.text().lower()
|
||||
|
||||
@@ -40,7 +40,7 @@ class TestConnectionTracing:
|
||||
}
|
||||
# Should hit max_hops without infinite loop
|
||||
result = trace_to_node(wf, ["1", 0], max_hops=5)
|
||||
assert result in ("1", "2") # any node, just don't hang
|
||||
assert result in {"1", "2"} # any node, just don't hang
|
||||
|
||||
|
||||
class TestPositiveNegativeDetection:
|
||||
|
||||
@@ -721,7 +721,7 @@ def drive_share(args):
|
||||
"type": args.type,
|
||||
"role": args.role,
|
||||
}
|
||||
if args.type in ("user", "group"):
|
||||
if args.type in {"user", "group"}:
|
||||
if not args.email:
|
||||
print("ERROR: --email is required for type=user or type=group", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -181,7 +181,7 @@ def http_get(url, params=None, retries=MAX_RETRIES, silent=False):
|
||||
return json.loads(raw)
|
||||
except urllib.error.HTTPError as exc:
|
||||
last_error = f"HTTP {exc.code}: {exc.reason} for {url}"
|
||||
if exc.code in (429, 503, 502, 504):
|
||||
if exc.code in {429, 503, 502, 504}:
|
||||
time.sleep(RETRY_DELAY * attempt)
|
||||
else:
|
||||
if silent:
|
||||
@@ -217,7 +217,7 @@ def http_get_text(url, params=None, retries=MAX_RETRIES, silent=False):
|
||||
return resp.read().decode("utf-8")
|
||||
except urllib.error.HTTPError as exc:
|
||||
last_error = f"HTTP {exc.code}: {exc.reason} for {url}"
|
||||
if exc.code in (429, 503, 502, 504):
|
||||
if exc.code in {429, 503, 502, 504}:
|
||||
time.sleep(RETRY_DELAY * attempt)
|
||||
else:
|
||||
if silent:
|
||||
@@ -256,7 +256,7 @@ def http_post(url, data_str, retries=MAX_RETRIES):
|
||||
return json.loads(raw)
|
||||
except urllib.error.HTTPError as exc:
|
||||
last_error = f"HTTP {exc.code}: {exc.reason}"
|
||||
if exc.code in (429, 503, 502, 504):
|
||||
if exc.code in {429, 503, 502, 504}:
|
||||
time.sleep(RETRY_DELAY * attempt)
|
||||
else:
|
||||
error_exit(last_error)
|
||||
@@ -459,8 +459,8 @@ def parse_overpass_elements(elements, ref_lat=None, ref_lon=None):
|
||||
"maps_url": f"https://www.google.com/maps/search/?api=1&query={el_lat},{el_lon}",
|
||||
"tags": {
|
||||
k: v for k, v in tags.items()
|
||||
if k not in ("name", "name:en",
|
||||
"addr:housenumber", "addr:street", "addr:city")
|
||||
if k not in {"name", "name:en",
|
||||
"addr:housenumber", "addr:street", "addr:city"}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ def check_requirements():
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
if not args or args[0] in ("-h", "--help"):
|
||||
if not args or args[0] in {"-h", "--help"}:
|
||||
print(__doc__)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ def show_metadata(path):
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
if not args or args[0] in ("-h", "--help"):
|
||||
if not args or args[0] in {"-h", "--help"}:
|
||||
print(__doc__)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ def search(query=None, author=None, category=None, ids=None, max_results=5, sort
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
if not args or args[0] in ("-h", "--help"):
|
||||
if not args or args[0] in {"-h", "--help"}:
|
||||
print(__doc__)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ def cmd_trades(limit: int = 10, market: str = None):
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
if not args or args[0] in ("-h", "--help", "help"):
|
||||
if not args or args[0] in {"-h", "--help", "help"}:
|
||||
print(__doc__)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user