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 + )