Closed LanDinh closed 2 years ago
You have to generate type hints for your stubs: https://github.com/nipunn1313/mypy-protobuf
So the thing is that I did generate the the type hints, and they are all there for the protobufs themselves. But there are no type hints for the stubs on the client side. The version of mypy-protobuf that I'm using is 3.2.0.
Did you add __init__.py
files for your stubs? If not, may need to set namespace packages to True with mypy.
I may be misunderstanding you, though.
So what I mean is that I generate my protos with this command:
python -m grpc_tools.protoc -I <proto folder> --python_out=<output folder> --grpc_python_out=<output fuolder> --mypy_out=<output folder> <proto folder>/*.proto
When I then typecheck my project, there are no issues whatsoever with the proto-objects (e.g. I can instantiate them, assign values etc, wrong value types raise type errors etc). But when instantiating the client stub as per my code snippet above (when implementing a gRPC client), type checking produces the error no-untyped-call
, as it doesn't find any type hints for the client stub (e.g. which methods are defined on the stubs, which proto objects are expected as input / output etc).
I'm currently silencing this error (# type: ignore[no-untyped-call]
), but it would be nice to get actual type hints for it (e.g. to get code completion in IDEs etc, have general type checking on the project, ...)
Hmm. Maybe try adding --mypy_grpc_out
as well?
Hey, thanks a ton for these stubs :)
I have recently added some client implementation to my server code (it's a gRPC server that queries another gRPC server), meaning that it makes use of the client stub of that other server.
Now mypy started complaining about
This error is happening on the line in which I instantiate my client:
I had a quick look into this repo to check if I was simply missing something, but I did indeed not find any stubs for the client stubs.
Are they missing? Is there a good way for me to get rid of that error other than ignoring it?