Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive when using mixins with DeleteView #1227

Open
monosans opened this issue Nov 3, 2022 · 1 comment
Open

False positive when using mixins with DeleteView #1227

monosans opened this issue Nov 3, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@monosans
Copy link
Contributor

monosans commented Nov 3, 2022

Bug report

What's wrong

After updating to version 1.13.0, I'm getting a false positive when using mixins with DeleteView. Probably this commit is related to this bug.

from django.contrib.auth.models import User
from django.forms import ModelForm
from django.views.generic import DeleteView


class DummyMixin:
    pass


class CategoryDeleteView(  # Definition of "object" in base class "DeletionMixin" is incompatible with definition in base class "BaseDetailView"  [misc]
    DummyMixin, DeleteView[User, ModelForm[User]]
):
    model = User
    success_url = ""

System information

  • OS: Arch Linux
  • python version: 3.10.8
  • django version: 4.1.3
  • mypy version: 0.982
  • django-stubs version: 1.13.0
  • django-stubs-ext version: 0.7.0
@monosans monosans added the bug Something isn't working label Nov 3, 2022
@monosans monosans changed the title Definition of "object" in base class "DeletionMixin" is incompatible with definition in base class "BaseDetailView" False positive when using mixins with DeleteView Nov 3, 2022
@adamchainz
Copy link
Contributor

adamchainz commented Nov 11, 2022

Unfortunately I think this is a Mypy bug: python/mypy#9031

The object definition on BaseDeleteView actually shouldn’t be there, since it comes from DeletionMixin. If it’s removed, the error occurs without the mixin:

diff --git a/django-stubs/views/generic/edit.pyi b/django-stubs/views/generic/edit.pyi
index 1138df7..7dccd47 100644
--- a/django-stubs/views/generic/edit.pyi
+++ b/django-stubs/views/generic/edit.pyi
@@ -67,7 +67,7 @@ class DeletionMixin(Generic[_M]):
     def get_success_url(self) -> str: ...
 
 class BaseDeleteView(Generic[_M, _ModelFormT], DeletionMixin[_M], FormMixin[_ModelFormT], BaseDetailView[_M]):
-    object: _M
+    pass
 
 class DeleteView(Generic[_M, _ModelFormT], SingleObjectTemplateResponseMixin, BaseDeleteView[_M, _ModelFormT]):
     object: _M

As a workaround, you can redeclare object in your subclass:

 class CategoryDeleteView(DummyMixin, DeleteView[User, ModelForm[User]]):
+    object: User
     model = User

@adamchainz adamchainz reopened this Nov 11, 2022
Nebucatnetzer added a commit to Nebucatnetzer/network_inventory that referenced this issue Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants