Skip to content

Commit 05fd684

Browse files
committed
chores: Lint and format
1 parent 762719b commit 05fd684

File tree

18 files changed

+73
-60
lines changed

18 files changed

+73
-60
lines changed

supertokens_python/exceptions.py

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

1919
def raise_general_exception(
2020
msg: Union[str, Exception], previous: Union[None, Exception] = None
21-
):
21+
) -> NoReturn:
2222
if isinstance(msg, SuperTokensError):
2323
raise msg
2424
if isinstance(msg, Exception):

supertokens_python/recipe/dashboard/api/userdetails/user_password_put.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ async def reset_password(
9696
field for field in form_fields if field.id == FORM_FIELD_PASSWORD_ID
9797
][0]
9898

99-
password_validation_error = await password_form_field.validate(new_password)
99+
password_validation_error = await password_form_field.validate(
100+
new_password, tenant_id
101+
)
100102

101103
if password_validation_error is not None:
102104
return UserPasswordPutAPIInvalidPasswordErrorResponse(

supertokens_python/recipe/dashboard/api/userdetails/user_put.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@
5858

5959

6060
async def update_email_for_recipe_id(
61-
recipe_id: str, user_id: str, email: str, user_context: Dict[str, Any]
61+
recipe_id: str,
62+
user_id: str,
63+
email: str,
64+
tenant_id: str,
65+
user_context: Dict[str, Any],
6266
) -> Union[
6367
UserPutAPIOkResponse,
6468
UserPutAPIInvalidEmailErrorResponse,
@@ -76,7 +80,7 @@ async def update_email_for_recipe_id(
7680
if form_field.id == FORM_FIELD_EMAIL_ID
7781
]
7882

79-
validation_error = await email_form_fields[0].validate(email)
83+
validation_error = await email_form_fields[0].validate(email, tenant_id)
8084

8185
if validation_error is not None:
8286
return UserPutAPIInvalidEmailErrorResponse(validation_error)
@@ -102,7 +106,7 @@ async def update_email_for_recipe_id(
102106
if form_field.id == FORM_FIELD_EMAIL_ID
103107
]
104108

105-
validation_error = await email_form_fields[0].validate(email)
109+
validation_error = await email_form_fields[0].validate(email, tenant_id)
106110

107111
if validation_error is not None:
108112
return UserPutAPIInvalidEmailErrorResponse(validation_error)
@@ -127,12 +131,14 @@ async def update_email_for_recipe_id(
127131
passwordless_config = PasswordlessRecipe.get_instance().config.contact_config
128132

129133
if isinstance(passwordless_config.contact_method, ContactPhoneOnlyConfig):
130-
validation_error = await default_validate_email(email)
134+
validation_error = await default_validate_email(email, tenant_id)
131135

132136
elif isinstance(
133137
passwordless_config, (ContactEmailOnlyConfig, ContactEmailOrPhoneConfig)
134138
):
135-
validation_error = await passwordless_config.validate_email_address(email)
139+
validation_error = await passwordless_config.validate_email_address(
140+
email, tenant_id
141+
)
136142

137143
if validation_error is not None:
138144
return UserPutAPIInvalidEmailErrorResponse(validation_error)
@@ -157,11 +163,13 @@ async def update_email_for_recipe_id(
157163
)
158164

159165
if isinstance(passwordless_config, ContactPhoneOnlyConfig):
160-
validation_error = await default_validate_email(email)
166+
validation_error = await default_validate_email(email, tenant_id)
161167
elif isinstance(
162168
passwordless_config, (ContactEmailOnlyConfig, ContactEmailOrPhoneConfig)
163169
):
164-
validation_error = await passwordless_config.validate_email_address(email)
170+
validation_error = await passwordless_config.validate_email_address(
171+
email, tenant_id
172+
)
165173

166174
if validation_error is not None:
167175
return UserPutAPIInvalidEmailErrorResponse(validation_error)
@@ -183,7 +191,11 @@ async def update_email_for_recipe_id(
183191

184192

185193
async def update_phone_for_recipe_id(
186-
recipe_id: str, user_id: str, phone: str, user_context: Dict[str, Any]
194+
recipe_id: str,
195+
user_id: str,
196+
phone: str,
197+
tenant_id: str,
198+
user_context: Dict[str, Any],
187199
) -> Union[
188200
UserPutAPIOkResponse,
189201
UserPutAPIInvalidPhoneErrorResponse,
@@ -197,11 +209,13 @@ async def update_phone_for_recipe_id(
197209
passwordless_config = PasswordlessRecipe.get_instance().config.contact_config
198210

199211
if isinstance(passwordless_config, ContactEmailOnlyConfig):
200-
validation_error = await default_validate_phone_number(phone)
212+
validation_error = await default_validate_phone_number(phone, tenant_id)
201213
elif isinstance(
202214
passwordless_config, (ContactPhoneOnlyConfig, ContactEmailOrPhoneConfig)
203215
):
204-
validation_error = await passwordless_config.validate_phone_number(phone)
216+
validation_error = await passwordless_config.validate_phone_number(
217+
phone, tenant_id
218+
)
205219

206220
if validation_error is not None:
207221
return UserPutAPIInvalidPhoneErrorResponse(validation_error)
@@ -226,12 +240,14 @@ async def update_phone_for_recipe_id(
226240
)
227241

228242
if isinstance(passwordless_config, ContactEmailOnlyConfig):
229-
validation_error = await default_validate_phone_number(phone)
243+
validation_error = await default_validate_phone_number(phone, tenant_id)
230244

231245
elif isinstance(
232246
passwordless_config, (ContactPhoneOnlyConfig, ContactEmailOrPhoneConfig)
233247
):
234-
validation_error = await passwordless_config.validate_phone_number(phone)
248+
validation_error = await passwordless_config.validate_phone_number(
249+
phone, tenant_id
250+
)
235251

236252
if validation_error is not None:
237253
return UserPutAPIInvalidPhoneErrorResponse(validation_error)
@@ -254,7 +270,7 @@ async def update_phone_for_recipe_id(
254270

255271
async def handle_user_put(
256272
_api_interface: APIInterface,
257-
_tenant_id: str,
273+
tenant_id: str,
258274
api_options: APIOptions,
259275
user_context: Dict[str, Any],
260276
) -> Union[
@@ -337,15 +353,15 @@ async def handle_user_put(
337353

338354
if email != "":
339355
email_update_response = await update_email_for_recipe_id(
340-
user_response.recipe, user_id, email, user_context
356+
user_response.recipe, user_id, email, tenant_id, user_context
341357
)
342358

343359
if not isinstance(email_update_response, UserPutAPIOkResponse):
344360
return email_update_response
345361

346362
if phone != "":
347363
phone_update_response = await update_phone_for_recipe_id(
348-
user_response.recipe, user_id, phone, user_context
364+
user_response.recipe, user_id, phone, tenant_id, user_context
349365
)
350366

351367
if not isinstance(phone_update_response, UserPutAPIOkResponse):

supertokens_python/recipe/emailpassword/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
)
3939

4040

41-
async def default_validator(_: str) -> Union[str, None]:
41+
async def default_validator(_: str, __: str) -> Union[str, None]:
4242
return None
4343

4444

45-
async def default_password_validator(value: str) -> Union[str, None]:
45+
async def default_password_validator(_: str, value: str) -> Union[str, None]:
4646
# length >= 8 && < 100
4747
# must have a number and a character
4848
# as per
@@ -62,7 +62,7 @@ async def default_password_validator(value: str) -> Union[str, None]:
6262
return None
6363

6464

65-
async def default_email_validator(value: Any) -> Union[str, None]:
65+
async def default_email_validator(_: str, value: Any) -> Union[str, None]:
6666
# We check if the email syntax is correct
6767
# As per https://github.com/supertokens/supertokens-auth-react/issues/5#issuecomment-709512438
6868
# Regex from https://stackoverflow.com/a/46181/3867175

supertokens_python/recipe/emailverification/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
# under the License.
1414
from __future__ import annotations
1515

16-
from typing import TYPE_CHECKING, Callable, Union, Optional, Any, Awaitable, Dict
16+
from typing import TYPE_CHECKING, Callable, Union, Optional
1717

1818
from . import exceptions as ex
1919
from . import utils
2020
from .emaildelivery import services as emaildelivery_services
2121
from . import recipe
2222
from .interfaces import TypeGetEmailForUserIdFunction
2323
from .recipe import EmailVerificationRecipe
24-
from .types import EmailTemplateVars, User
24+
from .types import EmailTemplateVars
2525
from ...ingredients.emaildelivery.types import EmailDeliveryConfig
2626

2727
InputOverrideConfig = utils.OverrideConfig
@@ -42,15 +42,11 @@ def init(
4242
mode: MODE_TYPE,
4343
email_delivery: Union[EmailDeliveryConfig[EmailTemplateVars], None] = None,
4444
get_email_for_user_id: Optional[TypeGetEmailForUserIdFunction] = None,
45-
create_and_send_custom_email: Union[
46-
Callable[[User, str, Dict[str, Any]], Awaitable[None]], None
47-
] = None,
4845
override: Union[OverrideConfig, None] = None,
4946
) -> Callable[[AppInfo], RecipeModule]:
5047
return EmailVerificationRecipe.init(
5148
mode,
5249
email_delivery,
5350
get_email_for_user_id,
54-
create_and_send_custom_email,
5551
override,
5652
)

supertokens_python/recipe/emailverification/recipe.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import annotations
1515

1616
from os import environ
17-
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, List, Optional, Union
17+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
1818

1919
from supertokens_python.exceptions import SuperTokensError, raise_general_exception
2020
from supertokens_python.ingredients.emaildelivery import EmailDeliveryIngredient
@@ -24,7 +24,6 @@
2424
from supertokens_python.recipe.emailverification.types import (
2525
EmailTemplateVars,
2626
EmailVerificationIngredients,
27-
User,
2827
VerificationEmailTemplateVars,
2928
VerificationEmailTemplateVarsUser,
3029
)
@@ -206,7 +205,7 @@ def init(
206205
get_email_for_user_id: Optional[TypeGetEmailForUserIdFunction] = None,
207206
override: Union[OverrideConfig, None] = None,
208207
):
209-
def func(app_info: AppInfo):
208+
def func(app_info: AppInfo) -> EmailVerificationRecipe:
210209
if EmailVerificationRecipe.__instance is None:
211210
ingredients = EmailVerificationIngredients(email_delivery=None)
212211
EmailVerificationRecipe.__instance = EmailVerificationRecipe(
@@ -231,7 +230,7 @@ def callback():
231230
PostSTInitCallbacks.add_post_init_callback(callback)
232231

233232
return EmailVerificationRecipe.__instance
234-
raise_general_exception(
233+
return raise_general_exception(
235234
"Emailverification recipe has already been initialised. Please check your code for bugs."
236235
)
237236

supertokens_python/recipe/emailverification/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import TYPE_CHECKING, Any, Dict, Optional
17+
from typing import TYPE_CHECKING, Optional
1818

1919
from supertokens_python.ingredients.emaildelivery.types import (
2020
EmailDeliveryConfig,
@@ -23,16 +23,15 @@
2323
from supertokens_python.recipe.emailverification.emaildelivery.services.backward_compatibility import (
2424
BackwardCompatibilityService,
2525
)
26-
from supertokens_python.utils import deprecated_warn
2726
from typing_extensions import Literal
2827

2928
if TYPE_CHECKING:
30-
from typing import Awaitable, Callable, Union
29+
from typing import Callable, Union
3130

3231
from supertokens_python.supertokens import AppInfo
3332

3433
from .interfaces import APIInterface, RecipeInterface, TypeGetEmailForUserIdFunction
35-
from .types import EmailTemplateVars, User, VerificationEmailTemplateVars
34+
from .types import EmailTemplateVars, VerificationEmailTemplateVars
3635

3736

3837
class OverrideConfig:

supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/__init__.py

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

1515
import json
1616
from os import environ
17-
from typing import Any, Awaitable, Callable, Dict, Union
17+
from typing import Any, Dict
1818

1919
from httpx import AsyncClient, HTTPStatusError, Response
2020
from supertokens_python.ingredients.smsdelivery.services.supertokens import (

supertokens_python/recipe/passwordless/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
)
5050

5151

52-
async def default_validate_phone_number(value: str, tenant_id: str):
52+
async def default_validate_phone_number(value: str, _tenant_id: str):
5353
try:
5454
parsed_phone_number: Any = parse(value, None)
5555
if not is_valid_number(parsed_phone_number):

supertokens_python/recipe/thirdparty/providers/custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def _normalize_input(self):
199199
if self.input_config.generate_fake_email is None:
200200

201201
async def default_generate_fake_email(
202-
third_party_user_id: str, _: Dict[str, Any]
202+
_tenant_id: str, third_party_user_id: str, _: Dict[str, Any]
203203
) -> str:
204204
return f"{third_party_user_id}@{self.input_config.third_party_id}.fakeemail.com"
205205

0 commit comments

Comments
 (0)