diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d095ff6f..0dad8f63 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,5 @@ # Frequenz Dispatch Client Library Release Notes -## Bug Fixes +## Summary -* The client was broken due to wrong usage of the new BaseClient API. +* The base client dependency was updated to v0.8.0. diff --git a/pyproject.toml b/pyproject.toml index 370e86da..a6cc48d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ requires-python = ">= 3.11, < 4" dependencies = [ "typing-extensions >= 4.6.1, < 5", "frequenz-api-dispatch == 1.0.0-rc1", - "frequenz-client-base >= 0.7.0, < 0.8.0", + "frequenz-client-base >= 0.8.0, < 0.9.0", "frequenz-client-common >= 0.1.0, < 0.3.0", "grpcio >= 1.66.1, < 2", ] diff --git a/src/frequenz/client/dispatch/_client.py b/src/frequenz/client/dispatch/_client.py index 36b2a416..1e64a028 100644 --- a/src/frequenz/client/dispatch/_client.py +++ b/src/frequenz/client/dispatch/_client.py @@ -52,7 +52,7 @@ DEFAULT_DISPATCH_PORT = 50051 -class Client(BaseApiClient): +class Client(BaseApiClient[dispatch_pb2_grpc.MicrogridDispatchServiceStub]): """Dispatch API client.""" streams: dict[ @@ -76,6 +76,7 @@ def __init__( """ super().__init__( server_url, + dispatch_pb2_grpc.MicrogridDispatchServiceStub, connect=connect, channel_defaults=ChannelOptions( port=DEFAULT_DISPATCH_PORT, @@ -90,21 +91,17 @@ def __init__( ), ) self._metadata = (("key", key),) - self._setup_stub() - - def _setup_stub(self) -> None: - stub = dispatch_pb2_grpc.MicrogridDispatchServiceStub(self.channel) - # We need the type: ignore here because the generated async stub only lives in - # the .pyi file (the interpreter doesn't know anything about it) so we can't use - # a proper `cast()`, we can only use the async stub as a type hint. - self._stub: dispatch_pb2_grpc.MicrogridDispatchServiceAsyncStub = stub # type: ignore @property def stub(self) -> dispatch_pb2_grpc.MicrogridDispatchServiceAsyncStub: """The stub for the service.""" - if self._channel is None: + if self._channel is None or self._stub is None: raise ClientNotConnected(server_url=self.server_url, operation="stub") - return self._stub + # This type: ignore is needed because we need to cast the sync stub to + # the async stub, but we can't use cast because the async stub doesn't + # actually exists to the eyes of the interpreter, it only exists for the + # type-checker, so it can only be used for type hints. + return self._stub # type: ignore # pylint: disable=too-many-arguments, too-many-locals async def list( diff --git a/src/frequenz/client/dispatch/test/client.py b/src/frequenz/client/dispatch/test/client.py index 629a43bf..66dd0d9c 100644 --- a/src/frequenz/client/dispatch/test/client.py +++ b/src/frequenz/client/dispatch/test/client.py @@ -34,9 +34,6 @@ def stub(self) -> FakeService: # type: ignore """ return self._stuba - def _setup_stub(self) -> None: - """Empty body because no setup needed.""" - def dispatches(self, microgrid_id: int) -> list[Dispatch]: """List of dispatches.