From 77d6c7b74d8189a8beb3dd8c7466bf7c0a3b906a Mon Sep 17 00:00:00 2001 From: Sir Qasim Date: Sat, 22 Mar 2025 08:27:09 +0500 Subject: [PATCH 1/2] Refactor: Add explicit TypeAlias for VoiceStreamEvent using modern Python typing |Update events.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR improves type hint clarity and consistency by defining `VoiceStreamEvent` as an explicit `TypeAlias` using Python 3.10+ syntax. ### 🔧 What was changed: ```python VoiceStreamEvent: TypeAlias = ( VoiceStreamEventAudio | VoiceStreamEventLifecycle | VoiceStreamEventError ) ``` ### 🧠 Why: - ✅ **Explicit Type Alias**: Clearly indicates that `VoiceStreamEvent` is a type alias, not a runtime variable (per [PEP 613](https://peps.python.org/pep-0613/)). - ✅ **Improved Readability**: Uses the modern `|` union syntax, which is more concise and readable than `Union[...]`. - ✅ **Better Tooling Support**: Helps static type checkers (like MyPy and Pyright) understand developer intent, improving accuracy and IDE support. ### 📌 Note: This change does not affect runtime behavior. It purely enhances type safety and code quality for developers and static analyzers. --- src/agents/voice/events.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/agents/voice/events.py b/src/agents/voice/events.py index bdcd08153..19c0b649f 100644 --- a/src/agents/voice/events.py +++ b/src/agents/voice/events.py @@ -41,7 +41,6 @@ class VoiceStreamEventError: """The type of event.""" -VoiceStreamEvent: TypeAlias = Union[ - VoiceStreamEventAudio, VoiceStreamEventLifecycle, VoiceStreamEventError -] +VoiceStreamEvent: TypeAlias = ( VoiceStreamEventAudio | VoiceStreamEventLifecycle | VoiceStreamEventError ) + """An event from the `VoicePipeline`, streamed via `StreamedAudioResult.stream()`.""" From f4e2cd4c0314f11411fe7ca666dce8e50eeb3020 Mon Sep 17 00:00:00 2001 From: Sir Qasim Date: Sat, 22 Mar 2025 09:11:23 +0500 Subject: [PATCH 2/2] replace UNION with "|" Update events.py --- src/agents/voice/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agents/voice/events.py b/src/agents/voice/events.py index 19c0b649f..62ce6978e 100644 --- a/src/agents/voice/events.py +++ b/src/agents/voice/events.py @@ -1,7 +1,7 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Literal, Union +from typing import Literal from typing_extensions import TypeAlias