Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
|
Sorry for the multiple commits. Some of the CI errors were not reproducible in my local environment, so I had to rely on GitHub Actions to verify the fixes.🥹 |
srittau
left a comment
There was a problem hiding this comment.
Thanks! Some notes below.
| aio_handler = cast(grpc.aio.RpcMethodHandler[bytes, bytes], object()) | ||
| aio_handler.unary_unary = cast(Callable[[bytes, grpc.aio.ServicerContext[bytes, bytes]], Awaitable[bytes]], None) | ||
| aio_handler.unary_stream = cast(Callable[[bytes, grpc.aio.ServicerContext[bytes, bytes]], AsyncIterator[bytes]], None) | ||
| aio_handler.stream_unary = cast(Callable[[AsyncIterator[bytes], grpc.aio.ServicerContext[bytes, bytes]], Awaitable[bytes]], None) | ||
| aio_handler.stream_stream = cast( | ||
| Callable[[AsyncIterator[bytes], grpc.aio.ServicerContext[bytes, bytes]], AsyncIterator[bytes]], None | ||
| ) |
There was a problem hiding this comment.
About tests: We only use tests for complex annotations. In this case, the tests basically replicate the type annotations, so we don't need them.
| @type_check_only | ||
| class RpcMethodHandler(Generic[_TRequest, _TResponse]): |
There was a problem hiding this comment.
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:
| @type_check_only | |
| class RpcMethodHandler(Generic[_TRequest, _TResponse]): | |
| # Async version of gprc.RpcMethodHandler. As opposed to the former, this type | |
| # does not exist at runtime. | |
| @type_check_only | |
| class _AsyncRpcMethodHandler(Generic[_TRequest, _TResponse]): |
Hi there, this is my first contribution to typeshed.
This PR is related to #15495
Fix typing for aio ServerInterceptor continuation.
grpc.aio.ServerInterceptor.intercept_serviceshould returngrpc.aio.RpcMethodHandlerinstead ofgrpc.RpcMethodHandler.The current stub references the synchronous handler type, which is
incorrect for the aio API.
This PR updates:
intercept_service