Comments (13)
That went in really easily. The instructions in your blog post were super clear. I'll work on adding more cases over time; at least I know now I have a good way to prevent further regressions. Thanks again!
from grpc-stubs.
Hm, will regular mypy
calls work? Like so:
# ./ex.py
from grpc import Channel
reveal_type(Channel())
And then mypy ex.py
from grpc-stubs.
Hello! Thanks so much for reaching out. That testing stuff looks great, I'll definitely look to getting it integrated with this. It's still early days for me with typed python so I'm likely to make a few more egregious errors before I find an equilibrium... maybe I'm not quite across the fine details of writing typing stubs for them to be fit for public consumption yet so I'm grateful for your support. Hopefully I don't break too many people's builds as I learn my way around.
Also, I was not aware of awesome-python-stubs, so thank you also for the link.
from grpc-stubs.
@shabbyrobe awesome! Thanks 🙂
Feel free to reach out in case you need any help!
from grpc-stubs.
It has only been 10 minutes, I only have 2 test cases, and I already flushed out a bug. Pretty quick payoff here! 👍
from grpc-stubs.
Hi @sobolevn; I hope you don't mind me "@"-ing you, but I'm having some trouble with pytest-mypy-plugins
in this project; it doesn't appear to actually be loading the stubs when I run pytest. It reports the types are all Any
and if I fill the stub files with junk it doesn't fail with syntax errors. I figure I'm doing something silly while sewing it together but I just can't seem to find the magic incantation
from grpc-stubs.
@shabbyrobe no problem, I am at your service 🙂
Can you please show me the code?
from grpc-stubs.
Sure! Thank you!
The issue is the grpc_channel_context_manager
test in test_grpc.yml:
- case: grpc_channel_context_manager
main: |
from grpc import Channel
reveal_type(Channel()) # N: Revealed type is 'Channel'
When I try to run it (pytest --mypy-ini-file=setup.cfg
), I get the following error, which indicates the stubs aren't loading at all:
/home/bl/code/py/grpc-stubs/typesafety/test_grpc.yml:5:
E pytest_mypy.utils.TypecheckAssertionError: Invalid output:
E Expected:
E main:3: note: Revealed type is 'Channel' (diff)
E Actual:
E main:3: note: Revealed type is 'Any' (diff)
E
E Alignment of first line difference:
E E: ...te: Revealed type is 'Channel'
E A: ...te: Revealed type is 'Any'
E ^
from grpc-stubs.
My wild guess is that mypy
cannot find your stub files for some reason.
Things to try:
- Make sure that your stubs are found by
setuptools
: https://github.com/typeddjango/django-stubs/blob/master/setup.py#L43 Docs on module resolution: https://www.python.org/dev/peps/pep-0561/#type-checker-module-resolution-order - Make sure that
PYTHONPATH
is set correctly on your system
You can have a look at the fully-working example here: https://github.com/typeddjango/django-stubs/tree/master/test-data It also works with stubs.
from grpc-stubs.
Thanks for getting back to me so quickly!
I've just confirmed your theory - I edited __init__.pyi
, added a whole bunch of unparseable junk, and the output was the same; the same failed test, the same error message.
I'm using I think the exact same find_stub_files
function in my setup.py
(probably copy-pasted from django-stubs); I checked it and the output is what I expect: {'grpc-stubs': ['__init__.pyi'], 'grpc_status-stubs': ['__init__.pyi', 'rpc_status.pyi']}
PYTHONPATH
is not set, but I'm in a virtualenv.
from grpc-stubs.
Oh no! It's so obvious now, as soon as I type the word virtualenv
... I must be using a globally installed pytest
, I mustn't've installed it in the venv...
Just checked, that was indeed it. I'm so sorry to waste your time on something so silly!
from grpc-stubs.
@shabbyrobe no problem! Glad that it worked! 👍
from grpc-stubs.
Now that it's all working and sorted, I'll close this issue as solved. Thank you again for your help, and for the recommendation for the package too!
from grpc-stubs.
Related Issues (20)
- Publish new version HOT 1
- Distribution doesn't include py.typed files. HOT 2
- 1.24 updates
- No stubs for `aio` HOT 9
- 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
- The partial typing of the aio.pyi module causes an error HOT 4
- pypi version 1.53.0.1 HOT 1
- enable_server_reflection should allow aio server instances
- Typeshed HOT 9
- The object returned from `UnaryStreamMultiCallable` and `StreamStreamMultiCallable` should also be a `Future` HOT 2
- Wrong type hints for continuation in streaming interceptors HOT 1
- intercept_stream_stream in grpc.aio incorrectly marked as a coroutine HOT 2
- `ServerInterceptor.intercept_service` return type doesn't match continuation return type HOT 2
- Type hints for abstract base classes are missing `abc.ABC`
- `CallIterator` is missing `__next__` method
- 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.