Skip to content

Commit 08903a6

Browse files
committed
fix: Cyclic import error
1 parent 5022be9 commit 08903a6

File tree

9 files changed

+20
-39
lines changed

9 files changed

+20
-39
lines changed

supertokens_python/always_initialised_recipes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
from supertokens_python.recipe_module import RecipeModule
1919
from supertokens_python import AppInfo
2020

21-
DEFAULT_MULTITENANCY_RECIPE: Optional[Callable[[AppInfo], RecipeModule]] = None
21+
from supertokens_python.recipe.multitenancy import init
22+
23+
DEFAULT_MULTITENANCY_RECIPE: Optional[Callable[[AppInfo], RecipeModule]] = init()

supertokens_python/recipe/multitenancy/__init__.py

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

1616
from typing import TYPE_CHECKING, Callable, Union
17-
from supertokens_python import always_initialised_recipes
1817

1918
from . import exceptions as ex
2019
from . import recipe
@@ -42,6 +41,3 @@ def init(
4241
error_handlers,
4342
override,
4443
)
45-
46-
47-
always_initialised_recipes.DEFAULT_MULTITENANCY_RECIPE = init()

supertokens_python/recipe/openid/recipe.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from typing import TYPE_CHECKING, List, Union, Optional, Any, Dict
1818

1919
from supertokens_python.querier import Querier
20-
from supertokens_python.recipe.jwt import JWTRecipe
2120

2221
from .api.implementation import APIImplementation
2322
from .api.open_id_discovery_configuration_get import open_id_discovery_configuration_get
@@ -49,6 +48,8 @@ def __init__(
4948
issuer: Union[str, None] = None,
5049
override: Union[InputOverrideConfig, None] = None,
5150
):
51+
from supertokens_python.recipe.jwt import JWTRecipe
52+
5253
super().__init__(recipe_id, app_info)
5354
self.config = validate_and_normalise_user_input(app_info, issuer, override)
5455
jwt_feature = None

supertokens_python/recipe/session/recipe.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
UnauthorisedError,
2929
InvalidClaimsError,
3030
)
31-
from ... import AppInfo
3231
from ...types import MaybeAwaitable
3332

3433
if TYPE_CHECKING:

supertokens_python/recipe/session/session_request_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
TokenTransferMethod,
5252
get_required_claim_validators,
5353
)
54-
from supertokens_python.supertokens import AppInfo
5554
from supertokens_python.types import MaybeAwaitable
5655
from supertokens_python.utils import (
5756
FRAMEWORKS,
@@ -60,10 +59,11 @@
6059
normalise_http_method,
6160
set_request_in_user_context_if_not_defined,
6261
)
63-
from supertokens_python import Supertokens
62+
from supertokens_python.supertokens import Supertokens
6463

6564
if TYPE_CHECKING:
6665
from supertokens_python.recipe.session.recipe import SessionRecipe
66+
from supertokens_python.supertokens import AppInfo
6767

6868
LEGACY_ID_REFRESH_TOKEN_COOKIE_NAME = "sIdRefreshToken"
6969

supertokens_python/recipe/thirdparty/providers/custom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ def __init__(self, provider_config: ProviderConfig):
204204
)
205205
super().__init__(input_config.third_party_id, provider_config_for_client)
206206

