Skip to content

Commit

Permalink
Make SuccessMessageMixin fully compatible with FormMixin (#86)
Browse files Browse the repository at this point in the history
This ensures that the order in which these mixins are included
into a derrived class does not matter and ends up more accurately
reflecting the return type of SuccessMessageMixin in the process
(its code doesn't appear to enforce that the returned response
is a redirect).

This provides a fix to a secondary aspect of
https://github.com/mkurnikov/django-stubs/issues/79.
  • Loading branch information
PeterJCLaw authored and mkurnikov committed Jul 2, 2019
1 parent db7b465 commit 861c665
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django-stubs/contrib/messages/views.pyi
@@ -1,9 +1,9 @@
from typing import Any, Dict, Optional

from django.forms.forms import BaseForm
from django.http.response import HttpResponseRedirect
from django.http.response import HttpResponse

class SuccessMessageMixin:
success_message: str = ...
def form_valid(self, form: BaseForm) -> HttpResponseRedirect: ...
def form_valid(self, form: BaseForm) -> HttpResponse: ...
def get_success_message(self, cleaned_data: Dict[str, str]) -> str: ...
10 changes: 10 additions & 0 deletions test-data/typecheck/messages.test
@@ -0,0 +1,10 @@
[CASE successmessagemixin_compatible_with_formmixin]
from django.views.generic.edit import FormMixin
from django.contrib.messages.views import SuccessMessageMixin

class FormFirstView(FormMixin, SuccessMessageMixin):
pass

class SuccessMessageFirstView(FormMixin, SuccessMessageMixin):
pass
[/CASE]

0 comments on commit 861c665

Please sign in to comment.