Skip to content

Commit

Permalink
WIP part 3: Fix some mypy issues
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Lucarella <[email protected]>
  • Loading branch information
llucax committed Jan 4, 2024
1 parent 39dd0ec commit 1d66c40
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/frequenz/sdk/microgrid/_data_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(
"""
from ..actor import ChannelRegistry

self._resampler_config: ResamplerConfig = resampler_config
self._resampler_config: ResamplingActorConfig = resampler_config

self._channel_registry: ChannelRegistry = ChannelRegistry(
name="Data Pipeline Registry"
Expand Down
26 changes: 17 additions & 9 deletions src/frequenz/sdk/timeseries/_resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from collections.abc import AsyncIterator, Callable, Coroutine, Sequence
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from typing import Generic
from typing import Generic, cast

from frequenz.channels.util import Timer
from frequenz.channels.util._timer import _to_microseconds
Expand Down Expand Up @@ -73,7 +73,12 @@


ResamplingFunction = Callable[
[Sequence[Sample[SupportsFloatT]], "ResamplerConfig", "SourceProperties"], float
[
Sequence[Sample[SupportsFloatT]],
"ResamplerConfig[SupportsFloatT]",
"SourceProperties",
],
float,
]
"""Resampling function type.
Expand Down Expand Up @@ -505,13 +510,16 @@ async def resample(self, *, one_shot: bool = False) -> None:
)

self._window_end += self._config.resampling_period
exceptions = {
source: results[i]
for i, source in enumerate(self._resamplers)
# CancelledError inherits from BaseException, but we don't want
# to catch *all* BaseExceptions here.
if isinstance(results[i], (Exception, asyncio.CancelledError))
}
exceptions = cast(
dict[Source[SupportsFloatT], Exception | asyncio.CancelledError],
{
source: results[i]
for i, source in enumerate(self._resamplers)
# CancelledError inherits from BaseException, but we don't want
# to catch *all* BaseExceptions here.
if isinstance(results[i], (Exception, asyncio.CancelledError))
},
)
if exceptions:
raise ResamplingError(exceptions)
if one_shot:
Expand Down
2 changes: 1 addition & 1 deletion src/frequenz/sdk/timeseries/_voltage_streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async def _send_request(self) -> None:
msg = Sample3Phase(
phases[0].timestamp,
*map(
lambda p: Voltage.from_volts(p.value.base_value)
lambda p: Voltage.from_volts(float(p.value))
if p.value
else None,
phases,
Expand Down
16 changes: 8 additions & 8 deletions src/frequenz/sdk/timeseries/formula_engine/_formula_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@
"""The dictionary of operator precedence for the shunting yard algorithm."""

_CompositionType = Union[
"FormulaEngine",
"HigherOrderFormulaBuilder",
"FormulaEngine3Phase",
"HigherOrderFormulaBuilder3Phase",
"FormulaEngine", # type: ignore
"HigherOrderFormulaBuilder", # type: ignore
"FormulaEngine3Phase", # type: ignore
"HigherOrderFormulaBuilder3Phase", # type: ignore
]

_CompositionType1Phase = Union[
"FormulaEngine",
"HigherOrderFormulaBuilder",
"FormulaEngine", # type: ignore
"HigherOrderFormulaBuilder", # type: ignore
]

_CompositionType3Phase = Union[
"FormulaEngine3Phase",
"HigherOrderFormulaBuilder3Phase",
"FormulaEngine3Phase", # type: ignore
"HigherOrderFormulaBuilder3Phase", # type: ignore
]

# The `FormulaEngine*` and `HigherOrderFormulaBuilder*` classes are generic, but
Expand Down

0 comments on commit 1d66c40

Please sign in to comment.