Comments (9)
Tagging onto this. Over here I ran into an issue where when i use grpc-stubs
it breaks any sort of typing for aio. Where if I don't have grpc-stubs
installed it gets some basic type info (and doesn't fail to import). Is there an easy way to make grpc-stubs
only be a stub package for the non-aio subset? Or am I stuck with a this or that.
from grpc-stubs.
I think you are asking for a partial stub package. https://www.python.org/dev/peps/pep-0561/#partial-stub-packages If stub package includes the line partial\n
in it's py.typed it is treated as only documenting a part of package.
https://github.com/shabbyrobe/grpc-stubs/blob/master/grpc-stubs/py.typed add one line to that file and that may be enough to fix your issue.
from grpc-stubs.
There's no stubs for grpc aio, to my knowledge. As a workaround, you can do this:
pyproject.toml
:
[[tool.mypy.overrides]]
module = [
"grpc.aio.*", # https://github.com/shabbyrobe/grpc-stubs/issues/22
]
ignore_missing_imports = true
from grpc-stubs.
Thanks for reaching out! There are no concrete plans but there's definitely a desire.
The last PR had to be reverted because it introduced a ton of problems I didn't have the time or inclination to work through. It was all autogenerated, didn't play nice with the rest of the package, and when I tried to write tests it showed up a lot of issues I didn't want to impose on package users. The PRs I get here are usually fine but this one caught me unawares and I just haven't come back to it yet.
I think one of the things that would most help nudge me into action here would be if you had any simple, runnable examples of the ways you use the package lying around. That'd help me set up an environment (which if I'm honest, I find a bit of an "ugh" task) I can use to validate whether we're on the right track. The easier it is for me to run the examples without faffing around, the likelier it is that I'll get cracking on it.
After the issues with the previous attempt, I probably won't just accept something wholesale again, I'd prefer to be involved, especially as there seemed to be a lot of messy overlap between the different coloured versions. I certainly won't be merging something that large without tests again, I've learned my lesson there! But as I'm not using the aio part of the package myself, that's really where those examples will be a huge help.
from grpc-stubs.
A sample aio
test case could look like:
@pytest.mark.asyncio
async def test_grpc_response() -> None:
request = my_pb2.MyRequest(prop1="hello")
async with grpc.aio.insecure_channel("localhost:8000") as channel:
stub = my_pb2_grpc.MyServiceStub(channel)
response = await stub.GetResponse(request)
assert response
Note that mypy also doesn't support the generated pb2
and pb2_grpc
files properly. An issue has been filed with mypy-protobuf
as well.
See: nipunn1313/mypy-protobuf#216
from grpc-stubs.
My understanding is that generating stubs for _pb2.py
(andpb2_grpc.py
for non-aio use cases) are supported by mypy-protobuf
In order to generate reasonable stubs for pb2_grpc
for aio use cases, it'll need to import grpc.aio.Server
to generate roughly this (or potentially two overloaded definitions - one for sync, one for async).
def add_DummyServiceServicer_to_server(
servicer: DummyServiceServicer,
server: typing.Union[grpc.Server, grpc.aio.AioServer]) -> None: ...
Hence I think this task is a pre-req for mypy-protobuf support.
from grpc-stubs.
I think you are asking for a partial stub package. https://www.python.org/dev/peps/pep-0561/#partial-stub-packages If stub package includes the line
partial\n
in it's py.typed it is treated as only documenting a part of package.https://github.com/shabbyrobe/grpc-stubs/blob/master/grpc-stubs/py.typed add one line to that file and that may be enough to fix your issue.
@shabbyrobe would you be open to a PR for this if it works?
from grpc-stubs.
Thanks to #22 (comment) for the tip, here's a workaround for pyright:
In your source, import aio as
import grpc.aio as aio
to ensure we get a missing import error instead of a missing symbol error. Then in the pyproject.toml
:
[tool.pyright]
exclude = ["**/*_pb2*"]
# https://github.com/shabbyrobe/grpc-stubs/issues/22
reportMissingImports = "warning"
But an even more targeted workaround is something like:
# TODO remove ignore when stubs are availabe for grpc.aio
# See https://github.com/shabbyrobe/grpc-stubs/issues/22
import grpc.aio as aio # type: ignore
UPDATE: doh! sorry for the commit spam! I shouldn't have linked this issue in the commit X|
from grpc-stubs.
Related Issues (11)
- Consider using pytest-mypy-plugins HOT 13
- Publish new version HOT 1
- Distribution doesn't include py.typed files. HOT 2
- 1.24 updates
- No stubs for client stubs? HOT 5
- can mypy be optional dependency? HOT 2
- Typing of HealthServicer.set HOT 6
- Missing grpc StatusCode HOT 1
- Typeshed HOT 9
- Argument `grace` of Server.stop() should be Optional[float] HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-stubs.