Skip to content

Commit 54650fe

Browse files
committed
Use covariant generics in ReceiverFetcher and LatestValueCache
This is done to be consistent with the covariant types used by the channels package as of v1.0.0-rc1. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 880e1c5 commit 54650fe

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/frequenz/sdk/_internal/_channels.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
from frequenz.channels import Receiver
1111

12-
T = typing.TypeVar("T")
12+
T_co = typing.TypeVar("T_co", covariant=True)
1313

1414

15-
class ReceiverFetcher(typing.Generic[T], typing.Protocol):
15+
class ReceiverFetcher(typing.Generic[T_co], typing.Protocol):
1616
"""An interface that just exposes a `new_receiver` method."""
1717

1818
@abc.abstractmethod
19-
def new_receiver(self, *, maxsize: int = 50) -> Receiver[T]:
19+
def new_receiver(self, *, maxsize: int = 50) -> Receiver[T_co]:
2020
"""Get a receiver from the channel.
2121
2222
Args:
@@ -31,20 +31,20 @@ class _Sentinel:
3131
"""A sentinel to denote that no value has been received yet."""
3232

3333

34-
class LatestValueCache(typing.Generic[T]):
34+
class LatestValueCache(typing.Generic[T_co]):
3535
"""A cache that stores the latest value in a receiver."""
3636

37-
def __init__(self, receiver: Receiver[T]) -> None:
37+
def __init__(self, receiver: Receiver[T_co]) -> None:
3838
"""Create a new cache.
3939
4040
Args:
4141
receiver: The receiver to cache.
4242
"""
4343
self._receiver = receiver
44-
self._latest_value: T | _Sentinel = _Sentinel()
44+
self._latest_value: T_co | _Sentinel = _Sentinel()
4545
self._task = asyncio.create_task(self._run())
4646

47-
def get(self) -> T:
47+
def get(self) -> T_co:
4848
"""Return the latest value that has been received.
4949
5050
This raises a `ValueError` if no value has been received yet. Use `has_value` to

0 commit comments

Comments
 (0)