Skip to content
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

No stubs for client stubs? #26

Closed
LanDinh opened this issue Dec 9, 2021 · 5 comments
Closed

No stubs for client stubs? #26

LanDinh opened this issue Dec 9, 2021 · 5 comments

Comments

@LanDinh
Copy link

LanDinh commented Dec 9, 2021

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

error: Call to untyped function "ServiceStub" in typed context  [no-untyped-call]

This error is happening on the line in which I instantiate my client:

channel = grpc.insecure_channel("some-address:8000")
client = ServiceStub(channel)  # This line is triggering the error
response = client.SomeMethod(request)

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?

@gitpushdashf
Copy link
Contributor

You have to generate type hints for your stubs: https://github.com/nipunn1313/mypy-protobuf

@LanDinh
Copy link
Author

LanDinh commented Jun 28, 2022

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.

@gitpushdashf
Copy link
Contributor

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.

@LanDinh
Copy link
Author

LanDinh commented Jun 28, 2022

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, ...)

@gitpushdashf
Copy link
Contributor

Hmm. Maybe try adding --mypy_grpc_out as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants