Giter Site home page Giter Site logo

Comments (13)

shabbyrobe avatar shabbyrobe commented on July 19, 2024 1

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.

sobolevn avatar sobolevn commented on July 19, 2024 1

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.

shabbyrobe avatar shabbyrobe commented on July 19, 2024

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.

sobolevn avatar sobolevn commented on July 19, 2024

@shabbyrobe awesome! Thanks 🙂

Feel free to reach out in case you need any help!

from grpc-stubs.

shabbyrobe avatar shabbyrobe commented on July 19, 2024

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.

shabbyrobe avatar shabbyrobe commented on July 19, 2024

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.

sobolevn avatar sobolevn commented on July 19, 2024

@shabbyrobe no problem, I am at your service 🙂

Can you please show me the code?

from grpc-stubs.

shabbyrobe avatar shabbyrobe commented on July 19, 2024

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.

sobolevn avatar sobolevn commented on July 19, 2024

My wild guess is that mypy cannot find your stub files for some reason.
Things to try:

  1. 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
  2. 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.

shabbyrobe avatar shabbyrobe commented on July 19, 2024

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.

shabbyrobe avatar shabbyrobe commented on July 19, 2024

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.

sobolevn avatar sobolevn commented on July 19, 2024

@shabbyrobe no problem! Glad that it worked! 👍

from grpc-stubs.

shabbyrobe avatar shabbyrobe commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.