Widen ToolsSchema.standard_tools to Sequence for covariance

`ToolsSchema.__init__` declared `standard_tools: list[FunctionSchema |
DirectFunction]`. Callers (`BaseLLMAdapter`, `MCPService`) pass in
`list[FunctionSchema]`, which is not assignable to the union list
because `list` is invariant in its element type.

Widen the parameter to `Sequence[...]` (covariant) so `list[X]` and
`list[X | Y]` both fit. A narrower `list[FunctionSchema]` is still
accepted, and nothing in this class mutates the argument — the
constructor immediately copies it via `_map_standard_tools`.

Also correct the `custom_tools` property return type to include
`None`, matching the stored `_custom_tools` field.

This single edit clears the pyright errors for three ignore-list
entries: `tools_schema.py`, `base_llm_adapter.py`, and `mcp_service.py`.
This commit is contained in:
Mark Backman
2026-04-22 11:54:20 -04:00
parent b64ed3f9e2
commit 0c3c5e5c7d
2 changed files with 3 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ This module provides schemas for managing both standardized function tools
and custom adapter-specific tools in the Pipecat framework.
"""
from collections.abc import Sequence
from enum import Enum
from typing import Any
@@ -39,7 +40,7 @@ class ToolsSchema:
def __init__(
self,
standard_tools: list[FunctionSchema | DirectFunction],
standard_tools: Sequence[FunctionSchema | DirectFunction],
custom_tools: dict[AdapterType, list[dict[str, Any]]] | None = None,
) -> None:
"""Initialize the tools schema.
@@ -75,7 +76,7 @@ class ToolsSchema:
return self._standard_tools
@property
def custom_tools(self) -> dict[AdapterType, list[dict[str, Any]]]:
def custom_tools(self) -> dict[AdapterType, list[dict[str, Any]]] | None:
"""Get the custom tools dictionary.
Returns: