Chore(mypy): Annotate None returns for typing improvements (#11213)

This commit is contained in:
Sebastian Steinbeißer
2026-02-02 08:44:12 -08:00
committed by GitHub
parent a9c0b06e28
commit 3b5ffbf9fa
113 changed files with 1598 additions and 1510 deletions
+23 -19
View File
@@ -29,7 +29,7 @@ class MockOpenIDProvider:
# see allauth.socialaccount.providers.openid_connect.provider.OpenIDConnectProviderAccount
class MockOpenIDConnectProviderAccount:
def __init__(self, mock_social_account_dict):
def __init__(self, mock_social_account_dict) -> None:
self.account = mock_social_account_dict
def to_str(self):
@@ -41,7 +41,7 @@ class MockOpenIDConnectProvider:
id = "openid_connect"
name = "OpenID Connect"
def __init__(self, app=None):
def __init__(self, app=None) -> None:
self.app = app
self.name = app.name
@@ -52,7 +52,7 @@ class MockOpenIDConnectProvider:
class TestApiProfile(DirectoriesMixin, APITestCase):
ENDPOINT = "/api/profile/"
def setUp(self):
def setUp(self) -> None:
super().setUp()
self.user = User.objects.create_superuser(
@@ -62,7 +62,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
)
self.client.force_authenticate(user=self.user)
def setupSocialAccount(self):
def setupSocialAccount(self) -> None:
SocialApp.objects.create(
name="Keycloak",
provider="openid_connect",
@@ -73,7 +73,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
bulk=False,
)
def test_get_profile(self):
def test_get_profile(self) -> None:
"""
GIVEN:
- Configured user
@@ -96,7 +96,11 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
@mock.patch(
"allauth.socialaccount.adapter.DefaultSocialAccountAdapter.list_providers",
)
def test_get_profile_w_social(self, mock_list_providers, mock_get_provider_account):
def test_get_profile_w_social(
self,
mock_list_providers,
mock_get_provider_account,
) -> None:
"""
GIVEN:
- Configured user and setup social account
@@ -136,7 +140,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
],
)
def test_profile_w_social_removed_app(self):
def test_profile_w_social_removed_app(self) -> None:
"""
GIVEN:
- Configured user and setup social account
@@ -166,7 +170,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
],
)
def test_update_profile(self):
def test_update_profile(self) -> None:
"""
GIVEN:
- Configured user
@@ -192,7 +196,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
self.assertEqual(user.first_name, user_data["first_name"])
self.assertEqual(user.last_name, user_data["last_name"])
def test_update_profile_invalid_password_returns_field_error(self):
def test_update_profile_invalid_password_returns_field_error(self) -> None:
"""
GIVEN:
- Configured user
@@ -220,7 +224,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
),
)
def test_update_profile_placeholder_password_skips_validation(self):
def test_update_profile_placeholder_password_skips_validation(self) -> None:
"""
GIVEN:
- Configured user with existing password
@@ -251,7 +255,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
self.assertEqual(user.first_name, user_data["first_name"])
self.assertEqual(user.last_name, user_data["last_name"])
def test_update_auth_token(self):
def test_update_auth_token(self) -> None:
"""
GIVEN:
- Configured user
@@ -274,7 +278,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
self.assertNotEqual(token1.key, token2.key)
def test_profile_not_logged_in(self):
def test_profile_not_logged_in(self) -> None:
"""
GIVEN:
- User not logged in
@@ -298,7 +302,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
def test_get_social_account_providers(
self,
mock_list_providers,
):
) -> None:
"""
GIVEN:
- Configured user
@@ -333,7 +337,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
def test_get_social_account_providers_openid(
self,
mock_list_providers,
):
) -> None:
"""
GIVEN:
- Configured user and openid social account provider
@@ -355,7 +359,7 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
2,
)
def test_disconnect_social_account(self):
def test_disconnect_social_account(self) -> None:
"""
GIVEN:
- Configured user
@@ -394,13 +398,13 @@ class TestApiProfile(DirectoriesMixin, APITestCase):
class TestApiTOTPViews(APITestCase):
ENDPOINT = "/api/profile/totp/"
def setUp(self):
def setUp(self) -> None:
super().setUp()
self.user = User.objects.create_superuser(username="temp_admin")
self.client.force_authenticate(user=self.user)
def test_get_totp(self):
def test_get_totp(self) -> None:
"""
GIVEN:
- Existing user account
@@ -418,7 +422,7 @@ class TestApiTOTPViews(APITestCase):
self.assertIn("secret", response.data)
@mock.patch("allauth.mfa.totp.internal.auth.validate_totp_code")
def test_activate_totp(self, mock_validate_totp_code):
def test_activate_totp(self, mock_validate_totp_code) -> None:
"""
GIVEN:
- Existing user account
@@ -441,7 +445,7 @@ class TestApiTOTPViews(APITestCase):
self.assertTrue(Authenticator.objects.filter(user=self.user).exists())
self.assertIn("recovery_codes", response.data)
def test_deactivate_totp(self):
def test_deactivate_totp(self) -> None:
"""
GIVEN:
- Existing user account with TOTP enabled