5252DEFAULT_DISPATCH_PORT = 50051
5353
5454
55- class Client (BaseApiClient ):
55+ class Client (BaseApiClient [ dispatch_pb2_grpc . MicrogridDispatchServiceStub ] ):
5656 """Dispatch API client."""
5757
5858 streams : dict [
@@ -76,6 +76,7 @@ def __init__(
7676 """
7777 super ().__init__ (
7878 server_url ,
79+ dispatch_pb2_grpc .MicrogridDispatchServiceStub ,
7980 connect = connect ,
8081 channel_defaults = ChannelOptions (
8182 port = DEFAULT_DISPATCH_PORT ,
@@ -90,21 +91,17 @@ def __init__(
9091 ),
9192 )
9293 self ._metadata = (("key" , key ),)
93- self ._setup_stub ()
94-
95- def _setup_stub (self ) -> None :
96- stub = dispatch_pb2_grpc .MicrogridDispatchServiceStub (self .channel )
97- # We need the type: ignore here because the generated async stub only lives in
98- # the .pyi file (the interpreter doesn't know anything about it) so we can't use
99- # a proper `cast()`, we can only use the async stub as a type hint.
100- self ._stub : dispatch_pb2_grpc .MicrogridDispatchServiceAsyncStub = stub # type: ignore
10194
10295 @property
10396 def stub (self ) -> dispatch_pb2_grpc .MicrogridDispatchServiceAsyncStub :
10497 """The stub for the service."""
105- if self ._channel is None :
98+ if self ._channel is None or self . _stub is None :
10699 raise ClientNotConnected (server_url = self .server_url , operation = "stub" )
107- return self ._stub
100+ # This type: ignore is needed because we need to cast the sync stub to
101+ # the async stub, but we can't use cast because the async stub doesn't
102+ # actually exists to the eyes of the interpreter, it only exists for the
103+ # type-checker, so it can only be used for type hints.
104+ return self ._stub # type: ignore
108105
109106 # pylint: disable=too-many-arguments, too-many-locals
110107 async def list (
0 commit comments