Add some type hints to the SocialAccountAdapter class

This commit is contained in:
Bruno Alla 2023-06-27 23:29:00 +01:00
parent 8e19164cf4
commit 476d877b92
No known key found for this signature in database

View File

@ -1,24 +1,31 @@
from typing import Any
from __future__ import annotations
import typing
from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from django.conf import settings
from django.http import HttpRequest
if typing.TYPE_CHECKING:
from allauth.socialaccount.models import SocialLogin
from {{cookiecutter.project_slug}}.users.models import User
class AccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request: HttpRequest):
def is_open_for_signup(self, request: HttpRequest) -> bool:
return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)
class SocialAccountAdapter(DefaultSocialAccountAdapter):
def is_open_for_signup(self, request: HttpRequest, sociallogin: Any):
def is_open_for_signup(self, request: HttpRequest, sociallogin: SocialLogin) -> bool:
return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)
def populate_user(self, request, sociallogin, data):
def populate_user(self, request: HttpRequest, sociallogin: SocialLogin, data: dict[str, typing.Any]) -> User:
"""
Populates user information from social provider info
See: https://django-allauth.readthedocs.io/en/latest/advanced.html?highlight=populate_user#creating-and-populating-user-instances
Populates user information from social provider info.
See: https://django-allauth.readthedocs.io/en/latest/advanced.html?#creating-and-populating-user-instances
"""
user = sociallogin.user
if name := data.get("name"):