Open ArthurBook opened 3 months ago
Yeah that's interesting. It's a little surprising that only the async stub has @Evgenus worked on this originally and may have some insight.
I am curious what concrete issue you're running into as a result of this. Is there a typecheck issue that comes up?
mypy-protobuf has tests https://github.com/nipunn1313/mypy-protobuf/blob/main/proto/testproto/grpc/import.proto which generates this stub https://github.com/nipunn1313/mypy-protobuf/blob/main/test/generated/testproto/grpc/import_pb2_grpc.pyi Which typechecks (our CI checks it).
It's a minor issue, but since the UnaryUnaryMultiCallable.__call__
doesn't have types, the return type of the generated RPC request method on the client will be unknown for type checkers.
import grpc
from shared.generated_code import service_pb2, service_pb2_grpc
def run() -> None:
channel = grpc.insecure_channel("localhost:50051")
stub = service_pb2_grpc.Service1Stub(channel)
request = service_pb2.GetUserRequest(user_id=123)
response = stub.GetUser(request) # (variable) response: Unknown
if __name__ == "__main__":
run()
Hi, thanks for the work on this project. It really improves the development workflow to have the proto and grpc interfaces recognizable by the language server (vscode pyright in my case).
The confusion / bug
When inspecting the generated .pyi file, I notice that the method type referenced in the client stub:
grpc.UnaryUnaryMultiCallable
is hinted with two type parameters:However, in the source implementation there are no generic typevars bound to the
grpc.UnaryUnaryMultiCallable
.It looks like there are typevars bound to the async version of the async version of unary-unary RPC that can be found here.
Let me know if something might be misconfigured on my side -- elsewise, more than happy to open a PR that suggests adding in the
RequestType
andResponseType
generics to the synchronous unary-unary in the grpc repo!Background / replication
Simplen sample client stub .proto file:
By running:
...It produces the following
pb2_grpc_.pyi
stub file: