mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 05:55:16 +08:00
ci/typecheck: cast JSON parses; drop mypy-style type ignores
Narrow chat tool JSON with typing.cast; remove obsolete type: ignore comments that basedpyright does not treat as pyright suppresses.
This commit is contained in:
@@ -55,7 +55,7 @@ def pause_task_cancel_for_prompt() -> Generator[None]:
|
||||
yield
|
||||
finally:
|
||||
with contextlib.suppress(ValueError):
|
||||
_ = signal.signal(signal.SIGINT, previous) # type: ignore[arg-type]
|
||||
_ = signal.signal(signal.SIGINT, previous)
|
||||
reinstall = _reinstall_holder[0]
|
||||
if loop_handler_removed and reinstall is not None:
|
||||
with contextlib.suppress(RuntimeError, NotImplementedError, ValueError):
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import cast
|
||||
|
||||
from plyngent.agent import tool
|
||||
from plyngent.prompting import ChoiceOption, NonInteractiveError, choose_async
|
||||
@@ -20,12 +21,12 @@ def parse_options(raw: str) -> list[ChoiceOption]:
|
||||
msg = "options must be a JSON array"
|
||||
raise TypeError(msg)
|
||||
out: list[ChoiceOption] = []
|
||||
for item in data:
|
||||
if isinstance(item, str):
|
||||
out.append(ChoiceOption(label=item))
|
||||
for item_obj in cast("list[object]", data):
|
||||
if isinstance(item_obj, str):
|
||||
out.append(ChoiceOption(label=item_obj))
|
||||
continue
|
||||
if isinstance(item, dict):
|
||||
raw_map: dict[str, object] = {str(k): v for k, v in item.items()} # type: ignore[misc]
|
||||
if isinstance(item_obj, dict):
|
||||
raw_map = {str(key): value for key, value in cast("dict[object, object]", item_obj).items()}
|
||||
label_obj = raw_map.get("label")
|
||||
if not isinstance(label_obj, str) or not label_obj:
|
||||
msg = "each option object needs a non-empty string label"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import cast
|
||||
|
||||
from plyngent.agent import tool
|
||||
from plyngent.prompting import FormField, NonInteractiveError, form_async
|
||||
@@ -21,11 +22,11 @@ def parse_fields(raw: str) -> list[FormField]:
|
||||
msg = "fields must be a non-empty JSON array"
|
||||
raise ValueError(msg)
|
||||
out: list[FormField] = []
|
||||
for item in data:
|
||||
if not isinstance(item, dict):
|
||||
for item_obj in cast("list[object]", data):
|
||||
if not isinstance(item_obj, dict):
|
||||
msg = "each field must be a JSON object"
|
||||
raise TypeError(msg)
|
||||
raw_map: dict[str, object] = {str(k): v for k, v in item.items()} # type: ignore[misc]
|
||||
raw_map = {str(key): value for key, value in cast("dict[object, object]", item_obj).items()}
|
||||
name = raw_map.get("name")
|
||||
prompt = raw_map.get("prompt")
|
||||
if not isinstance(name, str) or not name:
|
||||
|
||||
Reference in New Issue
Block a user