Skip to content

Commit 4e0d6a0

Browse files
committed
fix: Types and linter errors
1 parent 29e5023 commit 4e0d6a0

20 files changed

+90
-71
lines changed

supertokens_python/always_initialised_recipes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
from __future__ import annotations
15-
from typing import Any, Callable, Union
15+
from typing import Callable, Optional, TYPE_CHECKING
1616

17+
if TYPE_CHECKING:
18+
from supertokens_python.recipe_module import RecipeModule
19+
from supertokens_python import AppInfo
1720

18-
DEFAULT_MULTITENANCY_RECIPE: Union[Callable[[Any], Any], None] = None
21+
DEFAULT_MULTITENANCY_RECIPE: Optional[Callable[[AppInfo], RecipeModule]] = None

supertokens_python/recipe/multitenancy/interfaces.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ def __init__(
175175

176176

177177
class ThirdPartyProvider:
178-
def __init__(self, id: str, name: Optional[str]):
178+
def __init__(
179+
self, id: str, name: Optional[str]
180+
): # pylint: disable=redefined-builtin
179181
self.id = id
180182
self.name = name
181183

supertokens_python/recipe/multitenancy/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ async def login_methods_get(
255255

256256
class AllowedDomainsClaimClass(PrimitiveArrayClaim[List[str]]):
257257
def __init__(self):
258-
async def fetch_value(user_id: str, user_context: Dict[str, Any]) -> List[str]:
258+
async def fetch_value(_user_id: str, user_context: Dict[str, Any]) -> List[str]:
259259
recipe = MultitenancyRecipe.get_instance()
260260
tenant_id = (
261261
None # TODO fetch value will be passed with tenant_id as well later

supertokens_python/recipe/thirdparty/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
from . import exceptions as ex
21-
from . import utils, provider
21+
from . import utils, provider, providers
2222
from .recipe import ThirdPartyRecipe
2323

2424
InputOverrideConfig = utils.InputOverrideConfig

supertokens_python/recipe/thirdparty/provider.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,43 +41,43 @@ def __init__(
4141

4242

4343
class Provider:
44-
def __init__(self, id: str):
44+
def __init__(self, id: str): # pylint: disable=redefined-builtin
4545
self.id = id
4646
self.config = ProviderConfigForClientType("temp")
4747

48-
async def get_config_for_client_type(
48+
async def get_config_for_client_type( # pylint: disable=no-self-use
4949
self, client_type: Optional[str], user_context: Dict[str, Any]
5050
) -> ProviderConfigForClientType:
5151
_ = client_type
5252
__ = user_context
53-
raise NotImplementedError
53+
raise NotImplementedError()
5454

55-
async def get_authorisation_redirect_url(
55+
async def get_authorisation_redirect_url( # pylint: disable=no-self-use
5656
self,
5757
redirect_uri_on_provider_dashboard: str,
5858
user_context: Dict[str, Any],
5959
) -> AuthorisationRedirect:
6060
_ = redirect_uri_on_provider_dashboard
6161
__ = user_context
62-
raise NotImplementedError
62+
raise NotImplementedError()
6363

64-
async def exchange_auth_code_for_oauth_tokens(
64+
async def exchange_auth_code_for_oauth_tokens( # pylint: disable=no-self-use
6565
self,
6666
redirect_uri_info: RedirectUriInfo,
6767
user_context: Dict[str, Any],
6868
) -> Dict[str, Any]:
6969
_ = redirect_uri_info
7070
__ = user_context
71-
raise NotImplementedError
71+
raise NotImplementedError()
7272

73-
async def get_user_info(
73+
async def get_user_info( # pylint: disable=no-self-use
7474
self,
7575
oauth_tokens: Dict[str, Any],
7676
user_context: Dict[str, Any],
7777
) -> UserInfo:
7878
_ = oauth_tokens
7979
__ = user_context
80-
raise NotImplementedError
80+
raise NotImplementedError()
8181

8282

8383
class ProviderClientConfig:

supertokens_python/recipe/thirdparty/providers/active_directory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ async def get_config_for_client_type(
4848
return config
4949

5050

51-
def ActiveDirectory(input: ProviderInput) -> Provider:
51+
def ActiveDirectory(
52+
input: ProviderInput, # pylint: disable=redefined-builtin
53+
) -> Provider:
5254
if input.config.name is None:
5355
input.config.name = "Active Directory"
5456

supertokens_python/recipe/thirdparty/providers/bitbucket.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(
4040
] = None,
4141
is_default: bool = False,
4242
):
43-
super().__init__("bitbucket", is_default)
43+
super().__init__("bitbucket") # FIXME: Where should is_default go?
4444
self.client_id = client_id
4545
self.client_secret = client_secret
4646
self.scopes = ["account", "email"] if scope is None else list(set(scope))
@@ -50,8 +50,8 @@ def __init__(
5050
if authorisation_redirect is not None:
5151
self.authorisation_redirect_params = authorisation_redirect
5252

53-
async def get_profile_info(
54-
self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]
53+
async def get_profile_info( # pylint: disable=no-self-use
54+
self, auth_code_response: Dict[str, Any], _user_context: Dict[str, Any]
5555
) -> UserInfo:
5656
access_token: str = auth_code_response["access_token"]
5757
headers = {"Authorization": f"Bearer {access_token}"}
@@ -80,7 +80,7 @@ async def get_profile_info(
8080
return UserInfo(user_id, UserInfoEmail(email, is_verified))
8181

8282
def get_authorisation_redirect_api_info(
83-
self, user_context: Dict[str, Any]
83+
self, _user_context: Dict[str, Any]
8484
) -> AuthorisationRedirectAPI:
8585
params = {
8686
"scope": " ".join(self.scopes),
@@ -95,7 +95,7 @@ def get_access_token_api_info(
9595
self,
9696
redirect_uri: str,
9797
auth_code_from_request: str,
98-
user_context: Dict[str, Any],
98+
_user_context: Dict[str, Any],
9999
) -> AccessTokenAPI:
100100
params = {
101101
"client_id": self.client_id,
@@ -106,8 +106,10 @@ def get_access_token_api_info(
106106
}
107107
return AccessTokenAPI(self.access_token_api_url, params)
108108

109-
def get_redirect_uri(self, user_context: Dict[str, Any]) -> Union[None, str]:
109+
def get_redirect_uri( # pylint: disable=no-self-use
110+
self, _user_context: Dict[str, Any]
111+
) -> Union[None, str]:
110112
return None
111113

112-
def get_client_id(self, user_context: Dict[str, Any]) -> str:
114+
def get_client_id(self, _user_context: Dict[str, Any]) -> str:
113115
return self.client_id

supertokens_python/recipe/thirdparty/providers/boxy_saml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def get_config_for_client_type(
4949
return config
5050

5151

52-
def BoxySAML(input: ProviderInput) -> Provider:
52+
def BoxySAML(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
5353
if input.config.name is None:
5454
input.config.name = "Boxy SAML"
5555

supertokens_python/recipe/thirdparty/providers/custom.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ async def verify_id_token_from_jwks_endpoint_and_get_payload(
160160
raise err
161161

162162

163+
def merge_into_dict(src: Dict[str, Any], dest: Dict[str, Any]) -> Dict[str, Any]:
164+
res = dest.copy()
165+
for k, v in src.items():
166+
if v is None:
167+
if k in res:
168+
del res[k]
169+
else:
170+
res[k] = v
171+
172+
return res
173+
174+
163175
class GenericProvider(Provider):
164176
def __init__(self, config: ProviderConfig):
165177
super().__init__(config.third_party_id)
@@ -288,12 +300,7 @@ async def exchange_auth_code_for_oauth_tokens(
288300
access_token_params["code_verifier"] = redirect_uri_info.pkce_code_verifier
289301

290302
if self.config.token_endpoint_body_params is not None:
291-
for k, v in self.config.token_endpoint_body_params:
292-
if v is None:
293-
if k in access_token_params:
294-
del access_token_params[k]
295-
else:
296-
access_token_params[k] = v
303+
access_token_params = merge_into_dict(self.config.token_endpoint_body_params, access_token_params)
297304

298305
# Transformation needed for dev keys BEGIN
299306
if is_using_oauth_development_client_id(self.config.client_id):
@@ -336,20 +343,10 @@ async def get_user_info(
336343

337344
if self.config.user_info_endpoint is not None:
338345
if self.config.user_info_endpoint_headers is not None:
339-
for k, v in self.config.user_info_endpoint_headers.items():
340-
if v is None:
341-
if k in headers:
342-
del headers[k]
343-
else:
344-
headers[k] = v
346+
headers = merge_into_dict(self.config.user_info_endpoint_headers, headers)
345347

346348
if self.config.user_info_endpoint_query_params is not None:
347-
for k, v in self.config.user_info_endpoint_query_params.items():
348-
if v is None:
349-
if k in query_params:
350-
del query_params[k]
351-
else:
352-
query_params[k] = v
349+
query_params = merge_into_dict(self.config.user_info_endpoint_query_params, query_params)
353350

354351
raw_user_info_from_provider.from_user_info_api = await do_get_request(
355352
self.config.user_info_endpoint, query_params, headers
@@ -367,7 +364,7 @@ async def get_user_info(
367364

368365

369366
def NewProvider(
370-
input: ProviderInput,
367+
input: ProviderInput, # pylint: disable=redefined-builtin
371368
base_class: Callable[[ProviderConfig], Provider] = GenericProvider,
372369
) -> Provider:
373370
provider_instance = base_class(input.config)

supertokens_python/recipe/thirdparty/providers/discord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def get_config_for_client_type(
4040
return config
4141

4242

43-
def Discord(input: ProviderInput) -> Provider:
43+
def Discord(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
4444
if input.config.name is None:
4545
input.config.name = "Discord"
4646

supertokens_python/recipe/thirdparty/providers/facebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def get_user_info(
5353
return await super().get_user_info(oauth_tokens, user_context)
5454

5555

56-
def Facebook(input: ProviderInput) -> Provider:
56+
def Facebook(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
5757
if input.config.name is None:
5858
input.config.name = "Facebook"
5959

supertokens_python/recipe/thirdparty/providers/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def get_user_info(
6161
return result
6262

6363

64-
def Github(input: ProviderInput) -> Provider:
64+
def Github(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
6565
if input.config.name is None:
6666
input.config.name = "Github"
6767

supertokens_python/recipe/thirdparty/providers/gitlab.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(
4343
gitlab_base_url: str = "https://gitlab.com",
4444
is_default: bool = False,
4545
):
46-
super().__init__("gitlab", is_default)
46+
super().__init__("gitlab") # FIXME: Where should is_default go?
4747
default_scopes = ["read_user"]
4848
if scope is None:
4949
scope = default_scopes
@@ -59,7 +59,7 @@ def __init__(
5959
self.authorisation_redirect_params = authorisation_redirect
6060

6161
async def get_profile_info(
62-
self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]
62+
self, auth_code_response: Dict[str, Any], _user_context: Dict[str, Any]
6363
) -> UserInfo:
6464
access_token: str = auth_code_response["access_token"]
6565
headers = {"Authorization": f"Bearer {access_token}"}
@@ -74,7 +74,7 @@ async def get_profile_info(
7474
return UserInfo(user_id, UserInfoEmail(email, is_email_verified))
7575

7676
def get_authorisation_redirect_api_info(
77-
self, user_context: Dict[str, Any]
77+
self, _user_context: Dict[str, Any]
7878
) -> AuthorisationRedirectAPI:
7979
params = {
8080
"scope": " ".join(self.scopes),
@@ -88,7 +88,7 @@ def get_access_token_api_info(
8888
self,
8989
redirect_uri: str,
9090
auth_code_from_request: str,
91-
user_context: Dict[str, Any],
91+
_user_context: Dict[str, Any],
9292
) -> AccessTokenAPI:
9393
params = {
9494
"client_id": self.client_id,
@@ -99,8 +99,10 @@ def get_access_token_api_info(
9999
}
100100
return AccessTokenAPI(self.access_token_api_url, params)
101101

102-
def get_redirect_uri(self, user_context: Dict[str, Any]) -> Union[None, str]:
102+
def get_redirect_uri( # pylint: disable=no-self-use
103+
self, _user_context: Dict[str, Any]
104+
) -> Union[None, str]:
103105
return None
104106

105-
def get_client_id(self, user_context: Dict[str, Any]) -> str:
107+
def get_client_id(self, _user_context: Dict[str, Any]) -> str:
106108
return self.client_id

supertokens_python/recipe/thirdparty/providers/google.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def get_config_for_client_type(
4242

4343

4444
def Google(
45-
input: ProviderInput,
45+
input: ProviderInput, # pylint: disable=redefined-builtin
4646
base_class: Callable[[ProviderConfig], GoogleImpl] = GoogleImpl,
4747
) -> Provider:
4848
if input.config.name is None:

supertokens_python/recipe/thirdparty/providers/google_workspaces.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ async def get_config_for_client_type(
4040
return config
4141

4242

43-
def GoogleWorkspaces(input: ProviderInput) -> Provider:
43+
def GoogleWorkspaces(
44+
input: ProviderInput, # pylint: disable=redefined-builtin
45+
) -> Provider:
4446
if input.config.name is None:
4547
input.config.name = "Google Workspaces"
4648

@@ -49,7 +51,7 @@ def GoogleWorkspaces(input: ProviderInput) -> Provider:
4951
async def default_validate_id_token_payload(
5052
id_token_payload: Dict[str, Any],
5153
config: ProviderConfigForClientType,
52-
user_context: Dict[str, Any],
54+
_user_context: Dict[str, Any],
5355
):
5456
if (config.additional_config or {}).get("hd", "*") != "*":
5557
if (config.additional_config or {}).get("hd") != id_token_payload.get(

supertokens_python/recipe/thirdparty/providers/linkedin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def get_user_info(
8686
)
8787

8888

89-
def Linkedin(input: ProviderInput) -> Provider:
89+
def Linkedin(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
9090
if input.config.name is None:
9191
input.config.name = "Linkedin"
9292

supertokens_python/recipe/thirdparty/providers/okta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def get_config_for_client_type(
5050
return config
5151

5252

53-
def Okta(input: ProviderInput) -> Provider:
53+
def Okta(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
5454
if input.config.name is None:
5555
input.config.name = "Okta"
5656

0 commit comments

Comments
 (0)