-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not getting the type for the grpc response #277
Comments
Hiya, thanks for the report. Just to check
To help you debug, mypy has a feature called |
python -m grpc_tools.protoc --proto_path=protos --python_out=. --mypy_out=. --grpc_python_out=. --mypy_grpc_out=. protos/greeter.proto
syntax = "proto3";
service Greeter {
rpc HelloWorld (Request) returns (Response) {}
}
message Response {
repeated string tags = 1;
}
message Request {
string title = 1;
}
import grpc
import greeter_pb2
import greeter_pb2_grpc
request = greeter_pb2.Request(title="abc")
with grpc.insecure_channel("alba:50051") as channel:
stub = greeter_pb2_grpc.GreeterStub(channel)
response = stub.HelloWorld(request) Note WorkaroundI can get the typing by simply enforcing it with response: greeter_pb2_grpc.Response = stub.HelloWorld(request) but it shouldn't be necessary. |
I reproduced the issue by creating your test case. When running mypy - I see this
I am not totally sure why, but it doesn't seem to be resolving the relative import of we definitely have tests confirming the types here So there's clearly some difference in configuration between the testsuite and the repro that you've provided. I added a couple of
I was able to repro the issue in the testsuite by removing
From this - I was able to get your testcase to work by adding an Sadly protobuf itself does absolute imports (protocolbuffers/protobuf#881) - and doesn't produce I will consider using absolute imports similarly in the |
Wow great investigative work. Thanks for that! |
The type of
response
in the following code isUnknown
.Is that expected?
I'd expect a typed
TagReply
since my proto looks like thisThe text was updated successfully, but these errors were encountered: