Skip to content

Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.

fix(types): resolve all 28 mypy errors on Windows (zero new type: ignore)

Ricardo Lauritod62356e81902
diff --git a/agent_reach/channels/bilibili.py b/agent_reach/channels/bilibili.py
index 82ac99a9..fa88ebba 100644
--- a/agent_reach/channels/bilibili.py
+++ b/agent_reach/channels/bilibili.py
@@ -50,7 +50,7 @@ def _bvid(target: str, timeout: float) -> str:
raise ReachError(BAD_INPUT, "target must be a BV id or a bilibili.com / b23.tv video link")
-def _bili_json(args: list, timeout: float) -> dict:
+def _bili_json(args: list, timeout: float): # returns dict or list depending on the subcommand
"""Run bili-cli with --json; map its error envelope to unified codes."""
try:
out = run_cmd(["bili", *args, "--json"], timeout=timeout, env=session_env("bili-cli"))
diff --git a/agent_reach/channels/linkedin.py b/agent_reach/channels/linkedin.py
index 4924013f..d0ad6b6f 100644
--- a/agent_reach/channels/linkedin.py
+++ b/agent_reach/channels/linkedin.py
@@ -2,6 +2,7 @@
"""LinkedIn — job search through mcp-server-linkedin via mcporter."""
import json
+from typing import Any, Dict
from agent_reach.backends.mcporter import configured_server_names
from agent_reach.runtime.result import NEED_SETUP, UPSTREAM_BROKEN, ReachError, make_item
@@ -98,12 +99,13 @@ class LinkedInChannel(Channel):
else:
out = run_cmd(["mcporter", "config", "list", "--json"], timeout=min(timeout, 20))
names = configured_server_names(out)
- server = next((n for n in ("linkedin", "mcp-server-linkedin", "linkedin-scraper", "linkedin-scraper-mcp") if n in names), None)
+ _server = next((n for n in ("linkedin", "mcp-server-linkedin", "linkedin-scraper", "linkedin-scraper-mcp") if n in names), None)
base = ["mcporter"]
- if server is None:
+ if _server is None:
raise ReachError(NEED_SETUP, "LinkedIn is not set up", hint="Run `agent-reach add linkedin`, then `agent-reach login linkedin`.")
+ server = _server
# The official server names the query `keywords`; the scraper variants use `query`.
- args = {"keywords": query} if server in ("linkedin", "mcp-server-linkedin") else {"query": query, "max_results": limit}
+ args: Dict[str, Any] = {"keywords": query} if server in ("linkedin", "mcp-server-linkedin") else {"query": query, "max_results": limit}
if location:
args["location"] = location
try:
diff --git a/agent_reach/channels/youtube.py b/agent_reach/channels/youtube.py
index 1c964e0e..a2cb9e24 100644
--- a/agent_reach/channels/youtube.py
+++ b/agent_reach/channels/youtube.py
@@ -72,7 +72,7 @@ def _iso_date(yyyymmdd) -> str:
def vtt_to_text(vtt: str) -> str:
"""Plain text from WebVTT: drop headers, timings, tags; collapse auto-caption repeats."""
- out = []
+ out: list[str] = []
for line in vtt.splitlines():
s = line.strip()
if (
diff --git a/agent_reach/runtime/browser.py b/agent_reach/runtime/browser.py
index df0215c8..b7c56fd1 100644
--- a/agent_reach/runtime/browser.py
+++ b/agent_reach/runtime/browser.py
@@ -165,7 +165,7 @@ def _open_lock(path: Path) -> int:
def try_lock(fd: int) -> bool:
"""Take an exclusive lock on `fd` without blocking."""
try:
- if os.name == "nt":
+ if sys.platform == "win32":
import msvcrt
msvcrt.locking(fd, msvcrt.LK_NBLCK, 1)
@@ -269,7 +269,7 @@ def _system_chrome() -> Optional[str]:
if base:
candidates.append(os.path.join(base, "Google", "Chrome", "Application", "chrome.exe"))
else:
- candidates = [shutil.which(n) for n in ("google-chrome", "google-chrome-stable", "chromium")]
+ candidates = [c for n in ("google-chrome", "google-chrome-stable", "chromium") if (c := shutil.which(n)) is not None]
return next((c for c in candidates if c and os.path.exists(c)), None)
@@ -636,7 +636,8 @@ def delete_profile() -> bool:
if not wait_for(lambda: not _profile_pids(), 5.0, interval=0.2):
for pid in _profile_pids():
with contextlib.suppress(OSError):
- os.kill(pid, signal.SIGKILL)
+ if sys.platform != "win32":
+ os.kill(pid, signal.SIGKILL)
wait_for(lambda: not watcher_running(), 20.0, interval=0.2)
shutil.rmtree(root, ignore_errors=True)
return not root.exists()
diff --git a/agent_reach/runtime/browser_watcher.py b/agent_reach/runtime/browser_watcher.py
index 9da126fe..41ef6c7a 100644
--- a/agent_reach/runtime/browser_watcher.py
+++ b/agent_reach/runtime/browser_watcher.py
@@ -27,6 +27,8 @@ from . import browser
def _launch_with_pipe(chrome: str, url: str):
"""Start Chrome with the CDP pipe on its fds 3 (commands in) and 4 (replies out)."""
+ if sys.platform == "win32": # pragma: no cover
+ raise NotImplementedError("pipe launch is not supported on Windows")
import fcntl
from .cdp import PipeConnection
@@ -90,6 +92,7 @@ def watch(idle: Optional[float] = None, poll: float = 15.0, *, launch: Optional[
def gone() -> bool:
if conn is not None:
+ assert proc is not None
return conn.closed.is_set() or proc.poll() is not None
return not browser.is_running()
diff --git a/agent_reach/runtime/cdp.py b/agent_reach/runtime/cdp.py
index 23cdcd07..3a4dd6fa 100644
--- a/agent_reach/runtime/cdp.py
+++ b/agent_reach/runtime/cdp.py
@@ -155,7 +155,8 @@ class PipeConnection:
except ValueError:
continue
with self._lock:
- slot = self._waiting.get(msg.get("id")) if isinstance(msg, dict) else None
+ msg_id = msg.get("id") if isinstance(msg, dict) else None
+ slot = self._waiting.get(msg_id) if isinstance(msg_id, int) else None
if slot is not None:
slot.append(msg)
slot[0].set()
diff --git a/agent_reach/runtime/cli.py b/agent_reach/runtime/cli.py
index 939b5005..91e9cb3f 100644
--- a/agent_reach/runtime/cli.py
+++ b/agent_reach/runtime/cli.py
@@ -20,7 +20,7 @@ import json
import os
import subprocess
import sys
-from typing import Dict, List, Optional, Sequence
+from typing import Dict, List, Optional, Sequence, cast
from agent_reach.channels import get_all_channels
from agent_reach.channels.base import Action, Channel
@@ -91,7 +91,7 @@ class _ArgError(Exception):
class _Parser(argparse.ArgumentParser):
"""argparse that raises instead of printing usage and exiting."""
- def error(self, message: str): # type: ignore[override]
+ def error(self, message: str):
raise _ArgError(message)
@@ -151,7 +151,7 @@ def _cmd_action(channel: Channel, args: Sequence[str]) -> int:
ns = _parse_action_args(action, args[1:])
except _ArgError as exc:
return _bad_input(channel.name, action.name, f"{exc}; usage: {_usage(channel, action)}")
- timeout = ns.pop("timeout")
+ timeout = cast(float, ns.pop("timeout"))
return _emit(run_action(channel, action.name, ns, timeout=timeout))
diff --git a/agent_reach/runtime/dispatch.py b/agent_reach/runtime/dispatch.py
index edc37a6b..40084b55 100644
--- a/agent_reach/runtime/dispatch.py
+++ b/agent_reach/runtime/dispatch.py
@@ -123,10 +123,10 @@ def run_action(
try:
items = _call_with_deadline(getattr(channel, method_name), clean, clock)
except BaseException as exc: # noqa: BLE001
- err = classify(exc)
- attempts.append({"backend": label, "result": err.code, "message": err.message})
- errors.append(err)
- if err.code in FINAL_CODES:
+ exc_err = classify(exc)
+ attempts.append({"backend": label, "result": exc_err.code, "message": exc_err.message})
+ errors.append(exc_err)
+ if exc_err.code in FINAL_CODES:
break
continue
attempts.append({"backend": label, "result": "ok"})
@@ -139,12 +139,12 @@ def run_action(
attempts=attempts,
)
- final = errors and next((e for e in errors if e.code in FINAL_CODES), None)
- err = final or (_pick_error(errors) if errors else ReachError(BAD_INPUT, f"no backend named '{only_backend}'"))
+ final: Optional[ReachError] = next((e for e in errors if e.code in FINAL_CODES), None) if errors else None
+ final_err = final or (_pick_error(errors) if errors else ReachError(BAD_INPUT, f"no backend named '{only_backend}'"))
return envelope(
channel=channel.name,
action=action_name,
elapsed_ms=elapsed(),
attempts=attempts,
- error=err,
+ error=final_err,
)
diff --git a/agent_reach/runtime/manage.py b/agent_reach/runtime/manage.py
index aa4a3d2d..b116b70e 100644
--- a/agent_reach/runtime/manage.py
+++ b/agent_reach/runtime/manage.py
@@ -321,7 +321,7 @@ def render_skill(lang: Optional[str] = None) -> str:
from importlib.resources import files
lang = lang or _skill_lang()
- template = files("agent_reach").joinpath("skill", "SKILL_en.md" if lang == "en" else "SKILL.md").read_text("utf-8")
+ template = files("agent_reach").joinpath("skill").joinpath("SKILL_en.md" if lang == "en" else "SKILL.md").read_text("utf-8")
labels = {"default": "default", "optional": "optional", "experimental": "experimental"}
rows = ["| channel | level | actions | login |", "|---|---|---|---|"]
for ch in _channels():
diff --git a/agent_reach/runtime/run.py b/agent_reach/runtime/run.py
index 9a9b7a49..b39f6754 100644
--- a/agent_reach/runtime/run.py
+++ b/agent_reach/runtime/run.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import os
import signal
import subprocess
+import sys
import urllib.request
from pathlib import Path
from typing import Mapping, Optional, Sequence
@@ -60,7 +61,7 @@ def run_cmd(
try:
out, err = proc.communicate(timeout=max(timeout, 0.1))
except subprocess.TimeoutExpired:
- if os.name != "nt":
+ if sys.platform != "win32":
try:
os.killpg(proc.pid, signal.SIGKILL)
except ProcessLookupError: