From 035a9e6983ec415df6d5458865394f8734a529be Mon Sep 17 00:00:00 2001 From: Thibaut Decombe Date: Sun, 13 Jul 2025 20:01:02 +0200 Subject: [PATCH] Refs #31223 -- Added __class_getitem__() to SetPasswordMixin and SetUnusablePasswordMixin --- django/contrib/auth/forms.py | 6 ++++++ tests/auth_tests/test_forms.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 2214e134d092..6017e2454378 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -134,6 +134,9 @@ def set_password_and_save(self, user, password_field_name="password1", commit=Tr user.save() return user + def __class_getitem__(cls, *args, **kwargs): + return cls + class SetUnusablePasswordMixin: """ @@ -206,6 +209,9 @@ def set_password_and_save(self, user, commit=True, **kwargs): user.save() return user + def __class_getitem__(cls, *args, **kwargs): + return cls + class BaseUserCreationForm(SetPasswordMixin, forms.ModelForm): """ diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index df91f100f562..32aefb2ae1bc 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -16,6 +16,7 @@ ReadOnlyPasswordHashWidget, SetPasswordForm, SetPasswordMixin, + SetUnusablePasswordMixin, UserChangeForm, UserCreationForm, UsernameField, @@ -1761,3 +1762,12 @@ def test_passwords_marked_as_sensitive_in_admin_forms(self): self.assertContains( response, password2_fragment, html=True, status_code=500 ) + + +class GenericAuthFormTest(TestCase): + + def test_password_mixin_getitem(self): + self.assertIs(SetPasswordMixin["MyCustomUser"], SetPasswordMixin) + self.assertIs( + SetUnusablePasswordMixin["MyCustomUser"], SetUnusablePasswordMixin + )