Skip to content

Commit c9bd845

Browse files
committed
Fix typing of Self
The method always returned a `ComponentMetricFetcher` (or `LatestMetricsFetcher`), even for subclasses, which is not what `Self` is. To make sure that an instance of the subclass is returned we just use `cls` to call `__new__` instead of `ComponentMetricFetcher` (and fix the type hint for `LatestMetricsFetcher`). Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 3e51a6c commit c9bd845

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/frequenz/sdk/timeseries/battery_pool/_component_metric_fetcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def async_new(
5757
Returns:
5858
This class instance.
5959
"""
60-
self: ComponentMetricFetcher = ComponentMetricFetcher.__new__(cls)
60+
self: Self = cls.__new__(cls)
6161
self._component_id = component_id
6262
self._metrics = metrics
6363
return self
@@ -94,7 +94,7 @@ async def async_new(
9494
Returns:
9595
This class instance
9696
"""
97-
self: LatestMetricsFetcher[T] = await super().async_new(component_id, metrics)
97+
self: Self = await super().async_new(component_id, metrics)
9898

9999
for metric in metrics:
100100
# pylint: disable=protected-access

0 commit comments

Comments
 (0)