You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The recent addition of Sequence for BaseListView.object_list breaks code that expects it to be a QuerySet (which is the default behaviour in Django CBVs, unless you override the queryset attribute or get_queryset method).
At a minimum, object_list should be a Union of Iterable[T] or a QuerySet[T].
However, I don't think this is an optimal solution either. The default behaviour in Django CBVs is that it be a QuerySet - BaseListView.get() sets the value of object_list to the result of get_queryset(), which currently is always a QuerySet[T] in django-stubs (as is the attribute MultipleObjectMixin.queryset). So it is a bit inconsistent to have object_list be typed differently.
As per #477 , QuerySet is over-specific for get_queryset() (and for the queryset attribute) and probably should be possible for it to be an Iterable[T] as well. My concern on that issue applies here too.
As I asked in the other issue; is there a better solution? This is one area of python typing I find really challenging, and I'm not sure what options there are to make this work in a good way, if any.
System information
OS:
python version: 3.9.10 and 3.10.2
django version: 4.0.2
mypy version: 0.942
django-stubs version: 1.10.1
django-stubs-ext version: 0.4.0
The text was updated successfully, but these errors were encountered:
I'm going to bring in a quote from Django's documentation regarding object_list on ListView:
While this view is executing, self.object_list will contain the list of objects (usually, but not necessarily a queryset) that the view is operating upon.
The type of object_list is no longer Sequence, since #909. I'm not totally sure if the current type is optimal and the quote from the docs doesn't really help either, but it's currently better than Sequence.
Bug report
What's wrong
The recent addition of Sequence for BaseListView.object_list breaks code that expects it to be a QuerySet (which is the default behaviour in Django CBVs, unless you override the queryset attribute or get_queryset method).
A commit adding a failing test case can be found here: https://github.com/LucidDan/django-stubs/commit/7ec7761708653439945a589d08d98e6174e7c6b9
How is that should be
At a minimum, object_list should be a Union of Iterable[T] or a QuerySet[T].
However, I don't think this is an optimal solution either. The default behaviour in Django CBVs is that it be a QuerySet - BaseListView.get() sets the value of object_list to the result of get_queryset(), which currently is always a QuerySet[T] in django-stubs (as is the attribute MultipleObjectMixin.queryset). So it is a bit inconsistent to have object_list be typed differently.
As per #477 , QuerySet is over-specific for get_queryset() (and for the queryset attribute) and probably should be possible for it to be an Iterable[T] as well. My concern on that issue applies here too.
As I asked in the other issue; is there a better solution? This is one area of python typing I find really challenging, and I'm not sure what options there are to make this work in a good way, if any.
System information
python
version: 3.9.10 and 3.10.2django
version: 4.0.2mypy
version: 0.942django-stubs
version: 1.10.1django-stubs-ext
version: 0.4.0The text was updated successfully, but these errors were encountered: