|
14 | 14 | from collections.abc import AsyncIterator, Callable, Coroutine, Sequence |
15 | 15 | from dataclasses import dataclass |
16 | 16 | from datetime import datetime, timedelta, timezone |
17 | | -from typing import Generic |
| 17 | +from typing import Generic, cast |
18 | 18 |
|
19 | 19 | from frequenz.channels.util import Timer |
20 | 20 | from frequenz.channels.util._timer import _to_microseconds |
|
73 | 73 |
|
74 | 74 |
|
75 | 75 | ResamplingFunction = Callable[ |
76 | | - [Sequence[Sample[SupportsFloatT]], "ResamplerConfig", "SourceProperties"], float |
| 76 | + [ |
| 77 | + Sequence[Sample[SupportsFloatT]], |
| 78 | + "ResamplerConfig[SupportsFloatT]", |
| 79 | + "SourceProperties", |
| 80 | + ], |
| 81 | + float, |
77 | 82 | ] |
78 | 83 | """Resampling function type. |
79 | 84 |
|
@@ -505,13 +510,16 @@ async def resample(self, *, one_shot: bool = False) -> None: |
505 | 510 | ) |
506 | 511 |
|
507 | 512 | self._window_end += self._config.resampling_period |
508 | | - exceptions = { |
509 | | - source: results[i] |
510 | | - for i, source in enumerate(self._resamplers) |
511 | | - # CancelledError inherits from BaseException, but we don't want |
512 | | - # to catch *all* BaseExceptions here. |
513 | | - if isinstance(results[i], (Exception, asyncio.CancelledError)) |
514 | | - } |
| 513 | + exceptions = cast( |
| 514 | + dict[Source[SupportsFloatT], Exception | asyncio.CancelledError], |
| 515 | + { |
| 516 | + source: results[i] |
| 517 | + for i, source in enumerate(self._resamplers) |
| 518 | + # CancelledError inherits from BaseException, but we don't want |
| 519 | + # to catch *all* BaseExceptions here. |
| 520 | + if isinstance(results[i], (Exception, asyncio.CancelledError)) |
| 521 | + }, |
| 522 | + ) |
515 | 523 | if exceptions: |
516 | 524 | raise ResamplingError(exceptions) |
517 | 525 | if one_shot: |
|
0 commit comments