Skip to content

Refs #31223 -- Added __class_getitem__() to SetPasswordMixin and UnusablePasswordMixin #19638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions django/contrib/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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):
"""
Expand Down
10 changes: 10 additions & 0 deletions tests/auth_tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ReadOnlyPasswordHashWidget,
SetPasswordForm,
SetPasswordMixin,
SetUnusablePasswordMixin,
UserChangeForm,
UserCreationForm,
UsernameField,
Expand Down Expand Up @@ -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
)