diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 9c7b7aa2b..25221429c 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -78,7 +78,7 @@ class _FieldOpts(_OptionalFieldOpts, total=True): # Workaround for mypy issue, a Sequence type should be preferred here. # https://github.com/python/mypy/issues/8921 # _FieldsetSpec = Sequence[Tuple[Optional[str], _FieldOpts]] -_FieldsetSpec = _ListOrTuple[Tuple[Optional[str], _FieldOpts]] +_FieldsetSpec = _ListOrTuple[Tuple[Optional[_StrOrPromise], _FieldOpts]] _ListFilterT = Union[ Type[ListFilter], Field, diff --git a/django-stubs/contrib/auth/mixins.pyi b/django-stubs/contrib/auth/mixins.pyi index 1eff8e102..60f7c1441 100644 --- a/django-stubs/contrib/auth/mixins.pyi +++ b/django-stubs/contrib/auth/mixins.pyi @@ -2,14 +2,15 @@ from typing import Any, Callable, Optional, Sequence from django import http from django.http.response import HttpResponseBase, HttpResponseRedirect +from django.utils.functional import _StrOrPromise class AccessMixin: login_url: Any = ... - permission_denied_message: str = ... + permission_denied_message: _StrOrPromise = ... raise_exception: bool = ... redirect_field_name: Any = ... def get_login_url(self) -> str: ... - def get_permission_denied_message(self) -> str: ... + def get_permission_denied_message(self) -> _StrOrPromise: ... def get_redirect_field_name(self) -> str: ... def handle_no_permission(self) -> HttpResponseRedirect: ... diff --git a/django-stubs/contrib/messages/views.pyi b/django-stubs/contrib/messages/views.pyi index 344a9654b..c22c640bc 100644 --- a/django-stubs/contrib/messages/views.pyi +++ b/django-stubs/contrib/messages/views.pyi @@ -2,8 +2,9 @@ from typing import Dict from django.forms.forms import BaseForm from django.http.response import HttpResponse +from django.utils.functional import _StrOrPromise class SuccessMessageMixin: - success_message: str = ... + success_message: _StrOrPromise = ... def form_valid(self, form: BaseForm) -> HttpResponse: ... - def get_success_message(self, cleaned_data: Dict[str, str]) -> str: ... + def get_success_message(self, cleaned_data: Dict[str, str]) -> _StrOrPromise: ... diff --git a/tests/typecheck/contrib/admin/test_options.yml b/tests/typecheck/contrib/admin/test_options.yml index 7e77e73a0..02989e811 100644 --- a/tests/typecheck/contrib/admin/test_options.yml +++ b/tests/typecheck/contrib/admin/test_options.yml @@ -10,6 +10,7 @@ from django.db.models.options import Options from django.http.request import HttpRequest from django.db.models.query import QuerySet + from django.utils.translation import gettext_lazy as _ def an_action(modeladmin: admin.ModelAdmin, request: HttpRequest, queryset: QuerySet) -> None: pass @@ -29,6 +30,7 @@ fieldsets = [ (None, {"fields": ["a", "b"]}), ("group", {"fields": ("c",), "classes": ("a",), "description": "foo"}), + (_("lazy"), {"fields": ["bar"]}) ] form = ModelForm filter_vertical = ("fields",)