Fix type errors in utils and add to pyright checked set

This commit is contained in:
Mark Backman
2026-04-21 16:47:12 -04:00
parent c244a950eb
commit 21f5cfe21a
7 changed files with 23 additions and 15 deletions

View File

@@ -13,7 +13,8 @@
"src/pipecat/runner", "src/pipecat/runner",
"src/pipecat/tests", "src/pipecat/tests",
"src/pipecat/transcriptions", "src/pipecat/transcriptions",
"src/pipecat/turns" "src/pipecat/turns",
"src/pipecat/utils"
], ],
"exclude": ["**/*_pb2.py", "**/__pycache__"], "exclude": ["**/*_pb2.py", "**/__pycache__"],
"ignore": [ "ignore": [
@@ -23,7 +24,6 @@
"src/pipecat/serializers", "src/pipecat/serializers",
"src/pipecat/services", "src/pipecat/services",
"src/pipecat/transports", "src/pipecat/transports",
"src/pipecat/utils",
"tests" "tests"
], ],
"reportMissingImports": false "reportMissingImports": false

View File

@@ -20,7 +20,11 @@ if TYPE_CHECKING:
from loguru import logger from loguru import logger
from pipecat.processors.aggregators.llm_context import LLMContext, LLMSpecificMessage from pipecat.processors.aggregators.llm_context import (
LLMContext,
LLMContextMessage,
LLMSpecificMessage,
)
# Fallback timeout (seconds) used when summarization_timeout is None. # Fallback timeout (seconds) used when summarization_timeout is None.
DEFAULT_SUMMARIZATION_TIMEOUT = 120.0 DEFAULT_SUMMARIZATION_TIMEOUT = 120.0
@@ -269,7 +273,7 @@ class LLMMessagesToSummarize:
last_summarized_index: Index of the last message being summarized last_summarized_index: Index of the last message being summarized
""" """
messages: list[dict] messages: list[LLMContextMessage]
last_summarized_index: int last_summarized_index: int
@@ -415,7 +419,7 @@ class LLMContextSummarizationUtil:
@staticmethod @staticmethod
def _get_earliest_function_call_not_resolved_in_range( def _get_earliest_function_call_not_resolved_in_range(
messages: list[dict], start_idx: int, summary_end: int messages: list[LLMContextMessage], start_idx: int, summary_end: int
) -> int: ) -> int:
"""Find the earliest message index with incomplete function calls. """Find the earliest message index with incomplete function calls.
@@ -470,9 +474,10 @@ class LLMContextSummarizationUtil:
if role == "tool": if role == "tool":
tool_call_id = msg.get("tool_call_id") tool_call_id = msg.get("tool_call_id")
if tool_call_id and tool_call_id in pending_tool_calls: if tool_call_id and tool_call_id in pending_tool_calls:
if not LLMContextSummarizationUtil._is_tool_message_pending( content = msg.get("content", "")
msg.get("content", "") if not isinstance(content, str):
): content = ""
if not LLMContextSummarizationUtil._is_tool_message_pending(content):
pending_tool_calls.pop(tool_call_id) pending_tool_calls.pop(tool_call_id)
# Check for async tool completion — a developer message with # Check for async tool completion — a developer message with
@@ -480,7 +485,10 @@ class LLMContextSummarizationUtil:
# async result has arrived and the call is now resolved. # async result has arrived and the call is now resolved.
if role == "developer": if role == "developer":
try: try:
parsed = json.loads(msg.get("content", "")) content = msg.get("content", "")
if not isinstance(content, str):
continue
parsed = json.loads(content)
if ( if (
isinstance(parsed, dict) isinstance(parsed, dict)
and parsed.get("type") == "async_tool" and parsed.get("type") == "async_tool"

View File

@@ -58,7 +58,7 @@ class FrameQueue(asyncio.Queue):
Returns: Returns:
True if at least one enqueued frame is an instance of ``frame_type``. True if at least one enqueued frame is an instance of ``frame_type``.
""" """
for item in self._queue: for item in self._queue: # pyright: ignore[reportAttributeAccessIssue]
if isinstance(self._frame_getter(item), frame_type): if isinstance(self._frame_getter(item), frame_type):
return True return True
return False return False

View File

@@ -234,7 +234,7 @@ class TextPartForConcatenation:
includes_inter_part_spaces: bool includes_inter_part_spaces: bool
def __str__(self): def __str__(self):
return f"{self.name}(text: [{self.text}], includes_inter_part_spaces: {self.includes_inter_part_spaces})" return f"{type(self).__name__}(text: [{self.text}], includes_inter_part_spaces: {self.includes_inter_part_spaces})"
def concatenate_aggregated_text(text_parts: list[TextPartForConcatenation]) -> str: def concatenate_aggregated_text(text_parts: list[TextPartForConcatenation]) -> str:

View File

@@ -125,7 +125,7 @@ class BaseTextAggregator(ABC):
""" """
pass pass
# Make this a generator to satisfy type checker # Make this a generator to satisfy type checker
yield # pragma: no cover yield # pyright: ignore[reportReturnType] # pragma: no cover
@abstractmethod @abstractmethod
async def flush(self) -> Aggregation | None: async def flush(self) -> Aggregation | None:

View File

@@ -273,7 +273,7 @@ class PatternPairAggregator(SimpleTextAggregator):
# Which is why we base the return on the first found. # Which is why we base the return on the first found.
if start_count > end_count: if start_count > end_count:
start_index = text.find(start) start_index = text.find(start)
return [start_index, pattern_info] return (start_index, pattern_info)
return None return None

View File

@@ -440,7 +440,7 @@ def add_openai_realtime_span_attributes(
if isinstance(tool, dict) and "name" in tool: if isinstance(tool, dict) and "name" in tool:
tool_names.append(tool["name"]) tool_names.append(tool["name"])
elif hasattr(tool, "name"): elif hasattr(tool, "name"):
tool_names.append(tool.name) tool_names.append(getattr(tool, "name"))
elif isinstance(tool, dict) and "function" in tool and "name" in tool["function"]: elif isinstance(tool, dict) and "function" in tool and "name" in tool["function"]:
tool_names.append(tool["function"]["name"]) tool_names.append(tool["function"]["name"])
@@ -455,7 +455,7 @@ def add_openai_realtime_span_attributes(
if function_calls: if function_calls:
call = function_calls[0] call = function_calls[0]
if hasattr(call, "name"): if hasattr(call, "name"):
span.set_attribute("function_calls.first_name", call.name) span.set_attribute("function_calls.first_name", getattr(call, "name"))
elif isinstance(call, dict) and "name" in call: elif isinstance(call, dict) and "name" in call:
span.set_attribute("function_calls.first_name", call["name"]) span.set_attribute("function_calls.first_name", call["name"])