diff --git a/supabase_auth/_async/gotrue_admin_api.py b/supabase_auth/_async/gotrue_admin_api.py index b9dd871f..54d48739 100644 --- a/supabase_auth/_async/gotrue_admin_api.py +++ b/supabase_auth/_async/gotrue_admin_api.py @@ -1,7 +1,7 @@ from __future__ import annotations from functools import partial -from typing import Dict, List, Optional, Union +from typing import Dict, List, Optional from ..helpers import model_validate, parse_link_response, parse_user_response from ..http_clients import AsyncClient @@ -28,7 +28,7 @@ def __init__( *, url: str = "", headers: Dict[str, str] = {}, - http_client: Union[AsyncClient, None] = None, + http_client: Optional[AsyncClient] = None, verify: bool = True, proxy: Optional[str] = None, ) -> None: diff --git a/supabase_auth/_async/gotrue_base_api.py b/supabase_auth/_async/gotrue_base_api.py index 7dfb22fb..21d0b444 100644 --- a/supabase_auth/_async/gotrue_base_api.py +++ b/supabase_auth/_async/gotrue_base_api.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, overload from httpx import Response from pydantic import BaseModel @@ -19,7 +19,7 @@ def __init__( *, url: str, headers: Dict[str, str], - http_client: Union[AsyncClient, None], + http_client: Optional[AsyncClient], verify: bool = True, proxy: Optional[str] = None, ): @@ -47,11 +47,11 @@ async def _request( method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"], path: str, *, - jwt: Union[str, None] = None, - redirect_to: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - query: Union[Dict[str, str], None] = None, - body: Union[Any, None] = None, + jwt: Optional[str] = None, + redirect_to: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + query: Optional[Dict[str, str]] = None, + body: Optional[Any] = None, no_resolve_json: Literal[False] = False, xform: Callable[[Any], T], ) -> T: ... # pragma: no cover @@ -62,11 +62,11 @@ async def _request( method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"], path: str, *, - jwt: Union[str, None] = None, - redirect_to: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - query: Union[Dict[str, str], None] = None, - body: Union[Any, None] = None, + jwt: Optional[str] = None, + redirect_to: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + query: Optional[Dict[str, str]] = None, + body: Optional[Any] = None, no_resolve_json: Literal[True], xform: Callable[[Response], T], ) -> T: ... # pragma: no cover @@ -77,11 +77,11 @@ async def _request( method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"], path: str, *, - jwt: Union[str, None] = None, - redirect_to: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - query: Union[Dict[str, str], None] = None, - body: Union[Any, None] = None, + jwt: Optional[str] = None, + redirect_to: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + query: Optional[Dict[str, str]] = None, + body: Optional[Any] = None, no_resolve_json: bool = False, ) -> None: ... # pragma: no cover @@ -90,14 +90,14 @@ async def _request( method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"], path: str, *, - jwt: Union[str, None] = None, - redirect_to: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - query: Union[Dict[str, str], None] = None, - body: Union[Any, None] = None, + jwt: Optional[str] = None, + redirect_to: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + query: Optional[Dict[str, str]] = None, + body: Optional[Any] = None, no_resolve_json: bool = False, - xform: Union[Callable[[Any], T], None] = None, - ) -> Union[T, None]: + xform: Optional[Callable[[Any], T]] = None, + ) -> Optional[T]: url = f"{self._url}/{path}" headers = {**self._headers, **(headers or {})} if API_VERSION_HEADER_NAME not in headers: diff --git a/supabase_auth/_async/gotrue_client.py b/supabase_auth/_async/gotrue_client.py index b4803c3f..041ac63b 100644 --- a/supabase_auth/_async/gotrue_client.py +++ b/supabase_auth/_async/gotrue_client.py @@ -4,7 +4,7 @@ from functools import partial from json import loads from time import time -from typing import Callable, Dict, List, Optional, Tuple, Union +from typing import Callable, Dict, List, Optional, Tuple from urllib.parse import parse_qs, urlencode, urlparse from uuid import uuid4 @@ -87,13 +87,13 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI): def __init__( self, *, - url: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - storage_key: Union[str, None] = None, + url: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + storage_key: Optional[str] = None, auto_refresh_token: bool = True, persist_session: bool = True, - storage: Union[AsyncSupportedStorage, None] = None, - http_client: Union[AsyncClient, None] = None, + storage: Optional[AsyncSupportedStorage] = None, + http_client: Optional[AsyncClient] = None, flow_type: AuthFlowType = "implicit", verify: bool = True, proxy: Optional[str] = None, @@ -110,8 +110,8 @@ def __init__( self._auto_refresh_token = auto_refresh_token self._persist_session = persist_session self._storage = storage or AsyncMemoryStorage() - self._in_memory_session: Union[Session, None] = None - self._refresh_token_timer: Union[Timer, None] = None + self._in_memory_session: Optional[Session] = None + self._refresh_token_timer: Optional[Timer] = None self._network_retries = 0 self._state_change_emitters: Dict[str, Subscription] = {} self._flow_type = flow_type @@ -134,7 +134,7 @@ def __init__( # Initializations - async def initialize(self, *, url: Union[str, None] = None) -> None: + async def initialize(self, *, url: Optional[str] = None) -> None: if url and self._is_implicit_grant_flow(url): await self.initialize_from_url(url) else: @@ -158,7 +158,7 @@ async def initialize_from_url(self, url: str) -> None: # Public methods async def sign_in_anonymously( - self, credentials: Union[SignInAnonymouslyCredentials, None] = None + self, credentials: Optional[SignInAnonymouslyCredentials] = None ) -> AuthResponse: """ Creates a new anonymous user. @@ -591,14 +591,14 @@ async def reauthenticate(self) -> AuthResponse: xform=parse_auth_response, ) - async def get_session(self) -> Union[Session, None]: + async def get_session(self) -> Optional[Session]: """ Returns the session, refreshing it if necessary. The session returned can be null if the session is not detected which can happen in the event a user is not signed-in or has logged out. """ - current_session: Union[Session, None] = None + current_session: Optional[Session] = None if self._persist_session: maybe_session = await self._storage.get_item(self._storage_key) current_session = self._get_valid_session(maybe_session) @@ -620,7 +620,7 @@ async def get_session(self) -> Union[Session, None]: else current_session ) - async def get_user(self, jwt: Union[str, None] = None) -> Union[UserResponse, None]: + async def get_user(self, jwt: Optional[str] = None) -> Optional[UserResponse]: """ Gets the current user details if there is an existing session. @@ -672,7 +672,7 @@ async def set_session(self, access_token: str, refresh_token: str) -> AuthRespon time_now = round(time()) expires_at = time_now has_expired = True - session: Union[Session, None] = None + session: Optional[Session] = None if access_token and access_token.split(".")[1]: payload = self._decode_jwt(access_token) exp = payload.get("exp") @@ -701,7 +701,7 @@ async def set_session(self, access_token: str, refresh_token: str) -> AuthRespon return AuthResponse(session=session, user=response.user) async def refresh_session( - self, refresh_token: Union[str, None] = None + self, refresh_token: Optional[str] = None ) -> AuthResponse: """ Returns a new session, regardless of expiry status. @@ -743,7 +743,7 @@ async def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None: def on_auth_state_change( self, - callback: Callable[[AuthChangeEvent, Union[Session, None]], None], + callback: Callable[[AuthChangeEvent, Optional[Session]], None], ) -> Subscription: """ Receive a notification every time an auth event happens. @@ -889,7 +889,7 @@ async def _get_authenticator_assurance_level( current_authentication_methods=[], ) payload = self._decode_jwt(session.access_token) - current_level: Union[AuthenticatorAssuranceLevels, None] = None + current_level: Optional[AuthenticatorAssuranceLevels] = None if payload.get("aal"): current_level = payload.get("aal") verified_factors = [ @@ -917,7 +917,7 @@ async def _remove_session(self) -> None: async def _get_session_from_url( self, url: str, - ) -> Tuple[Session, Union[str, None]]: + ) -> Tuple[Session, Optional[str]]: if not self._is_implicit_grant_flow(url): raise AuthImplicitGrantRedirectError("Not a valid implicit grant flow url.") result = urlparse(url) @@ -1062,15 +1062,15 @@ async def refresh_token_function(): def _notify_all_subscribers( self, event: AuthChangeEvent, - session: Union[Session, None], + session: Optional[Session], ) -> None: for subscription in self._state_change_emitters.values(): subscription.callback(event, session) def _get_valid_session( self, - raw_session: Union[str, None], - ) -> Union[Session, None]: + raw_session: Optional[str], + ) -> Optional[Session]: if not raw_session: return None data = loads(raw_session) @@ -1096,7 +1096,7 @@ def _get_param( self, query_params: Dict[str, List[str]], name: str, - ) -> Union[str, None]: + ) -> Optional[str]: return query_params[name][0] if name in query_params else None def _is_implicit_grant_flow(self, url: str) -> bool: diff --git a/supabase_auth/_sync/gotrue_admin_api.py b/supabase_auth/_sync/gotrue_admin_api.py index cedd4bb7..3997c53d 100644 --- a/supabase_auth/_sync/gotrue_admin_api.py +++ b/supabase_auth/_sync/gotrue_admin_api.py @@ -1,7 +1,7 @@ from __future__ import annotations from functools import partial -from typing import Dict, List, Optional, Union +from typing import Dict, List, Optional from ..helpers import model_validate, parse_link_response, parse_user_response from ..http_clients import SyncClient @@ -28,7 +28,7 @@ def __init__( *, url: str = "", headers: Dict[str, str] = {}, - http_client: Union[SyncClient, None] = None, + http_client: Optional[SyncClient] = None, verify: bool = True, proxy: Optional[str] = None, ) -> None: diff --git a/supabase_auth/_sync/gotrue_base_api.py b/supabase_auth/_sync/gotrue_base_api.py index 19448760..c6c2b7b0 100644 --- a/supabase_auth/_sync/gotrue_base_api.py +++ b/supabase_auth/_sync/gotrue_base_api.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, overload from httpx import Response from pydantic import BaseModel @@ -19,7 +19,7 @@ def __init__( *, url: str, headers: Dict[str, str], - http_client: Union[SyncClient, None], + http_client: Optional[SyncClient], verify: bool = True, proxy: Optional[str] = None, ): @@ -47,11 +47,11 @@ def _request( method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"], path: str, *, - jwt: Union[str, None] = None, - redirect_to: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - query: Union[Dict[str, str], None] = None, - body: Union[Any, None] = None, + jwt: Optional[str] = None, + redirect_to: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + query: Optional[Dict[str, str]] = None, + body: Optional[Any] = None, no_resolve_json: Literal[False] = False, xform: Callable[[Any], T], ) -> T: ... # pragma: no cover @@ -62,11 +62,11 @@ def _request( method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"], path: str, *, - jwt: Union[str, None] = None, - redirect_to: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - query: Union[Dict[str, str], None] = None, - body: Union[Any, None] = None, + jwt: Optional[str] = None, + redirect_to: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + query: Optional[Dict[str, str]] = None, + body: Optional[Any] = None, no_resolve_json: Literal[True], xform: Callable[[Response], T], ) -> T: ... # pragma: no cover @@ -77,11 +77,11 @@ def _request( method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"], path: str, *, - jwt: Union[str, None] = None, - redirect_to: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - query: Union[Dict[str, str], None] = None, - body: Union[Any, None] = None, + jwt: Optional[str] = None, + redirect_to: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + query: Optional[Dict[str, str]] = None, + body: Optional[Any] = None, no_resolve_json: bool = False, ) -> None: ... # pragma: no cover @@ -90,14 +90,14 @@ def _request( method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"], path: str, *, - jwt: Union[str, None] = None, - redirect_to: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - query: Union[Dict[str, str], None] = None, - body: Union[Any, None] = None, + jwt: Optional[str] = None, + redirect_to: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + query: Optional[Dict[str, str]] = None, + body: Optional[Any] = None, no_resolve_json: bool = False, - xform: Union[Callable[[Any], T], None] = None, - ) -> Union[T, None]: + xform: Optional[Callable[[Any], T]] = None, + ) -> Optional[T]: url = f"{self._url}/{path}" headers = {**self._headers, **(headers or {})} if API_VERSION_HEADER_NAME not in headers: diff --git a/supabase_auth/_sync/gotrue_client.py b/supabase_auth/_sync/gotrue_client.py index 27fc723e..90fa9c88 100644 --- a/supabase_auth/_sync/gotrue_client.py +++ b/supabase_auth/_sync/gotrue_client.py @@ -4,7 +4,7 @@ from functools import partial from json import loads from time import time -from typing import Callable, Dict, List, Optional, Tuple, Union +from typing import Callable, Dict, List, Optional, Tuple from urllib.parse import parse_qs, urlencode, urlparse from uuid import uuid4 @@ -87,13 +87,13 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI): def __init__( self, *, - url: Union[str, None] = None, - headers: Union[Dict[str, str], None] = None, - storage_key: Union[str, None] = None, + url: Optional[str] = None, + headers: Optional[Dict[str, str]] = None, + storage_key: Optional[str] = None, auto_refresh_token: bool = True, persist_session: bool = True, - storage: Union[SyncSupportedStorage, None] = None, - http_client: Union[SyncClient, None] = None, + storage: Optional[SyncSupportedStorage] = None, + http_client: Optional[SyncClient] = None, flow_type: AuthFlowType = "implicit", verify: bool = True, proxy: Optional[str] = None, @@ -110,8 +110,8 @@ def __init__( self._auto_refresh_token = auto_refresh_token self._persist_session = persist_session self._storage = storage or SyncMemoryStorage() - self._in_memory_session: Union[Session, None] = None - self._refresh_token_timer: Union[Timer, None] = None + self._in_memory_session: Optional[Session] = None + self._refresh_token_timer: Optional[Timer] = None self._network_retries = 0 self._state_change_emitters: Dict[str, Subscription] = {} self._flow_type = flow_type @@ -134,7 +134,7 @@ def __init__( # Initializations - def initialize(self, *, url: Union[str, None] = None) -> None: + def initialize(self, *, url: Optional[str] = None) -> None: if url and self._is_implicit_grant_flow(url): self.initialize_from_url(url) else: @@ -158,7 +158,7 @@ def initialize_from_url(self, url: str) -> None: # Public methods def sign_in_anonymously( - self, credentials: Union[SignInAnonymouslyCredentials, None] = None + self, credentials: Optional[SignInAnonymouslyCredentials] = None ) -> AuthResponse: """ Creates a new anonymous user. @@ -585,14 +585,14 @@ def reauthenticate(self) -> AuthResponse: xform=parse_auth_response, ) - def get_session(self) -> Union[Session, None]: + def get_session(self) -> Optional[Session]: """ Returns the session, refreshing it if necessary. The session returned can be null if the session is not detected which can happen in the event a user is not signed-in or has logged out. """ - current_session: Union[Session, None] = None + current_session: Optional[Session] = None if self._persist_session: maybe_session = self._storage.get_item(self._storage_key) current_session = self._get_valid_session(maybe_session) @@ -614,7 +614,7 @@ def get_session(self) -> Union[Session, None]: else current_session ) - def get_user(self, jwt: Union[str, None] = None) -> Union[UserResponse, None]: + def get_user(self, jwt: Optional[str] = None) -> Optional[UserResponse]: """ Gets the current user details if there is an existing session. @@ -666,7 +666,7 @@ def set_session(self, access_token: str, refresh_token: str) -> AuthResponse: time_now = round(time()) expires_at = time_now has_expired = True - session: Union[Session, None] = None + session: Optional[Session] = None if access_token and access_token.split(".")[1]: payload = self._decode_jwt(access_token) exp = payload.get("exp") @@ -694,7 +694,7 @@ def set_session(self, access_token: str, refresh_token: str) -> AuthResponse: self._notify_all_subscribers("TOKEN_REFRESHED", session) return AuthResponse(session=session, user=response.user) - def refresh_session(self, refresh_token: Union[str, None] = None) -> AuthResponse: + def refresh_session(self, refresh_token: Optional[str] = None) -> AuthResponse: """ Returns a new session, regardless of expiry status. @@ -735,7 +735,7 @@ def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None: def on_auth_state_change( self, - callback: Callable[[AuthChangeEvent, Union[Session, None]], None], + callback: Callable[[AuthChangeEvent, Optional[Session]], None], ) -> Subscription: """ Receive a notification every time an auth event happens. @@ -881,7 +881,7 @@ def _get_authenticator_assurance_level( current_authentication_methods=[], ) payload = self._decode_jwt(session.access_token) - current_level: Union[AuthenticatorAssuranceLevels, None] = None + current_level: Optional[AuthenticatorAssuranceLevels] = None if payload.get("aal"): current_level = payload.get("aal") verified_factors = [ @@ -909,7 +909,7 @@ def _remove_session(self) -> None: def _get_session_from_url( self, url: str, - ) -> Tuple[Session, Union[str, None]]: + ) -> Tuple[Session, Optional[str]]: if not self._is_implicit_grant_flow(url): raise AuthImplicitGrantRedirectError("Not a valid implicit grant flow url.") result = urlparse(url) @@ -1054,15 +1054,15 @@ def refresh_token_function(): def _notify_all_subscribers( self, event: AuthChangeEvent, - session: Union[Session, None], + session: Optional[Session], ) -> None: for subscription in self._state_change_emitters.values(): subscription.callback(event, session) def _get_valid_session( self, - raw_session: Union[str, None], - ) -> Union[Session, None]: + raw_session: Optional[str], + ) -> Optional[Session]: if not raw_session: return None data = loads(raw_session) @@ -1088,7 +1088,7 @@ def _get_param( self, query_params: Dict[str, List[str]], name: str, - ) -> Union[str, None]: + ) -> Optional[str]: return query_params[name][0] if name in query_params else None def _is_implicit_grant_flow(self, url: str) -> bool: diff --git a/supabase_auth/errors.py b/supabase_auth/errors.py index df423800..2fc1c138 100644 --- a/supabase_auth/errors.py +++ b/supabase_auth/errors.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import List, Literal, Union +from typing import List, Literal, Optional from typing_extensions import TypedDict @@ -153,14 +153,14 @@ class AuthImplicitGrantRedirectErrorDetails(TypedDict): class AuthImplicitGrantRedirectErrorDict(AuthApiErrorDict): - details: Union[AuthImplicitGrantRedirectErrorDetails, None] + details: Optional[AuthImplicitGrantRedirectErrorDetails] class AuthImplicitGrantRedirectError(CustomAuthError): def __init__( self, message: str, - details: Union[AuthImplicitGrantRedirectErrorDetails, None] = None, + details: Optional[AuthImplicitGrantRedirectErrorDetails] = None, ) -> None: CustomAuthError.__init__( self, diff --git a/supabase_auth/helpers.py b/supabase_auth/helpers.py index 25e9aa78..1ac90e83 100644 --- a/supabase_auth/helpers.py +++ b/supabase_auth/helpers.py @@ -8,7 +8,7 @@ from base64 import urlsafe_b64decode from datetime import datetime from json import loads -from typing import Any, Dict, Type, TypeVar, Union, cast +from typing import Any, Dict, Optional, Type, TypeVar, cast from httpx import HTTPStatusError, Response from pydantic import BaseModel @@ -68,7 +68,7 @@ def model_dump_json(model: BaseModel) -> str: def parse_auth_response(data: Any) -> AuthResponse: - session: Union[Session, None] = None + session: Optional[Session] = None if ( "access_token" in data and "refresh_token" in data diff --git a/supabase_auth/timer.py b/supabase_auth/timer.py index 1b6bf9b8..60095c20 100644 --- a/supabase_auth/timer.py +++ b/supabase_auth/timer.py @@ -1,18 +1,18 @@ import asyncio from threading import Timer as _Timer -from typing import Any, Callable, Coroutine, Union, cast +from typing import Any, Callable, Coroutine, Optional, cast class Timer: def __init__( self, seconds: float, - function: Callable[[], Union[Coroutine[Any, Any, None], None]], + function: Callable[[], Optional[Coroutine[Any, Any, None]]], ) -> None: self._milliseconds = seconds self._function = function - self._task: Union[asyncio.Task, None] = None - self._timer: Union[_Timer, None] = None + self._task: Optional[asyncio.Task] = None + self._timer: Optional[_Timer] = None def start(self) -> None: if asyncio.iscoroutinefunction(self._function): diff --git a/supabase_auth/types.py b/supabase_auth/types.py index bf5ba2d4..86bda3e2 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -2,7 +2,7 @@ from datetime import datetime from time import time -from typing import Any, Callable, Dict, List, Union +from typing import Any, Callable, Dict, List, Optional, Union from pydantic import BaseModel, ConfigDict @@ -93,14 +93,14 @@ class InviteUserByEmailOptions(TypedDict): class AuthResponse(BaseModel): - user: Union[User, None] = None - session: Union[Session, None] = None + user: Optional[User] = None + session: Optional[Session] = None class AuthOtpResponse(BaseModel): user: None = None session: None = None - message_id: Union[str, None] = None + message_id: Optional[str] = None class OAuthResponse(BaseModel): @@ -125,12 +125,12 @@ class UserResponse(BaseModel): class Session(BaseModel): - provider_token: Union[str, None] = None + provider_token: Optional[str] = None """ The oauth provider token. If present, this can be used to make external API requests to the oauth provider used. """ - provider_refresh_token: Union[str, None] = None + provider_refresh_token: Optional[str] = None """ The oauth provider refresh token. If present, this can be used to refresh the provider_token via the oauth provider's API. @@ -146,7 +146,7 @@ class Session(BaseModel): The number of seconds until the token expires (since it was issued). Returned when a login is confirmed. """ - expires_at: Union[int, None] = None + expires_at: Optional[int] = None """ A timestamp of when the token will expire. Returned when a login is confirmed. """ @@ -168,8 +168,8 @@ class UserIdentity(BaseModel): identity_data: Dict[str, Any] provider: str created_at: datetime - last_sign_in_at: Union[datetime, None] = None - updated_at: Union[datetime, None] = None + last_sign_in_at: Optional[datetime] = None + updated_at: Optional[datetime] = None class Factor(BaseModel): @@ -181,7 +181,7 @@ class Factor(BaseModel): """ ID of the factor. """ - friendly_name: Union[str, None] = None + friendly_name: Optional[str] = None """ Friendly name of the factor, useful to disambiguate between multiple factors. """ @@ -203,25 +203,25 @@ class User(BaseModel): app_metadata: Dict[str, Any] user_metadata: Dict[str, Any] aud: str - confirmation_sent_at: Union[datetime, None] = None - recovery_sent_at: Union[datetime, None] = None - email_change_sent_at: Union[datetime, None] = None - new_email: Union[str, None] = None - new_phone: Union[str, None] = None - invited_at: Union[datetime, None] = None - action_link: Union[str, None] = None - email: Union[str, None] = None - phone: Union[str, None] = None + confirmation_sent_at: Optional[datetime] = None + recovery_sent_at: Optional[datetime] = None + email_change_sent_at: Optional[datetime] = None + new_email: Optional[str] = None + new_phone: Optional[str] = None + invited_at: Optional[datetime] = None + action_link: Optional[str] = None + email: Optional[str] = None + phone: Optional[str] = None created_at: datetime - confirmed_at: Union[datetime, None] = None - email_confirmed_at: Union[datetime, None] = None - phone_confirmed_at: Union[datetime, None] = None - last_sign_in_at: Union[datetime, None] = None - role: Union[str, None] = None - updated_at: Union[datetime, None] = None - identities: Union[List[UserIdentity], None] = None + confirmed_at: Optional[datetime] = None + email_confirmed_at: Optional[datetime] = None + phone_confirmed_at: Optional[datetime] = None + last_sign_in_at: Optional[datetime] = None + role: Optional[str] = None + updated_at: Optional[datetime] = None + identities: Optional[List[UserIdentity]] = None is_anonymous: bool = False - factors: Union[List[Factor], None] = None + factors: Optional[List[Factor]] = None class UserAttributes(TypedDict): @@ -266,7 +266,7 @@ class Subscription(BaseModel): """ The subscriber UUID. This will be set by the client. """ - callback: Callable[[AuthChangeEvent, Union[Session, None]], None] + callback: Callable[[AuthChangeEvent, Optional[Session]], None] """ The function to call every time there is an event. """ @@ -691,11 +691,11 @@ class AuthMFAListFactorsResponse(BaseModel): class AuthMFAGetAuthenticatorAssuranceLevelResponse(BaseModel): - current_level: Union[AuthenticatorAssuranceLevels, None] = None + current_level: Optional[AuthenticatorAssuranceLevels] = None """ Current AAL level of the session. """ - next_level: Union[AuthenticatorAssuranceLevels, None] = None + next_level: Optional[AuthenticatorAssuranceLevels] = None """ Next possible AAL level for the session. If the next level is higher than the current one, the user should go through MFA. @@ -778,8 +778,8 @@ class GenerateLinkResponse(BaseModel): class DecodedJWTDict(TypedDict): exp: NotRequired[int] - aal: NotRequired[Union[AuthenticatorAssuranceLevels, None]] - amr: NotRequired[Union[List[AMREntry], None]] + aal: NotRequired[Optional[AuthenticatorAssuranceLevels]] + amr: NotRequired[Optional[List[AMREntry]]] SignOutScope = Literal["global", "local", "others"] diff --git a/tests/_async/utils.py b/tests/_async/utils.py index 4b8982fc..1f648197 100644 --- a/tests/_async/utils.py +++ b/tests/_async/utils.py @@ -1,6 +1,6 @@ from random import random from time import time -from typing import Union +from typing import Optional from faker import Faker from jwt import encode @@ -22,9 +22,9 @@ def mock_access_token() -> str: class OptionalCredentials(TypedDict): - email: NotRequired[Union[str, None]] - phone: NotRequired[Union[str, None]] - password: NotRequired[Union[str, None]] + email: NotRequired[Optional[str]] + phone: NotRequired[Optional[str]] + password: NotRequired[Optional[str]] class Credentials(TypedDict): @@ -64,8 +64,8 @@ def mock_app_metadata(): async def create_new_user_with_email( *, - email: Union[str, None] = None, - password: Union[str, None] = None, + email: Optional[str] = None, + password: Optional[str] = None, ) -> User: credentials = mock_user_credentials( { diff --git a/tests/_sync/utils.py b/tests/_sync/utils.py index a459e7ba..2cc31de2 100644 --- a/tests/_sync/utils.py +++ b/tests/_sync/utils.py @@ -1,6 +1,6 @@ from random import random from time import time -from typing import Union +from typing import Optional from faker import Faker from jwt import encode @@ -22,9 +22,9 @@ def mock_access_token() -> str: class OptionalCredentials(TypedDict): - email: NotRequired[Union[str, None]] - phone: NotRequired[Union[str, None]] - password: NotRequired[Union[str, None]] + email: NotRequired[Optional[str]] + phone: NotRequired[Optional[str]] + password: NotRequired[Optional[str]] class Credentials(TypedDict): @@ -64,8 +64,8 @@ def mock_app_metadata(): def create_new_user_with_email( *, - email: Union[str, None] = None, - password: Union[str, None] = None, + email: Optional[str] = None, + password: Optional[str] = None, ) -> User: credentials = mock_user_credentials( {