Fix grpc aio handler typing by XiaXia009 · Pull Request #15497 · python/typeshed · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions stubs/grpcio/@tests/test_cases/check_server_interceptor.py
16 changes: 15 additions & 1 deletion stubs/grpcio/grpc/aio/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ from grpc import (
GenericRpcHandler,
HandlerCallDetails,
RpcError,
RpcMethodHandler,
ServerCredentials,
StatusCode,
_Options,
Expand Down Expand Up @@ -369,6 +368,21 @@ class StreamStreamClientInterceptor(ClientInterceptor, metaclass=abc.ABCMeta):
request_iterator: AsyncIterable[_TRequest] | Iterable[_TRequest],
) -> AsyncIterator[_TResponse] | StreamStreamCall[_TRequest, _TResponse]: ...

# Service-Side Handler:

@type_check_only
class RpcMethodHandler(Generic[_TRequest, _TResponse]):
Comment on lines +373 to +374

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from marking non-existing runtime types with @type_check_only, we also prefix them with an underscore to make it very obvious that something is "wrong" with this type to users. I would also like to add some explanation for why this type is here, and add Async to the name to clearly distinguish it from the "regular" RpcMethodHandler:

Suggested change

request_streaming: bool
response_streaming: bool

request_deserializer: _Deserializer[_TRequest] | None
response_serializer: _Serializer[_TResponse] | None

unary_unary: Callable[[_TRequest, ServicerContext[_TRequest, _TResponse]], Awaitable[_TResponse]] | None
unary_stream: Callable[[_TRequest, ServicerContext[_TRequest, _TResponse]], AsyncIterator[_TResponse]] | None
stream_unary: Callable[[AsyncIterator[_TRequest], ServicerContext[_TRequest, _TResponse]], Awaitable[_TResponse]] | None
stream_stream: Callable[[AsyncIterator[_TRequest], ServicerContext[_TRequest, _TResponse]], AsyncIterator[_TResponse]] | None

# Server-Side Interceptor:

class ServerInterceptor(metaclass=abc.ABCMeta):
Expand Down