Enforce strict Pyright gate
This commit is contained in:
parent
90898cfd63
commit
2841042b9c
16 changed files with 214 additions and 77 deletions
|
|
@ -18,6 +18,7 @@ from http import HTTPStatus
|
|||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from pathlib import Path
|
||||
from time import monotonic
|
||||
from typing import cast
|
||||
|
||||
from .errors import DocForgeError
|
||||
from .index import APPLICATION_ID, INDEX_SCHEMA_VERSION, ProjectIndex, re_tokenize
|
||||
|
|
@ -54,21 +55,35 @@ class VisualizationIndexSnapshot:
|
|||
self.max_query_chars = index.project.descriptor.limits.max_query_chars
|
||||
self.max_results = index.project.descriptor.limits.max_results
|
||||
self.max_depth = index.project.descriptor.limits.max_traversal_depth
|
||||
self.identity = {key: checked[key] for key in self._IDENTITY_KEYS}
|
||||
self.identity: dict[str, object] = {key: checked[key] for key in self._IDENTITY_KEYS}
|
||||
self._stat = self._safe_stat()
|
||||
|
||||
@classmethod
|
||||
def from_spec(cls, spec: dict[str, object]) -> VisualizationIndexSnapshot:
|
||||
snapshot = cls.__new__(cls)
|
||||
snapshot.path = Path(str(spec["path"]))
|
||||
snapshot.title = str(spec["title"])
|
||||
snapshot.max_query_chars = int(spec["max_query_chars"])
|
||||
snapshot.max_results = int(spec["max_results"])
|
||||
snapshot.max_depth = int(spec["max_depth"])
|
||||
path = spec["path"]
|
||||
title = spec["title"]
|
||||
max_query_chars = spec["max_query_chars"]
|
||||
max_results = spec["max_results"]
|
||||
max_depth = spec["max_depth"]
|
||||
if (
|
||||
not isinstance(path, str)
|
||||
or not isinstance(title, str)
|
||||
or type(max_query_chars) is not int
|
||||
or type(max_results) is not int
|
||||
or type(max_depth) is not int
|
||||
):
|
||||
raise DocForgeError("invalid_index", "Visualization snapshot is invalid")
|
||||
snapshot.path = Path(path)
|
||||
snapshot.title = title
|
||||
snapshot.max_query_chars = max_query_chars
|
||||
snapshot.max_results = max_results
|
||||
snapshot.max_depth = max_depth
|
||||
identity = spec["identity"]
|
||||
if not isinstance(identity, dict):
|
||||
raise DocForgeError("invalid_index", "Visualization identity is invalid")
|
||||
snapshot.identity = {key: identity[key] for key in cls._IDENTITY_KEYS}
|
||||
typed_identity = cast(dict[str, object], identity)
|
||||
snapshot.identity = {key: typed_identity[key] for key in cls._IDENTITY_KEYS}
|
||||
snapshot._stat = snapshot._safe_stat()
|
||||
return snapshot
|
||||
|
||||
|
|
@ -131,7 +146,7 @@ class VisualizationIndexSnapshot:
|
|||
+ " ORDER BY rank, nodes.node_id LIMIT ?",
|
||||
values,
|
||||
).fetchall()
|
||||
results = []
|
||||
results: list[dict[str, object]] = []
|
||||
for row in rows:
|
||||
item = _node_dict(row, include_content=False)
|
||||
item.update({"rank": row["rank"], "snippet": row["snippet"]})
|
||||
|
|
@ -294,6 +309,9 @@ class VisualizationIndexSnapshot:
|
|||
**payload,
|
||||
}
|
||||
|
||||
def result(self, **payload: object) -> dict[str, object]:
|
||||
return self._result(**payload)
|
||||
|
||||
|
||||
class VisualizationRunner:
|
||||
"""Start one token-protected loopback reader for one immutable project binding."""
|
||||
|
|
@ -387,7 +405,8 @@ class VisualizationRunner:
|
|||
def do_DELETE(self) -> None: # noqa: N802
|
||||
self.do_POST()
|
||||
|
||||
def log_message(self, _format: str, *_args: object) -> None:
|
||||
def log_message(self, format: str, *args: object) -> None:
|
||||
del format, args
|
||||
return
|
||||
|
||||
self._server = _VisualizationHttpServer(("127.0.0.1", 0), Handler)
|
||||
|
|
@ -514,7 +533,7 @@ class VisualizationRunner:
|
|||
if parsed.path == f"{prefix}/api/overview":
|
||||
payload = reader.overview()
|
||||
elif parsed.path == f"{prefix}/api/heartbeat":
|
||||
payload = reader._result(
|
||||
payload = reader.result(
|
||||
viewer="alive",
|
||||
lease_seconds=self.lease_seconds,
|
||||
)
|
||||
|
|
@ -761,7 +780,7 @@ class DetachedVisualizationRunner:
|
|||
"visualization_unavailable",
|
||||
"The detached visualization worker rejected the snapshot",
|
||||
)
|
||||
return response["visualization"]
|
||||
return cast(dict[str, object], response["visualization"])
|
||||
|
||||
def stop(self) -> None:
|
||||
process = self._process
|
||||
|
|
@ -793,7 +812,7 @@ def _receive_worker_response(control: socket.socket) -> dict[str, object]:
|
|||
result = json.loads(payload)
|
||||
if not isinstance(result, dict):
|
||||
raise ValueError("Visualization worker returned an invalid response")
|
||||
return result
|
||||
return cast(dict[str, object], result)
|
||||
|
||||
|
||||
def _one(params: dict[str, list[str]], name: str) -> str:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue