django-stubs
django-stubs copied to clipboard
MultipleObjectMixin and SingleObjectMixin has incompatible types for queryset and context_object_name
Bug report
What's wrong
I have view class in django-hordak defined as:
class AccountTransactionsView(LoginRequiredMixin, SingleObjectMixin, ListView):
...
Which gives the following mypy errors:
# mypy .
hordak/views/accounts.py:86: error: Definition of "context_object_name" in base class "SingleObjectMixin" is incompatible with definition in base class "MultipleObjectMixin"
hordak/views/accounts.py:86: error: Definition of "queryset" in base class "SingleObjectMixin" is incompatible with definition in base class "MultipleObjectMixin"
Found 2 errors in 1 file (checked 56 source files)
How is that should be
Types for queryset and context_object_name should be made less strict to be compatible similar to solution of issue #152
System information
- OS: Ubuntu
pythonversion: 3.9.7djangoversion: 4.0.2mypyversion: 0.931django-stubsversion: 1.9.0django-stubs-extversion: 0.3.1
Probably I misunderstand something, but it looks like unsafe code. SingleObjectMixin.queryset is a queryset to get_object from, it should be QuerySet[Account] (if it is "view listing transactions for account"). MultipleObjectMixin.queryset is queryset you operate on (e.g. render in ListView) - it should be QuerySet[Transaction]. These two bases are really incompatible.