Skip to content

Commit 098f30e

Browse files
Allow None return from grpc.aio.ServerInterceptor.intercept_service (#15783)
1 parent 536aeeb commit 098f30e

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

stubs/grpcio/@tests/test_cases/check_server_interceptor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def intercept_service(
2626
class NoopAioInterceptor(grpc.aio.ServerInterceptor):
2727
async def intercept_service(
2828
self,
29-
continuation: Callable[[grpc.HandlerCallDetails], Awaitable[grpc.RpcMethodHandler[RequestT, ResponseT]]],
29+
continuation: Callable[[grpc.HandlerCallDetails], Awaitable[grpc.RpcMethodHandler[RequestT, ResponseT] | None]],
3030
handler_call_details: grpc.HandlerCallDetails,
31-
) -> grpc.RpcMethodHandler[RequestT, ResponseT]:
31+
) -> grpc.RpcMethodHandler[RequestT, ResponseT] | None:
3232
return await continuation(handler_call_details)
3333

3434

stubs/grpcio/grpc/aio/__init__.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,15 @@ class ServerInterceptor(metaclass=abc.ABCMeta):
375375
# This method (not the class) is generic over _TRequest and _TResponse
376376
# and the types must satisfy the no-op implementation of
377377
# `return await continuation(handler_call_details)`.
378+
# The return is Optional: per the runtime docstring, an interceptor
379+
# may return None to signal that the RPC is not serviced, and the
380+
# continuation propagates that None down the chain.
378381
@abc.abstractmethod
379382
async def intercept_service(
380383
self,
381-
continuation: Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler[_TRequest, _TResponse]]],
384+
continuation: Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler[_TRequest, _TResponse] | None]],
382385
handler_call_details: HandlerCallDetails,
383-
) -> RpcMethodHandler[_TRequest, _TResponse]: ...
386+
) -> RpcMethodHandler[_TRequest, _TResponse] | None: ...
384387

385388
# Multi-Callable Interfaces:
386389

0 commit comments

Comments
 (0)