Skip to content

Commit 476d877

Browse files
committed
Add some type hints to the SocialAccountAdapter class
1 parent 8e19164 commit 476d877

File tree

1 file changed

+13
-6
lines changed
  • {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users

1 file changed

+13
-6
lines changed

{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/adapters.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
from typing import Any
1+
from __future__ import annotations
2+
3+
import typing
24

35
from allauth.account.adapter import DefaultAccountAdapter
46
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
57
from django.conf import settings
68
from django.http import HttpRequest
79

10+
if typing.TYPE_CHECKING:
11+
from allauth.socialaccount.models import SocialLogin
12+
from {{cookiecutter.project_slug}}.users.models import User
13+
814

915
class AccountAdapter(DefaultAccountAdapter):
10-
def is_open_for_signup(self, request: HttpRequest):
16+
def is_open_for_signup(self, request: HttpRequest) -> bool:
1117
return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)
1218

1319

1420
class SocialAccountAdapter(DefaultSocialAccountAdapter):
15-
def is_open_for_signup(self, request: HttpRequest, sociallogin: Any):
21+
def is_open_for_signup(self, request: HttpRequest, sociallogin: SocialLogin) -> bool:
1622
return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)
1723

18-
def populate_user(self, request, sociallogin, data):
24+
def populate_user(self, request: HttpRequest, sociallogin: SocialLogin, data: dict[str, typing.Any]) -> User:
1925
"""
20-
Populates user information from social provider info
21-
See: https://django-allauth.readthedocs.io/en/latest/advanced.html?highlight=populate_user#creating-and-populating-user-instances
26+
Populates user information from social provider info.
27+
28+
See: https://django-allauth.readthedocs.io/en/latest/advanced.html?#creating-and-populating-user-instances
2229
"""
2330
user = sociallogin.user
2431
if name := data.get("name"):

0 commit comments

Comments
 (0)