From 476d877b92127353086363a34c969452beff014d Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 27 Jun 2023 23:29:00 +0100 Subject: [PATCH] Add some type hints to the SocialAccountAdapter class --- .../users/adapters.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/adapters.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/adapters.py index ae3a4b617f..c5c824bda7 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/adapters.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/adapters.py @@ -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"):