We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
This is probably a silly question. I'm getting runtime errors when using the QuerySet[] generic.
Consider this file:
mypy_test.py
from django.contrib.auth.models import User, Permission from django.db.models.query import QuerySet def f(queryset: QuerySet[User]) -> QuerySet[User]: return queryset.order_by('id') def g() -> None: print(f(User.objects.all())) print(f(Permission.objects.all()))
Mypy is working as expected (which tells me, I've configured django-stubs correctly):
mypy src/mypy_test.py src/mypy_test.py:11: error: Argument 1 to "f" has incompatible type "QuerySet[Permission, Permission]"; expected "QuerySet[User, User]" exit 1
Only, I can't import this file:
In [1]: import mypy_test --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-040518e7b0e9> in <module> ----> 1 import mypy_test ~/Projects/flatfox-website/src/mypy_test.py in <module> 3 4 ----> 5 def f(queryset: QuerySet[User]) -> QuerySet[User]: 6 return queryset.order_by('id') 7 TypeError: 'type' object is not subscriptable In [2]:
Why is the interpreter even trying to make sense of the type annotations? I'm confused, appreciating any help!
Oh, and many thanks for your work on this package!
mypy.ini
# Global options: [mypy] python_version = 3.6 warn_return_any = True warn_unused_configs = True ignore_missing_imports = True plugins = mypy_django_plugin.main
I don't have a mypy_django.ini.
The text was updated successfully, but these errors were encountered:
Use quotes around the annotation like that, 'QuerySet[Model]', as QuerySet does not yet support __class_getitem__ and therefore not subscriptable.
'QuerySet[Model]'
QuerySet
__class_getitem__
Sorry, something went wrong.
Ugh, that would never have occurred to me. Thanks!
No branches or pull requests
This is probably a silly question. I'm getting runtime errors when using the QuerySet[] generic.
Consider this file:
mypy_test.py
Mypy is working as expected (which tells me, I've configured django-stubs correctly):
Only, I can't import this file:
Why is the interpreter even trying to make sense of the type annotations? I'm confused, appreciating any help!
Oh, and many thanks for your work on this package!
mypy.ini
I don't have a mypy_django.ini.
The text was updated successfully, but these errors were encountered: