@@ -45,8 +45,6 @@ class AioRpcError(RpcError):
4545
4646# Create Client:
4747
48- class ClientInterceptor (metaclass = abc .ABCMeta ): ...
49-
5048def insecure_channel (
5149 target : str ,
5250 options : _Options | None = None ,
@@ -288,7 +286,7 @@ class InterceptedUnaryUnaryCall(_InterceptedCall[_TRequest, _TResponse], metacla
288286 def __await__ (self ) -> Generator [Incomplete , None , _TResponse ]: ...
289287 def __init__ (
290288 self ,
291- interceptors : Sequence [UnaryUnaryClientInterceptor [ _TRequest , _TResponse ] ],
289+ interceptors : Sequence [UnaryUnaryClientInterceptor ],
292290 request : _TRequest ,
293291 timeout : float | None ,
294292 metadata : Metadata ,
@@ -304,7 +302,7 @@ class InterceptedUnaryUnaryCall(_InterceptedCall[_TRequest, _TResponse], metacla
304302 # pylint: disable=too-many-arguments
305303 async def _invoke (
306304 self ,
307- interceptors : Sequence [UnaryUnaryClientInterceptor [ _TRequest , _TResponse ] ],
305+ interceptors : Sequence [UnaryUnaryClientInterceptor ],
308306 method : bytes ,
309307 timeout : float | None ,
310308 metadata : Metadata | None ,
@@ -316,47 +314,67 @@ class InterceptedUnaryUnaryCall(_InterceptedCall[_TRequest, _TResponse], metacla
316314 ) -> UnaryUnaryCall [_TRequest , _TResponse ]: ...
317315 def time_remaining (self ) -> float | None : ...
318316
319- class UnaryUnaryClientInterceptor (Generic [_TRequest , _TResponse ], metaclass = abc .ABCMeta ):
317+ class ClientInterceptor (metaclass = abc .ABCMeta ): ...
318+
319+ class UnaryUnaryClientInterceptor (ClientInterceptor , metaclass = abc .ABCMeta ):
320+ # This method (not the class) is generic over _TRequest and _TResponse
321+ # and the types must satisfy the no-op implementation of
322+ # `return await continuation(client_call_details, request)`.
320323 @abc .abstractmethod
321324 async def intercept_unary_unary (
322325 self ,
323- # XXX: See equivalent function in grpc types for notes about continuation:
324- continuation : Callable [[ClientCallDetails , _TRequest ], UnaryUnaryCall [_TRequest , _TResponse ]],
326+ continuation : Callable [[ClientCallDetails , _TRequest ], Awaitable [UnaryUnaryCall [_TRequest , _TResponse ]]],
325327 client_call_details : ClientCallDetails ,
326328 request : _TRequest ,
327- ) -> _TResponse : ...
329+ ) -> _TResponse | UnaryUnaryCall [ _TRequest , _TResponse ] : ...
328330
329- class UnaryStreamClientInterceptor (Generic [_TRequest , _TResponse ], metaclass = abc .ABCMeta ):
331+ class UnaryStreamClientInterceptor (ClientInterceptor , metaclass = abc .ABCMeta ):
332+ # This method (not the class) is generic over _TRequest and _TResponse
333+ # and the types must satisfy the no-op implementation of
334+ # `return await continuation(client_call_details, request)`.
330335 @abc .abstractmethod
331336 async def intercept_unary_stream (
332337 self ,
333- continuation : Callable [[ClientCallDetails , _TRequest ], UnaryStreamCall [_TRequest , _TResponse ]],
338+ continuation : Callable [[ClientCallDetails , _TRequest ], Awaitable [ UnaryStreamCall [_TRequest , _TResponse ] ]],
334339 client_call_details : ClientCallDetails ,
335340 request : _TRequest ,
336- ) -> AsyncIterable [_TResponse ] | UnaryStreamCall [_TRequest , _TResponse ]: ...
341+ ) -> AsyncIterator [_TResponse ] | UnaryStreamCall [_TRequest , _TResponse ]: ...
337342
338- class StreamUnaryClientInterceptor (Generic [_TRequest , _TResponse ], metaclass = abc .ABCMeta ):
343+ class StreamUnaryClientInterceptor (ClientInterceptor , metaclass = abc .ABCMeta ):
344+ # This method (not the class) is generic over _TRequest and _TResponse
345+ # and the types must satisfy the no-op implementation of
346+ # `return await continuation(client_call_details, request_iterator)`.
339347 @abc .abstractmethod
340348 async def intercept_stream_unary (
341349 self ,
342- continuation : Callable [[ClientCallDetails , _TRequest ], StreamUnaryCall [_TRequest , _TResponse ]],
350+ continuation : Callable [
351+ [ClientCallDetails , AsyncIterable [_TRequest ] | Iterable [_TRequest ]], Awaitable [StreamUnaryCall [_TRequest , _TResponse ]]
352+ ],
343353 client_call_details : ClientCallDetails ,
344354 request_iterator : AsyncIterable [_TRequest ] | Iterable [_TRequest ],
345- ) -> AsyncIterable [ _TResponse ] | UnaryStreamCall [_TRequest , _TResponse ]: ...
355+ ) -> _TResponse | StreamUnaryCall [_TRequest , _TResponse ]: ...
346356
347- class StreamStreamClientInterceptor (Generic [_TRequest , _TResponse ], metaclass = abc .ABCMeta ):
357+ class StreamStreamClientInterceptor (ClientInterceptor , metaclass = abc .ABCMeta ):
358+ # This method (not the class) is generic over _TRequest and _TResponse
359+ # and the types must satisfy the no-op implementation of
360+ # `return await continuation(client_call_details, request_iterator)`.
348361 @abc .abstractmethod
349362 async def intercept_stream_stream (
350363 self ,
351- continuation : Callable [[ClientCallDetails , _TRequest ], StreamStreamCall [_TRequest , _TResponse ]],
364+ continuation : Callable [
365+ [ClientCallDetails , AsyncIterable [_TRequest ] | Iterable [_TRequest ]],
366+ Awaitable [StreamStreamCall [_TRequest , _TResponse ]],
367+ ],
352368 client_call_details : ClientCallDetails ,
353369 request_iterator : AsyncIterable [_TRequest ] | Iterable [_TRequest ],
354- ) -> AsyncIterable [_TResponse ] | StreamStreamCall [_TRequest , _TResponse ]: ...
370+ ) -> AsyncIterator [_TResponse ] | StreamStreamCall [_TRequest , _TResponse ]: ...
355371
356372# Server-Side Interceptor:
357373
358374class ServerInterceptor (metaclass = abc .ABCMeta ):
359- # This method (not the class) is generic over _TRequest and _TResponse.
375+ # This method (not the class) is generic over _TRequest and _TResponse
376+ # and the types must satisfy the no-op implementation of
377+ # `return await continuation(handler_call_details)`.
360378 @abc .abstractmethod
361379 async def intercept_service (
362380 self ,
0 commit comments