Enforce strict Pyright gate
This commit is contained in:
parent
90898cfd63
commit
2841042b9c
16 changed files with 214 additions and 77 deletions
|
|
@ -8,7 +8,7 @@ import os
|
|||
import socket
|
||||
import time
|
||||
from contextlib import suppress
|
||||
from typing import Any
|
||||
from typing import cast
|
||||
|
||||
from .errors import DocForgeError
|
||||
from .visualization import VisualizationRunner
|
||||
|
|
@ -20,7 +20,7 @@ def _parser() -> argparse.ArgumentParser:
|
|||
return parser
|
||||
|
||||
|
||||
def _read_request(control: socket.socket) -> dict[str, Any]:
|
||||
def _read_request(control: socket.socket) -> dict[str, object]:
|
||||
chunks: list[bytes] = []
|
||||
size = 0
|
||||
while True:
|
||||
|
|
@ -37,7 +37,7 @@ def _read_request(control: socket.socket) -> dict[str, Any]:
|
|||
request = json.loads(payload)
|
||||
if not isinstance(request, dict):
|
||||
raise ValueError("Visualization launch request is invalid")
|
||||
return request
|
||||
return cast(dict[str, object], request)
|
||||
|
||||
|
||||
def _pid_exists(pid: int) -> bool:
|
||||
|
|
@ -59,21 +59,45 @@ def main(argv: list[str] | None = None) -> int:
|
|||
try:
|
||||
request = _read_request(control)
|
||||
target = request["target"]
|
||||
if not isinstance(target, dict):
|
||||
snapshot = request["snapshot"]
|
||||
token = request["token"]
|
||||
initial_grace = request["initial_grace_seconds"]
|
||||
lease = request["lease_seconds"]
|
||||
monitor_interval = request["monitor_interval_seconds"]
|
||||
owner = request["owner_pid"]
|
||||
if not isinstance(target, dict) or not isinstance(snapshot, dict):
|
||||
raise ValueError("Visualization target is invalid")
|
||||
target = cast(dict[str, object], target)
|
||||
node_id = target.get("node_id")
|
||||
query = target.get("query")
|
||||
depth = target.get("depth")
|
||||
if (
|
||||
(node_id is not None and not isinstance(node_id, str))
|
||||
or (query is not None and not isinstance(query, str))
|
||||
or type(depth) is not int
|
||||
or not isinstance(token, str)
|
||||
or not isinstance(initial_grace, int | float)
|
||||
or isinstance(initial_grace, bool)
|
||||
or not isinstance(lease, int | float)
|
||||
or isinstance(lease, bool)
|
||||
or not isinstance(monitor_interval, int | float)
|
||||
or isinstance(monitor_interval, bool)
|
||||
or type(owner) is not int
|
||||
):
|
||||
raise ValueError("Visualization launch request is invalid")
|
||||
runner = VisualizationRunner(
|
||||
None,
|
||||
snapshot_spec=request["snapshot"],
|
||||
token=str(request["token"]),
|
||||
snapshot_spec=cast(dict[str, object], snapshot),
|
||||
token=token,
|
||||
register_atexit=False,
|
||||
initial_grace_seconds=float(request["initial_grace_seconds"]),
|
||||
lease_seconds=float(request["lease_seconds"]),
|
||||
monitor_interval_seconds=float(request["monitor_interval_seconds"]),
|
||||
initial_grace_seconds=float(initial_grace),
|
||||
lease_seconds=float(lease),
|
||||
monitor_interval_seconds=float(monitor_interval),
|
||||
)
|
||||
visualization = runner.start(
|
||||
node_id=target.get("node_id"),
|
||||
query=target.get("query"),
|
||||
depth=int(target["depth"]),
|
||||
node_id=node_id,
|
||||
query=query,
|
||||
depth=depth,
|
||||
)
|
||||
control.sendall(
|
||||
json.dumps(
|
||||
|
|
@ -83,7 +107,7 @@ def main(argv: list[str] | None = None) -> int:
|
|||
).encode("utf-8")
|
||||
+ b"\n"
|
||||
)
|
||||
owner_pid = int(request["owner_pid"])
|
||||
owner_pid = owner
|
||||
except (DocForgeError, KeyError, OSError, TypeError, ValueError) as error:
|
||||
with suppress(OSError):
|
||||
control.sendall(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue