django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

`RawQuerySet` has conflicting errors: "is not subscriptable" vs "Missing type parameter"

Open hterik opened this issue 1 year ago • 2 comments

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
  • python version: 3.12.3
  • django version: 5.0.6
  • mypy version: 1.10
  • django-stubs version: 5.0.2
  • django-stubs-ext version: 5.0.2

hterik avatar Jun 25 '24 07:06 hterik