fix: resolve mypy redundant-cast errors while keeping pyright happy

Use cast(list[Any], x) with type: ignore[redundant-cast] comments to
satisfy both mypy (which considers casting Any redundant) and pyright
strict mode (which needs explicit casts to narrow Unknown types).

Also fix evaluator decorator check_name type annotation to be
explicitly str, resolving mypy str|Any|None mismatch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
alliscode
2026-03-20 15:25:07 -07:00
Unverified
parent 45527eed29
commit b0a15914bf
2 changed files with 6 additions and 6 deletions
@@ -313,7 +313,7 @@ def _extract_per_evaluator(run: Any) -> dict[str, dict[str, int]]:
if per_testing_criteria is None:
return per_eval
try:
items = cast(list[Any], per_testing_criteria) if isinstance(per_testing_criteria, list) else []
items = cast(list[Any], per_testing_criteria) if isinstance(per_testing_criteria, list) else [] # type: ignore[redundant-cast]
for item in items:
name: str = str(getattr(item, "name", None) or getattr(item, "testing_criteria", "unknown"))
counts = _extract_result_counts(item)
@@ -759,7 +759,7 @@ def _extract_agent_eval_data(
agent_exec_response: AgentExecutorResponse | None = None
if isinstance(completion_data, list):
for cdata_item in cast(list[Any], completion_data):
for cdata_item in cast(list[Any], completion_data): # type: ignore[redundant-cast]
if isinstance(cdata_item, AgentExecutorResponse):
agent_exec_response = cdata_item
break
@@ -807,7 +807,7 @@ def _extract_overall_query(workflow_result: WorkflowRunResult) -> str | None:
if isinstance(data, str):
return data
if isinstance(data, list) and data:
items_list = cast(list[Any], data)
items_list = cast(list[Any], data) # type: ignore[redundant-cast]
first = items_list[0]
if isinstance(first, Message):
msgs: list[Message] = [m for m in items_list if isinstance(m, Message)]
@@ -1209,7 +1209,7 @@ def evaluator(
"""
def _wrap(func: Callable[..., Any]) -> EvalCheck:
check_name = name or getattr(func, "__name__", "evaluator")
check_name: str = name or getattr(func, "__name__", None) or "evaluator"
async def _check(item: EvalItem) -> CheckResult:
kwargs = _resolve_function_args(func, item)
@@ -1218,7 +1218,7 @@ def evaluator(
result = await result
return _coerce_result(result, check_name)
_check.__name__ = check_name # type: ignore[attr-defined]
_check.__name__ = check_name # type: ignore[attr-defined,assignment]
_check.__doc__ = func.__doc__
return _check
@@ -1769,7 +1769,7 @@ def _build_overall_item(
final_output: Any = outputs[-1]
overall_response: AgentResponse[None]
if isinstance(final_output, list) and final_output and isinstance(final_output[0], Message):
msgs: list[Message] = [m for m in cast(list[Any], final_output) if isinstance(m, Message)]
msgs: list[Message] = [m for m in cast(list[Any], final_output) if isinstance(m, Message)] # type: ignore[redundant-cast]
response_text = " ".join(str(m.text) for m in msgs if m.role == "assistant")
overall_response = AgentResponse(messages=[Message("assistant", [response_text])])
elif isinstance(final_output, AgentResponse):