11from __future__ import annotations
22
3- from typing import TYPE_CHECKING
3+ from typing import TYPE_CHECKING , cast
44
55from social_core .exceptions import AuthAlreadyAssociated , AuthException , AuthForbidden
66
77if TYPE_CHECKING :
88 from social_core .backends .base import BaseAuth
9- from social_core .storage import UserProtocol
9+ from social_core .storage import BaseStorage , UserProtocol
1010
1111
1212def social_details (backend : BaseAuth , details , response , * args , ** kwargs ):
@@ -26,7 +26,9 @@ def social_user(
2626 backend : BaseAuth , uid , user : UserProtocol | None = None , * args , ** kwargs
2727):
2828 provider = backend .name
29- social = backend .strategy .storage .user .get_social_auth (provider , uid )
29+ social = cast ("type[BaseStorage]" , backend .strategy .storage ).user .get_social_auth (
30+ provider , uid
31+ )
3032 if social :
3133 if user and social .user != user :
3234 raise AuthAlreadyAssociated (backend )
@@ -50,11 +52,13 @@ def associate_user(
5052):
5153 if user and not social :
5254 try :
53- social = backend . strategy . storage . user . create_social_auth (
54- user , uid , backend .name
55- )
55+ social = cast (
56+ "type[BaseStorage]" , backend .strategy . storage
57+ ). user . create_social_auth ( user , uid , backend . name )
5658 except Exception as err :
57- if not backend .strategy .storage .is_integrity_error (err ):
59+ if not cast (
60+ "type[BaseStorage]" , backend .strategy .storage
61+ ).is_integrity_error (err ):
5862 raise
5963 # Protect for possible race condition, those bastard with FTL
6064 # clicking capabilities, check issue #131:
@@ -91,7 +95,11 @@ def associate_by_email(
9195 # Try to associate accounts registered with the same email address,
9296 # only if it's a single object. AuthException is raised if multiple
9397 # objects are returned.
94- users = list (backend .strategy .storage .user .get_users_by_email (email ))
98+ users = list (
99+ cast ("type[BaseStorage]" , backend .strategy .storage ).user .get_users_by_email (
100+ email
101+ )
102+ )
95103 if len (users ) == 0 :
96104 return None
97105 if len (users ) > 1 :
@@ -111,9 +119,9 @@ def load_extra_data(
111119 * args ,
112120 ** kwargs ,
113121) -> None :
114- social = kwargs .get ("social" ) or backend . strategy . storage . user . get_social_auth (
115- backend . name , uid
116- )
122+ social = kwargs .get ("social" ) or cast (
123+ "type[BaseStorage]" , backend . strategy . storage
124+ ). user . get_social_auth ( backend . name , uid )
117125 if social :
118126 extra_data = backend .extra_data (user , uid , response , details , kwargs )
119127 social .set_extra_data (extra_data )
0 commit comments