207-
def _normalize_input(
208-
self, input_config: ProviderConfig # pylint: disable=no-self-use
207+
def _normalize_input( # pylint: disable=no-self-use
208+
self, input_config: ProviderConfig
209209
) -> ProviderConfig:
210210
if input_config.user_info_map is None:
211211
input_config.user_info_map = UserInfoMap(

supertokens_python/recipe_module.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
from .exceptions import SuperTokensError
3131
from .normalised_url_path import NormalisedURLPath
3232

33-
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe
34-
3533

3634
class ApiIdWithTenantId:
3735
def __init__(self, api_id: str, tenant_id: str):
@@ -54,6 +52,7 @@ async def return_api_id_if_can_handle_request(
5452
self, path: NormalisedURLPath, method: str, user_context: Dict[str, Any]
5553
) -> Union[ApiIdWithTenantId, None]:
5654
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
55+
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe
5756

5857
apis_handled = self.get_apis_handled()
5958

supertokens_python/supertokens.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
send_non_200_response_with_message,
4747
)
4848

49-
from .always_initialised_recipes import DEFAULT_MULTITENANCY_RECIPE
50-
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
5149

5250
if TYPE_CHECKING:
5351
from .recipe_module import RecipeModule
@@ -154,6 +152,8 @@ def __init__(
154152
mode: Union[Literal["asgi", "wsgi"], None],
155153
telemetry: Union[bool, None],
156154
):
155+
from .always_initialised_recipes import DEFAULT_MULTITENANCY_RECIPE
156+
157157
if not isinstance(app_info, InputAppInfo): # type: ignore
158158
raise ValueError("app_info must be an instance of InputAppInfo")
159159

@@ -189,17 +189,18 @@ def __init__(
189189
"Please provide at least one recipe to the supertokens.init function call"
190190
)
191191

192-
multitenancy_found = [False]
192+
multitenancy_found = False
193193

194194
def make_recipe(recipe: Callable[[AppInfo], RecipeModule]) -> RecipeModule:
195+
nonlocal multitenancy_found
195196
recipe_module = recipe(self.app_info)
196197
if recipe_module.get_recipe_id() == "multitenancy":
197-
multitenancy_found[0] = True
198+
multitenancy_found = True
198199
return recipe_module
199200

200201
self.recipe_modules: List[RecipeModule] = list(map(make_recipe, recipe_list))
201202

202-
if callable(DEFAULT_MULTITENANCY_RECIPE) and not multitenancy_found[0]:
203+
if callable(DEFAULT_MULTITENANCY_RECIPE) and not multitenancy_found:
203204
recipe = DEFAULT_MULTITENANCY_RECIPE( # pylint: disable=not-callable
204205
self.app_info
205206
)
@@ -259,6 +260,8 @@ async def get_user_count( # pylint: disable=no-self-use
259260
include_recipe_ids: Union[None, List[str]],
260261
tenant_id: Optional[str] = None,
261262
) -> int:
263+
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
264+
262265
querier = Querier.get_instance(None)
263266
include_recipe_ids_str = None
264267
if include_recipe_ids is not None:
@@ -296,6 +299,8 @@ async def get_users( # pylint: disable=no-self-use
296299
query: Union[Dict[str, str], None] = None,
297300
tenant_id: Optional[str] = None,
298301
) -> UsersResponse:
302+
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
303+
299304
querier = Querier.get_instance(None)
300305
params = {"timeJoinedOrder": time_joined_order}
301306
if limit is not None:

tests/input_validation/test_input_validation.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -434,27 +434,6 @@ async def test_init_validation_thirdpartyemailpassword():
434434
)
435435
assert "sign_up_feature must be of type InputSignUpFeature or None" == str(ex.value)
436436

437-
with pytest.raises(ValueError) as ex:
438-
init(
439-
supertokens_config=SupertokensConfig("http://localhost:3567"),
440-
app_info=InputAppInfo(
441-
app_name="SuperTokens Demo",
442-
api_domain="http://api.supertokens.io",
443-
website_domain="http://supertokens.io",
444-
api_base_path="/auth",
445-
),
446-
framework="fastapi",
447-
recipe_list=[
448-
thirdpartyemailpassword.init(
449-
reset_password_using_token_feature="reset password" # type: ignore
450-
)
451-
],
452-
)
453-
assert (
454-
"reset_password_using_token_feature must be of type InputResetPasswordUsingTokenFeature or None"
455-
== str(ex.value)
456-
)
457-
458437
with pytest.raises(ValueError) as ex:
459438
init(
460439
supertokens_config=SupertokensConfig("http://localhost:3567"),

0 commit comments

Comments
 (0)