python/typeshed

grpc.aio.ServerInterceptor is incompatible with async RPC methods

Open

#15,495 创建于 2026年3月8日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Python (1,483 fork)batch import
help wantedstubs: false positive

仓库指标

Star
 (3,436 star)
PR 合并指标
 (平均合并 12天 21小时) (30 天内合并 66 个 PR)

描述

The grpc.aio.ServerInterceptor is currently annotated using grpc.RpcMethodHandler. However the interface for grpc.RpcMethodHandler is not compatible with async RPC methods. The correct stub for an async version would make use of Awaitable and AsyncIterator:

class RpcMethodHandler(abc.ABC, Generic[_TRequest, _TResponse]):
    request_streaming: bool
    response_streaming: bool

    # XXX: not clear from docs whether this is optional or not
    request_deserializer: _Deserializer[_TRequest] | None

    # XXX: not clear from docs whether this is optional or not
    response_serializer: _Serializer[_TResponse] | None

    unary_unary: Callable[[_TRequest, ServicerContext], Awaitable[_TResponse]] | None

    unary_stream: Callable[[_TRequest, ServicerContext], AsyncIterator[_TResponse]] | None

    stream_unary: Callable[[Iterator[_TRequest], ServicerContext], Awaitable[_TResponse]] | None

    stream_stream: Callable[[Iterator[_TRequest], ServicerContext], AsyncIterator[_TResponse]] | None

贡献者指南