From 944efeb5d60e3d20423c1dafd7ebdbe03feff82f Mon Sep 17 00:00:00 2001 From: Benjamin Lewars <8916115+Rhadamanthus1@users.noreply.github.com> Date: Tue, 12 May 2026 14:29:06 +0100 Subject: [PATCH 1/2] Allow None return from grpc.aio.ServerInterceptor.intercept_service --- stubs/grpcio/grpc/aio/__init__.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stubs/grpcio/grpc/aio/__init__.pyi b/stubs/grpcio/grpc/aio/__init__.pyi index d05a8c3ddbe5..0704e5dea3d9 100644 --- a/stubs/grpcio/grpc/aio/__init__.pyi +++ b/stubs/grpcio/grpc/aio/__init__.pyi @@ -375,12 +375,15 @@ class ServerInterceptor(metaclass=abc.ABCMeta): # This method (not the class) is generic over _TRequest and _TResponse # and the types must satisfy the no-op implementation of # `return await continuation(handler_call_details)`. + # The return is Optional: per the runtime docstring, an interceptor + # may return None to signal that the RPC is not serviced, and the + # continuation propagates that None down the chain. @abc.abstractmethod async def intercept_service( self, - continuation: Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler[_TRequest, _TResponse]]], + continuation: Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler[_TRequest, _TResponse] | None]], handler_call_details: HandlerCallDetails, - ) -> RpcMethodHandler[_TRequest, _TResponse]: ... + ) -> RpcMethodHandler[_TRequest, _TResponse] | None: ... # Multi-Callable Interfaces: From 81ea9c802bd6af48ce183667f7eaaeab4c5e5869 Mon Sep 17 00:00:00 2001 From: Benjamin Lewars <8916115+Rhadamanthus1@users.noreply.github.com> Date: Tue, 12 May 2026 14:47:54 +0100 Subject: [PATCH 2/2] Update grpcio async ServerInterceptor test case for Optional return --- stubs/grpcio/@tests/test_cases/check_server_interceptor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/grpcio/@tests/test_cases/check_server_interceptor.py b/stubs/grpcio/@tests/test_cases/check_server_interceptor.py index d5ef592a61ad..893ff591fb52 100644 --- a/stubs/grpcio/@tests/test_cases/check_server_interceptor.py +++ b/stubs/grpcio/@tests/test_cases/check_server_interceptor.py @@ -26,9 +26,9 @@ def intercept_service( class NoopAioInterceptor(grpc.aio.ServerInterceptor): async def intercept_service( self, - continuation: Callable[[grpc.HandlerCallDetails], Awaitable[grpc.RpcMethodHandler[RequestT, ResponseT]]], + continuation: Callable[[grpc.HandlerCallDetails], Awaitable[grpc.RpcMethodHandler[RequestT, ResponseT] | None]], handler_call_details: grpc.HandlerCallDetails, - ) -> grpc.RpcMethodHandler[RequestT, ResponseT]: + ) -> grpc.RpcMethodHandler[RequestT, ResponseT] | None: return await continuation(handler_call_details)