Closed
Description
Bug report
What's wrong
I can't set the correct type on the return value of a values list.
Simplified example:
class Question:
category = models.TextField()
def get_result() -> QuerySet[Any]:
result = Exam.objects.get().questions.values_list("category", flat=True)
reveal_type(result) # Revealed type is "django.db.models.query._QuerySet[backend.models.Question, Union[builtins.str, None]]"
return result
reveal_type(get_result()) # Revealed type is "django.db.models.query._QuerySet[Any, Any]"
How is that should be
The calling code needs to loop over the categories, i.e. it needs a sequence of type str.
What is the best way to annotate the get_result function?
System information
- OS: debian 11
python
version: 3.9.7django
version: 3.2.13mypy
version: 0.961django-stubs
version: 1.12.0django-stubs-ext
version: 0.4.0