Fix the generic-ness of the non-aio and aio ClientInterceptors: previously an interceptor was generic over (TRequest, TResponse) meaning that an instantiated interceptor can only handle one particular RPC. This is clearly wrong, as an interceptor (which is attached to the channel) should be able to handle all RPCs. This means that an interceptor must be generic-less and the intercept methods should be generic over all (TRequest, TResponse) instead.
See the new test cases for an example of how interceptors are meant to work.
A few other fixes and tweaks too:
Properly type serializers/deserializers with a new generic _Serializer[_T] and _Deserializer[_T]: these are just functions to/from bytes, confirmed by reading the Cython code.
Fix the continuation type on the non-aio client streaming interceptors. The continuation describes the "underlying handler" and so should be passed the original request iterator, not just a single request item.
Add a new _Iterable[_T] in the aio stubs as the union of AsyncIterable[_T] and Iterable[_T], since aio client streaming methods can accept either async or non-async iterators. Note that server streaming methods always give an async iterator.
Correct a few missing generic types here and there.
Minimum Reproducible Example
See the added test cases.
Checklist:
[x] I have verified my MRE is sufficient to demonstrate the issue and solution by attempting to execute it myself
[ ] OR I believe my contribution is minor enough that a typing test is sufficient.
[x] I have added tests to typesafety/test_grpc.yml for all APIs added or changed by this PR
[x] I have removed any code generation notices from anything seeded using mypy-protobuf.
Description of change
Fix the generic-ness of the non-aio and aio ClientInterceptors: previously an interceptor was generic over (TRequest, TResponse) meaning that an instantiated interceptor can only handle one particular RPC. This is clearly wrong, as an interceptor (which is attached to the channel) should be able to handle all RPCs. This means that an interceptor must be generic-less and the intercept methods should be generic over all (TRequest, TResponse) instead.
See the new test cases for an example of how interceptors are meant to work.
A few other fixes and tweaks too:
_Serializer[_T]
and_Deserializer[_T]
: these are just functions to/frombytes
, confirmed by reading the Cython code._Iterable[_T]
in the aio stubs as the union ofAsyncIterable[_T]
andIterable[_T]
, since aio client streaming methods can accept either async or non-async iterators. Note that server streaming methods always give an async iterator.Minimum Reproducible Example
See the added test cases.
Checklist:
typesafety/test_grpc.yml
for all APIs added or changed by this PRmypy-protobuf
.