Merge pull request #5231 from cookiecutter/pyup-update-mypy-1.10.0-to-1.11.0

Update mypy to 1.11.0
This commit is contained in:
Bruno Alla 2024-07-31 15:11:25 +01:00 committed by GitHub
commit 5a61a0c828
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 8 deletions

View File

@ -13,12 +13,12 @@ watchfiles==0.21.0 # https://github.com/samuelcolvin/watchfiles
# Testing # Testing
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
mypy==1.10.0 # https://github.com/python/mypy mypy==1.11.0 # https://github.com/python/mypy
django-stubs[compatible-mypy]==5.0.2 # https://github.com/typeddjango/django-stubs django-stubs[compatible-mypy]==5.0.4 # https://github.com/typeddjango/django-stubs
pytest==8.3.2 # https://github.com/pytest-dev/pytest pytest==8.3.2 # https://github.com/pytest-dev/pytest
pytest-sugar==1.0.0 # https://github.com/Frozenball/pytest-sugar pytest-sugar==1.0.0 # https://github.com/Frozenball/pytest-sugar
{%- if cookiecutter.use_drf == "y" %} {%- if cookiecutter.use_drf == "y" %}
djangorestframework-stubs[compatible-mypy]==3.15.0 # https://github.com/typeddjango/djangorestframework-stubs djangorestframework-stubs==3.15.0 # https://github.com/typeddjango/djangorestframework-stubs
{%- endif %} {%- endif %}
# Documentation # Documentation

View File

@ -1,5 +1,6 @@
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.db.models import QuerySet
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView from django.views.generic import DetailView
@ -28,12 +29,12 @@ class UserUpdateView(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
fields = ["name"] fields = ["name"]
success_message = _("Information successfully updated") success_message = _("Information successfully updated")
def get_success_url(self): def get_success_url(self) -> str:
# for mypy to know that the user is authenticated assert self.request.user.is_authenticated # type guard
assert self.request.user.is_authenticated
return self.request.user.get_absolute_url() return self.request.user.get_absolute_url()
def get_object(self): def get_object(self, queryset: QuerySet | None=None) -> User:
assert self.request.user.is_authenticated # type guard
return self.request.user return self.request.user
@ -43,7 +44,7 @@ user_update_view = UserUpdateView.as_view()
class UserRedirectView(LoginRequiredMixin, RedirectView): class UserRedirectView(LoginRequiredMixin, RedirectView):
permanent = False permanent = False
def get_redirect_url(self): def get_redirect_url(self) -> str:
{%- if cookiecutter.username_type == "email" %} {%- if cookiecutter.username_type == "email" %}
return reverse("users:detail", kwargs={"pk": self.request.user.pk}) return reverse("users:detail", kwargs={"pk": self.request.user.pk})
{%- else %} {%- else %}