Skip to content

Commit

Permalink
fix: Types to use Option[T] (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored Oct 15, 2024
1 parent fce8839 commit c36d80f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 5 additions & 7 deletions supabase/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(
self,
supabase_url: str,
supabase_key: str,
options: Union[ClientOptions, None] = None,
options: Optional[ClientOptions] = None,
):
"""Instantiate the client.
Expand Down Expand Up @@ -97,7 +97,7 @@ async def create(
cls,
supabase_url: str,
supabase_key: str,
options: Union[ClientOptions, None] = None,
options: Optional[ClientOptions] = None,
):
auth_header = options.headers.get("Authorization") if options else None
client = cls(supabase_url, supabase_key, options)
Expand Down Expand Up @@ -278,9 +278,7 @@ def _init_postgrest_client(
def _create_auth_header(self, token: str):
return f"Bearer {token}"

def _get_auth_headers(
self, authorization: Union[str, None] = None
) -> Dict[str, str]:
def _get_auth_headers(self, authorization: Optional[str] = None) -> Dict[str, str]:
if authorization is None:
authorization = self.options.headers.get(
"Authorization", self._create_auth_header(self.supabase_key)
Expand All @@ -293,7 +291,7 @@ def _get_auth_headers(
}

def _listen_to_auth_events(
self, event: AuthChangeEvent, session: Union[Session, None]
self, event: AuthChangeEvent, session: Optional[Session]
):
access_token = self.supabase_key
if event in ["SIGNED_IN", "TOKEN_REFRESHED", "SIGNED_OUT"]:
Expand All @@ -310,7 +308,7 @@ def _listen_to_auth_events(
async def create_client(
supabase_url: str,
supabase_key: str,
options: Union[ClientOptions, None] = None,
options: Optional[ClientOptions] = None,
) -> AsyncClient:
"""Create client function to instantiate supabase client like JS runtime.
Expand Down
12 changes: 5 additions & 7 deletions supabase/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
self,
supabase_url: str,
supabase_key: str,
options: Union[ClientOptions, None] = None,
options: Optional[ClientOptions] = None,
):
"""Instantiate the client.
Expand Down Expand Up @@ -96,7 +96,7 @@ def create(
cls,
supabase_url: str,
supabase_key: str,
options: Union[ClientOptions, None] = None,
options: Optional[ClientOptions] = None,
):
auth_header = options.headers.get("Authorization") if options else None
client = cls(supabase_url, supabase_key, options)
Expand Down Expand Up @@ -277,9 +277,7 @@ def _init_postgrest_client(
def _create_auth_header(self, token: str):
return f"Bearer {token}"

def _get_auth_headers(
self, authorization: Union[str, None] = None
) -> Dict[str, str]:
def _get_auth_headers(self, authorization: Optional[str] = None) -> Dict[str, str]:
if authorization is None:
authorization = self.options.headers.get(
"Authorization", self._create_auth_header(self.supabase_key)
Expand All @@ -292,7 +290,7 @@ def _get_auth_headers(
}

def _listen_to_auth_events(
self, event: AuthChangeEvent, session: Union[Session, None]
self, event: AuthChangeEvent, session: Optional[Session]
):
access_token = self.supabase_key
if event in ["SIGNED_IN", "TOKEN_REFRESHED", "SIGNED_OUT"]:
Expand All @@ -308,7 +306,7 @@ def _listen_to_auth_events(
def create_client(
supabase_url: str,
supabase_key: str,
options: Union[ClientOptions, None] = None,
options: Optional[ClientOptions] = None,
) -> SyncClient:
"""Create client function to instantiate supabase client like JS runtime.
Expand Down

0 comments on commit c36d80f

Please sign in to comment.