What type hint to use for a function which returns a queryset like the one below?
def _get_cars_for_validation(filter_: dict) -> QuerySet:
return (
Car.objects.filter(**filter_)
.values("id", "brand", "engine")
.order_by("id")
)
mypy
returns an error
Incompatible return value type (got "ValuesQuerySet[Car, TypedDict({'id': int, 'brand': str, 'engine': str})]", expected "QuerySet[Any]")
I would use ValuesQuerySet
but it was removed in Django 1.9. ValuesQuerySet
reported by mypy
comes from 3rd party lib django-stubs
(and I am unable to import it; is it actually possible?).