From 6f2ffa8fed8f5b84074624013450d4cb61809612 Mon Sep 17 00:00:00 2001 From: James Hush Date: Mon, 19 Jan 2026 11:07:56 +0800 Subject: [PATCH] fix: add type annotations to event_handler decorator Add proper generic type annotations to the event_handler decorator so that static type checkers (pyright, mypy) understand the decorated function is returned and used, eliminating false reportUnusedFunction warnings. Changes: - Import TypeVar and Callable from typing - Define F TypeVar bound to Callable[..., Any] - Add Callable[[F], F] return type to event_handler method - Add F type annotations to inner decorator function --- src/pipecat/utils/base_object.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pipecat/utils/base_object.py b/src/pipecat/utils/base_object.py index f6e4c47de..e8c4b13ad 100644 --- a/src/pipecat/utils/base_object.py +++ b/src/pipecat/utils/base_object.py @@ -16,12 +16,15 @@ import inspect import traceback from abc import ABC from dataclasses import dataclass -from typing import Any, Dict, List, Optional +from typing import Any, Callable, Dict, List, Optional, Set, Tuple, TypeVar from loguru import logger from pipecat.utils.utils import obj_count, obj_id +# TypeVar for preserving function signatures in decorators +F = TypeVar("F", bound=Callable[..., Any]) + @dataclass class EventHandler: @@ -99,7 +102,7 @@ class BaseObject(ABC): logger.debug(f"{self}: waiting on event handlers to finish {list(event_names)}...") await asyncio.wait(tasks) - def event_handler(self, event_name: str): + def event_handler(self, event_name: str) -> Callable[[F], F]: """Decorator for registering event handlers. Args: @@ -109,7 +112,7 @@ class BaseObject(ABC): The decorator function that registers the handler. """ - def decorator(handler): + def decorator(handler: F) -> F: self.add_event_handler(event_name, handler) return handler