From 7cc7968abb86bb4fb50bf3e25c02fdd58397c8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 12 May 2026 12:15:04 -0700 Subject: [PATCH] Fix pyright errors in service_decorators.py --- .../utils/tracing/service_decorators.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/pipecat/utils/tracing/service_decorators.py b/src/pipecat/utils/tracing/service_decorators.py index 8117e06fd..c7e7583d0 100644 --- a/src/pipecat/utils/tracing/service_decorators.py +++ b/src/pipecat/utils/tracing/service_decorators.py @@ -360,7 +360,7 @@ def traced_tts(func: Callable | None = None, *, name: str | None = None) -> Call await original_setup(self, setup) install_audio_context_patches(self) - patched_setup.__tts_tracing_setup_wrapped__ = True + setattr(patched_setup, "__tts_tracing_setup_wrapped__", True) owner.setup = patched_setup def attach_run_tts_attributes(service, text, args, kwargs): @@ -418,7 +418,11 @@ def traced_tts(func: Callable | None = None, *, name: str | None = None) -> Call return _TracedTTSDescriptor() if func is not None: - return decorator(func) + # ``decorator(func)`` returns a descriptor placeholder that + # Python replaces with the real wrapped function once + # ``__set_name__`` runs at class definition time. Pyright sees + # only the descriptor instance, hence the ignore. + return decorator(func) # type: ignore[return-value] return decorator @@ -493,10 +497,12 @@ def traced_stt(func: Callable | None = None, *, name: str | None = None) -> Call """Open the STT span, anchored at ``segment_start_time`` if set.""" parent = _get_turn_context(service) or _get_parent_service_context(service) tracer = trace.get_tracer("pipecat") - kwargs = {"context": parent} - if state["segment_start_time"] is not None: - kwargs["start_time"] = int(state["segment_start_time"] * 1e9) - span = tracer.start_span("stt", **kwargs) + start_time_ns = ( + int(state["segment_start_time"] * 1e9) + if state["segment_start_time"] is not None + else None + ) + span = tracer.start_span("stt", context=parent, start_time=start_time_ns) try: settings = getattr(service, "_settings", None) add_stt_span_attributes( @@ -637,7 +643,7 @@ def traced_stt(func: Callable | None = None, *, name: str | None = None) -> Call except Exception as e: logging.warning(f"Error in STT post-push tracing: {e}") - patched_push_frame.__stt_tracing_push_frame_wrapped__ = True + setattr(patched_push_frame, "__stt_tracing_push_frame_wrapped__", True) owner.push_frame = patched_push_frame def patch_stop_ttfb_metrics(owner): @@ -681,7 +687,7 @@ def traced_stt(func: Callable | None = None, *, name: str | None = None) -> Call except Exception as e: logging.warning(f"Error in STT stop_ttfb_metrics tracing: {e}") - patched_stop.__stt_tracing_stop_ttfb_wrapped__ = True + setattr(patched_stop, "__stt_tracing_stop_ttfb_wrapped__", True) owner.stop_ttfb_metrics = patched_stop class _TracedSTTDescriptor: @@ -704,7 +710,11 @@ def traced_stt(func: Callable | None = None, *, name: str | None = None) -> Call return _TracedSTTDescriptor() if func is not None: - return decorator(func) + # ``decorator(func)`` returns a descriptor placeholder that + # Python replaces with the real wrapped function once + # ``__set_name__`` runs at class definition time. Pyright sees + # only the descriptor instance, hence the ignore. + return decorator(func) # type: ignore[return-value] return decorator