From 861c6653fda9a65d8b2fdc8873ff0f5d0a03839d Mon Sep 17 00:00:00 2001 From: Peter Law Date: Tue, 2 Jul 2019 11:34:05 +0100 Subject: [PATCH] Make SuccessMessageMixin fully compatible with FormMixin (#86) 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. --- django-stubs/contrib/messages/views.pyi | 4 ++-- test-data/typecheck/messages.test | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test-data/typecheck/messages.test diff --git a/django-stubs/contrib/messages/views.pyi b/django-stubs/contrib/messages/views.pyi index ec624c15b..8f38ade61 100644 --- a/django-stubs/contrib/messages/views.pyi +++ b/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: ... diff --git a/test-data/typecheck/messages.test b/test-data/typecheck/messages.test new file mode 100644 index 000000000..9a3646140 --- /dev/null +++ b/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]