|
6 | 6 | import contextlib |
7 | 7 | from collections.abc import AsyncGenerator, Callable |
8 | 8 | from functools import wraps |
9 | | -from typing import Any, Final, ParamSpec |
10 | | - |
11 | | -from music_assistant_models.streamdetails import AudioFormat |
| 9 | +from typing import TYPE_CHECKING, Any, Final, ParamSpec, cast |
12 | 10 |
|
13 | 11 | from music_assistant.helpers.util import close_async_generator |
14 | 12 |
|
| 13 | +if TYPE_CHECKING: |
| 14 | + from music_assistant_models.media_items.audio_format import AudioFormat |
| 15 | + |
15 | 16 | # Type variables for the buffered decorator |
16 | 17 | _P = ParamSpec("_P") |
17 | 18 |
|
|
23 | 24 | _ACTIVE_PRODUCER_TASKS: set[asyncio.Task[Any]] = set() |
24 | 25 |
|
25 | 26 |
|
26 | | -async def buffered_audio( |
| 27 | +async def buffered_audio( # noqa: PLR0915 |
27 | 28 | generator: AsyncGenerator[bytes, None], |
28 | 29 | pcm_format: AudioFormat, |
29 | 30 | buffer_size: int = DEFAULT_BUFFER_SIZE, |
@@ -82,7 +83,7 @@ async def producer() -> None: |
82 | 83 | await condition.wait() |
83 | 84 |
|
84 | 85 | if cancelled: |
85 | | - break |
| 86 | + break # type: ignore[unreachable] |
86 | 87 |
|
87 | 88 | # Append to shared buffer |
88 | 89 | data_buffer.extend(chunk) |
@@ -200,7 +201,7 @@ def decorator( |
200 | 201 | @wraps(func) |
201 | 202 | async def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> AsyncGenerator[bytes, None]: |
202 | 203 | # Extract pcm_format from function arguments |
203 | | - pcm_format = kwargs.get(pcm_format_arg) |
| 204 | + pcm_format = cast("AudioFormat | None", kwargs.get(pcm_format_arg)) |
204 | 205 | if pcm_format is None: |
205 | 206 | msg = f"Audio buffer decorator requires '{pcm_format_arg}' argument" |
206 | 207 | raise ValueError(msg) |
|
0 commit comments