Modernize Python typing across the codebase
Automated via ruff UP006, UP007, UP035, UP045 rules (target: py311): - Replace `typing.List`, `Dict`, `Tuple`, `Set`, `FrozenSet`, `Type` with their built-in equivalents (`list`, `dict`, `tuple`, etc.) - Replace `typing.Optional[X]` with `X | None` - Replace `typing.Union[X, Y]` with `X | Y` - Move `Mapping`, `Sequence`, `Callable`, `Awaitable`, `MutableMapping`, `MutableSequence`, `Iterator`, `AsyncIterator`, `AsyncGenerator` imports from `typing` to `collections.abc` - Remove now-unused `typing` imports - Add `from __future__ import annotations` to 5 files that use forward-reference strings in `X | "Y"` annotations
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
import asyncio
|
||||
import unittest
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
|
||||
from pipecat.frames.frames import (
|
||||
DataFrame,
|
||||
@@ -35,7 +34,7 @@ class BroadcastTestFrame(DataFrame):
|
||||
|
||||
text: str = ""
|
||||
value: int = 0
|
||||
items: List[str] = field(default_factory=list)
|
||||
items: list[str] = field(default_factory=list)
|
||||
|
||||
|
||||
class TestFrameProcessor(unittest.IsolatedAsyncioTestCase):
|
||||
@@ -191,8 +190,8 @@ class TestFrameProcessor(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
async def test_broadcast_frame(self):
|
||||
"""Test that broadcast_frame creates two separate frames with fresh IDs."""
|
||||
downstream_frames: List[Frame] = []
|
||||
upstream_frames: List[Frame] = []
|
||||
downstream_frames: list[Frame] = []
|
||||
upstream_frames: list[Frame] = []
|
||||
|
||||
class BroadcastTestProcessor(FrameProcessor):
|
||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
||||
@@ -205,7 +204,7 @@ class TestFrameProcessor(unittest.IsolatedAsyncioTestCase):
|
||||
await self.push_frame(frame, direction)
|
||||
|
||||
class CaptureProcessor(FrameProcessor):
|
||||
def __init__(self, capture_list: List[Frame], direction: FrameDirection):
|
||||
def __init__(self, capture_list: list[Frame], direction: FrameDirection):
|
||||
super().__init__()
|
||||
self._capture_list = capture_list
|
||||
self._capture_direction = direction
|
||||
@@ -256,9 +255,9 @@ class TestFrameProcessor(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
async def test_broadcast_frame_instance(self):
|
||||
"""Test that broadcast_frame_instance shallow-copies all fields except id and name."""
|
||||
downstream_frames: List[Frame] = []
|
||||
upstream_frames: List[Frame] = []
|
||||
original_frame: List[Frame] = []
|
||||
downstream_frames: list[Frame] = []
|
||||
upstream_frames: list[Frame] = []
|
||||
original_frame: list[Frame] = []
|
||||
|
||||
class BroadcastInstanceTestProcessor(FrameProcessor):
|
||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
||||
@@ -273,7 +272,7 @@ class TestFrameProcessor(unittest.IsolatedAsyncioTestCase):
|
||||
await self.push_frame(frame, direction)
|
||||
|
||||
class CaptureProcessor(FrameProcessor):
|
||||
def __init__(self, capture_list: List[Frame], direction: FrameDirection):
|
||||
def __init__(self, capture_list: list[Frame], direction: FrameDirection):
|
||||
super().__init__()
|
||||
self._capture_list = capture_list
|
||||
self._capture_direction = direction
|
||||
@@ -346,7 +345,7 @@ class TestFrameProcessor(unittest.IsolatedAsyncioTestCase):
|
||||
This test simulates issue #3524 where an InterruptionFrame during slow
|
||||
processing would cause terminal frames to be lost, freezing the pipeline.
|
||||
"""
|
||||
received_frames: List[Frame] = []
|
||||
received_frames: list[Frame] = []
|
||||
|
||||
class DelayAndInterruptProcessor(FrameProcessor):
|
||||
"""This processor delays processing and then generates an interruption.
|
||||
@@ -398,7 +397,7 @@ class TestFrameProcessor(unittest.IsolatedAsyncioTestCase):
|
||||
Similar to test_terminal_frames_survive_interruption but specifically
|
||||
for StopFrame.
|
||||
"""
|
||||
received_frames: List[Frame] = []
|
||||
received_frames: list[Frame] = []
|
||||
|
||||
class DelayAndInterruptProcessor(FrameProcessor):
|
||||
"""This processor delays processing and then generates an interruption."""
|
||||
|
||||
Reference in New Issue
Block a user