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

How to use with mypy #37

Closed
last-partizan opened this issue Jun 8, 2023 · 4 comments
Closed

How to use with mypy #37

last-partizan opened this issue Jun 8, 2023 · 4 comments

Comments

@last-partizan
Copy link

Is there any steps required to use it with mypy?

I have installed it:

# requirements.txt
Django==4.2.2
djangorestframework==3.14.0
djangorestframework-types==0.8.0
django-types==0.17.0
django-filter==23.2
mypy==1.3.0

But mypy seems to ignore it:

mypy example.py
example.py:1: error: Cannot find implementation or library stub for module named "rest_framework.viewsets"  [import]
example.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
example.py:2: error: Cannot find implementation or library stub for module named "django_filters.rest_framework"  [import]
Found 2 errors in 1 file (checked 1 source file)
@dolfandringa
Copy link

As stated in the README and on pypi:

Note: this project was forked from https://github.com/typeddjango/djangorestframework-stubs with the goal of removing the mypy plugin dependency so that mypy can't typeddjango/django-stubs#318, and that non-mypy type checkers like pyright will work better with Django Rest Framework.

If you want to use mypy, why not use the original https://github.com/typeddjango/djangorestframework-stubs

@last-partizan
Copy link
Author

I was trying to check some cross-type-checker behaviour. And if type-checker-agnosctics is the goal - it should work with mypy also.

I think there's just some misconfiguration on my part, but i have no idea where.

@dolfandringa
Copy link

AH, wait, I see your error.
It is:

Cannot find implementation or library stub for module named "django_filters.rest_framework"

That is an issue with django_filters, not restframework. For pyright, I locally added this file to my own respository which addresses that:

typings/django_filters/rest_framework.pyi:

from rest_framework.filters import _FilterBackendProtocol  # type: ignore [reportPrivateUsage]

class DjangoFilterBackend(_FilterBackendProtocol): ...

@last-partizan
Copy link
Author

Turned out, i need to install mypy to the same venv i'm using. Global installation doesn't work.

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

2 participants