django-stubs
django-stubs copied to clipboard
`RawQuerySet` has conflicting errors: "is not subscriptable" vs "Missing type parameter"
Bug report
What's wrong
Using RawQuerySet as type annotation is not possible.
Without the generic parameter, mypy fails with is not subscriptable error.
With the generic parameter, python throws TypeError.
from django.db.models.query import RawQuerySet
from models import MyModel
# TypeError: type 'RawQuerySet' is not subscriptable
def foo() -> RawQuerySet[MyModel]:
return MyModel.objects.raw("SELECT id FROM my_model")
# mypy error: Missing type parameters for generic type "RawQuerySet" [type-arg]
def bar() -> RawQuerySet:
return MyModel.objects.raw("SELECT id FROM my_model")
System information
- OS: Ubuntu 24.04
pythonversion: 3.12.3djangoversion: 5.0.6mypyversion: 1.10django-stubsversion: 5.0.2django-stubs-extversion: 5.0.2