From b077982b3eb4be9bb86d670221902442efb7ab31 Mon Sep 17 00:00:00 2001 From: Thibaut Decombe Date: Sun, 13 Jul 2025 20:01:02 +0200 Subject: [PATCH] [6.0.x] Refs #31223 -- Added __class_getitem__() to SetPasswordMixin. Backport of d0c8f89c942d1379724bdd37127076d13452f71d from main. --- django/contrib/auth/forms.py | 3 +++ tests/auth_tests/test_forms.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 2214e134d0..aff0cca342 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -134,6 +134,9 @@ class SetPasswordMixin: user.save() return user + def __class_getitem__(cls, *args, **kwargs): + return cls + class SetUnusablePasswordMixin: """ diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index be55c4369b..73065adddf 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -350,6 +350,9 @@ class BaseUserCreationFormTest(TestDataMixin, TestCase): form.fields[field_name].widget.attrs["autocomplete"], autocomplete ) + def test_user_creation_form_class_getitem(self): + self.assertIs(BaseUserCreationForm["MyCustomUser"], BaseUserCreationForm) + class CustomUserCreationFormTest(TestDataMixin, TestCase):