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

Help installing the appropriate stub version #662

Open
DMunkei opened this issue Sep 13, 2024 · 2 comments
Open

Help installing the appropriate stub version #662

DMunkei opened this issue Sep 13, 2024 · 2 comments
Labels
pyright Related to pyright type checker question Further information is requested

Comments

@DMunkei
Copy link

DMunkei commented Sep 13, 2024

Hey, I'm not understanding which version of the stubs I need to install?

These are my installed modules per pip list.

django-stubs              4.2.7
django-stubs-ext          5.0.4
djangorestframework       3.14.0
Django                    4.2.9
mypy                      1.7.1
mypy-extensions           1.0.0

If I'm understanding the docs right. then I am supposed to install the 1.7.0 version to match the mypy version I have?

Would the command look like this?

pip install djangorestframework-stubs==1.7.0

When I open my editor NeoVim with the virtual environment active I get this error message for this line of code.

from rest_framework import serializers
Diagnostics:
1. Import "rest_framework" could not be resolved [reportMissingImports]

Hopefully someone can make sense of this and help me out :)

Cheers!

@intgr intgr added question Further information is requested pyright Related to pyright type checker labels Sep 13, 2024
@intgr
Copy link
Contributor

intgr commented Sep 13, 2024

If I'm understanding the docs right. then I am supposed to install the 1.7.0 version to match the mypy version I have?

That's not correct, I guess the documentation is unclear. Is there something we can improve in the docs?

The latest version that is strictly compatible with mypy 1.7.0 is djangorestframework-stubs==3.14.5 (setup.py)

(Note: There's a tradeoff between using older -stubs versions, or updating to latest even if your Django version is not latest. See here for details: typeddjango/django-stubs#2101 (comment))

When I open my editor NeoVim with the virtual environment active I get this error message for this line of code.
1. Import "rest_framework" could not be resolved [reportMissingImports]

This error comes from pylance/pyright, not mypy.

I'm guessing you installed djangorestframework-stubs inside a virtualenv, but when NeoVim invokes pyright, it runs outside of that virtualenv and does not find the stubs package. You can probably configure it to use the venv. But sorry, can't help more there, I have not used pyright/NeoVim myself.

@intgr intgr changed the title Help installing the appropriate stub version. Help installing the appropriate stub version Sep 13, 2024
@DMunkei
Copy link
Author

DMunkei commented Sep 14, 2024

I'm not really experience with mypy and stubs. What would you recommend me doing? Would appreciate that if it's not too much of an inconveniece. Do I simply just execute these commands?

pip install myp
pip install djangorestframework-stubs
pip install django-stubs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pyright Related to pyright type checker question Further information is requested
Development

No branches or pull requests

2 participants