Skip to content

Commit a892c43

Browse files
authored
fix(auth): more linting rules (#1289)
1 parent 7159116 commit a892c43

24 files changed

+374
-347
lines changed

src/auth/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ select = [
5959
# pyupgrade
6060
"UP",
6161
# flake8-bugbear
62-
# "B",
62+
"B",
6363
# flake8-simplify
6464
# "SIM",
6565
# isort
6666
"I",
67+
"ANN2"
6768
]
68-
ignore = ["F401", "F403", "F841", "E712", "E501", "E402", "E722", "E731", "UP006", "UP035"]
69-
# isort.required-imports = ["from __future__ import annotations"]
69+
ignore = ["F403", "E501", "E402", "UP006", "UP035"]
7070

7171
[tool.ruff.lint.pyupgrade]
7272
# Preserve types, even if a file imports `from __future__ import annotations`.

src/auth/scripts/gh-download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ def download_directory(repository: Repository, sha: str, server_path: str) -> No
7373
print("Error processing %s: %s", content.path, exc)
7474

7575

76-
def usage():
76+
def usage() -> None:
7777
"""
7878
Prints the usage command lines
7979
"""
8080
print("usage: gh-download --repo=repo --branch=branch --folder=folder")
8181

8282

83-
def main(argv):
83+
def main(argv) -> None:
8484
"""
8585
Main function block
8686
"""
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from __future__ import annotations
22

3-
from ._async.gotrue_admin_api import AsyncGoTrueAdminAPI
4-
from ._async.gotrue_client import AsyncGoTrueClient
3+
from ._async.gotrue_admin_api import AsyncGoTrueAdminAPI # noqa
4+
from ._async.gotrue_client import AsyncGoTrueClient # noqa
55
from ._async.storage import (
6-
AsyncMemoryStorage,
7-
AsyncSupportedStorage,
6+
AsyncMemoryStorage, # noqa
7+
AsyncSupportedStorage, # noqa
88
)
9-
from ._sync.gotrue_admin_api import SyncGoTrueAdminAPI
10-
from ._sync.gotrue_client import SyncGoTrueClient
9+
from ._sync.gotrue_admin_api import SyncGoTrueAdminAPI # noqa
10+
from ._sync.gotrue_client import SyncGoTrueClient # noqa
1111
from ._sync.storage import (
12-
SyncMemoryStorage,
13-
SyncSupportedStorage,
12+
SyncMemoryStorage, # noqa
13+
SyncSupportedStorage, # noqa
1414
)
1515
from .types import *
16-
from .version import __version__
16+
from .version import __version__ # noqa

src/auth/src/supabase_auth/_async/gotrue_admin_api.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from __future__ import annotations
22

3-
from typing import Any, Dict, List, Optional
3+
from typing import Dict, List, Optional
44

5-
from httpx import QueryParams, Response
6-
from pydantic import TypeAdapter
5+
from httpx import QueryParams
76

87
from ..helpers import (
98
model_validate,
@@ -42,15 +41,16 @@ def __init__(
4241
self,
4342
*,
4443
url: str = "",
45-
headers: Dict[str, str] = {},
44+
headers: Optional[Dict[str, str]] = None,
4645
http_client: Optional[AsyncClient] = None,
4746
verify: bool = True,
4847
proxy: Optional[str] = None,
4948
) -> None:
49+
http_headers = headers or {}
5050
AsyncGoTrueBaseAPI.__init__(
5151
self,
5252
url=url,
53-
headers=headers,
53+
headers=http_headers,
5454
http_client=http_client,
5555
verify=verify,
5656
proxy=proxy,
@@ -82,16 +82,17 @@ async def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
8282
async def invite_user_by_email(
8383
self,
8484
email: str,
85-
options: InviteUserByEmailOptions = {},
85+
options: Optional[InviteUserByEmailOptions] = None,
8686
) -> UserResponse:
8787
"""
8888
Sends an invite link to an email address.
8989
"""
90+
email_options = options or {}
9091
response = await self._request(
9192
"POST",
9293
"invite",
93-
body={"email": email, "data": options.get("data")},
94-
redirect_to=options.get("redirect_to"),
94+
body={"email": email, "data": email_options.get("data")},
95+
redirect_to=email_options.get("redirect_to"),
9596
)
9697
return parse_user_response(response)
9798

src/auth/src/supabase_auth/_async/gotrue_base_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, Callable, Dict, Optional, TypeVar, overload
3+
from typing import Any, Dict, Optional
44

55
from httpx import HTTPStatusError, QueryParams, Response
66
from pydantic import BaseModel
@@ -20,7 +20,7 @@ def __init__(
2020
http_client: Optional[AsyncClient],
2121
verify: bool = True,
2222
proxy: Optional[str] = None,
23-
):
23+
) -> None:
2424
self._url = url
2525
self._headers = headers
2626
self._http_client = http_client or AsyncClient(
@@ -74,4 +74,4 @@ async def _request(
7474
response.raise_for_status()
7575
return response
7676
except (HTTPStatusError, RuntimeError) as e:
77-
raise handle_exception(e)
77+
raise handle_exception(e) # noqa

src/auth/src/supabase_auth/_async/gotrue_client.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import time
44
from contextlib import suppress
5-
from functools import partial
6-
from json import loads
7-
from typing import Callable, Dict, List, Mapping, Optional, Tuple, Union
8-
from urllib.parse import parse_qs, urlencode, urlparse
5+
from typing import Callable, Dict, List, Optional, Tuple
6+
from urllib.parse import parse_qs, urlparse
97
from uuid import uuid4
108

11-
from httpx import QueryParams
9+
from httpx import QueryParams, Response
1210
from jwt import get_algorithm_by_name
1311
from typing_extensions import cast
1412

@@ -33,7 +31,6 @@
3331
decode_jwt,
3432
generate_pkce_challenge,
3533
generate_pkce_verifier,
36-
model_dump,
3734
model_dump_json,
3835
model_validate,
3936
parse_auth_otp_response,
@@ -50,7 +47,6 @@
5047
JWK,
5148
AMREntry,
5249
AuthChangeEvent,
53-
AuthenticatorAssuranceLevels,
5450
AuthFlowType,
5551
AuthMFAChallengeResponse,
5652
AuthMFAEnrollResponse,
@@ -86,6 +82,7 @@
8682
SignUpWithEmailAndPasswordCredentialsOptions,
8783
SignUpWithPasswordCredentials,
8884
SignUpWithPhoneAndPasswordCredentialsOptions,
85+
SSOResponse,
8986
Subscription,
9087
UpdateUserOptions,
9188
UserAttributes,
@@ -361,7 +358,9 @@ async def sign_in_with_id_token(
361358
self._notify_all_subscribers("SIGNED_IN", auth_response.session)
362359
return auth_response
363360

364-
async def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
361+
async def sign_in_with_sso(
362+
self, credentials: SignInWithSSOCredentials
363+
) -> SSOResponse:
365364
"""
366365
Attempts a single-sign on using an enterprise Identity Provider. A
367366
successful SSO attempt will redirect the current page to the identity
@@ -476,7 +475,7 @@ async def get_user_identities(self) -> IdentitiesResponse:
476475
return IdentitiesResponse(identities=response.user.identities or [])
477476
raise AuthSessionMissingError()
478477

479-
async def unlink_identity(self, identity: UserIdentity):
478+
async def unlink_identity(self, identity: UserIdentity) -> Response:
480479
session = await self.get_session()
481480
if not session:
482481
raise AuthSessionMissingError()
@@ -621,7 +620,7 @@ async def reauthenticate(self) -> AuthResponse:
621620
if not session:
622621
raise AuthSessionMissingError()
623622

624-
response = await self._request(
623+
await self._request(
625624
"GET",
626625
"reauthenticate",
627626
jwt=session.access_token,
@@ -674,19 +673,20 @@ async def get_user(self, jwt: Optional[str] = None) -> Optional[UserResponse]:
674673
return parse_user_response(await self._request("GET", "user", jwt=jwt))
675674

676675
async def update_user(
677-
self, attributes: UserAttributes, options: UpdateUserOptions = {}
676+
self, attributes: UserAttributes, options: Optional[UpdateUserOptions] = None
678677
) -> UserResponse:
679678
"""
680679
Updates user data, if there is a logged in user.
681680
"""
682681
session = await self.get_session()
683682
if not session:
684683
raise AuthSessionMissingError()
684+
update_options = options or {}
685685
response = await self._request(
686686
"PUT",
687687
"user",
688688
body=attributes,
689-
redirect_to=options.get("email_redirect_to"),
689+
redirect_to=update_options.get("email_redirect_to"),
690690
jwt=session.access_token,
691691
)
692692
user_response = parse_user_response(response)
@@ -762,7 +762,7 @@ async def refresh_session(
762762
session = await self._call_refresh_token(refresh_token)
763763
return AuthResponse(session=session, user=session.user)
764764

765-
async def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
765+
async def sign_out(self, options: Optional[SignOutOptions] = None) -> None:
766766
"""
767767
`sign_out` will remove the logged in user from the
768768
current session and log them out - removing all items from storage and then trigger a `"SIGNED_OUT"` event.
@@ -772,13 +772,14 @@ async def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
772772
There is no way to revoke a user's access token jwt until it expires.
773773
It is recommended to set a shorter expiry on the jwt for this reason.
774774
"""
775+
signout_options = options or {"scope": "global"}
775776
with suppress(AuthApiError):
776777
session = await self.get_session()
777778
access_token = session.access_token if session else None
778779
if access_token:
779-
await self.admin.sign_out(access_token, options["scope"])
780+
await self.admin.sign_out(access_token, signout_options["scope"])
780781

781-
if options["scope"] != "others":
782+
if signout_options["scope"] != "others":
782783
await self._remove_session()
783784
self._notify_all_subscribers("SIGNED_OUT", None)
784785

@@ -802,31 +803,35 @@ def _unsubscribe() -> None:
802803
self._state_change_emitters[unique_id] = subscription
803804
return subscription
804805

805-
async def reset_password_for_email(self, email: str, options: Options = {}) -> None:
806+
async def reset_password_for_email(
807+
self, email: str, options: Optional[Options] = None
808+
) -> None:
806809
"""
807810
Sends a password reset request to an email address.
808811
"""
812+
reset_options = options or {}
809813
await self._request(
810814
"POST",
811815
"recover",
812816
body={
813817
"email": email,
814818
"gotrue_meta_security": {
815-
"captcha_token": options.get("captcha_token"),
819+
"captcha_token": reset_options.get("captcha_token"),
816820
},
817821
},
818-
redirect_to=options.get("redirect_to"),
822+
redirect_to=reset_options.get("redirect_to"),
819823
)
820824

821825
async def reset_password_email(
822826
self,
823827
email: str,
824-
options: Options = {},
828+
options: Optional[Options] = None,
825829
) -> None:
826830
"""
827831
Sends a password reset request to an email address.
828832
"""
829-
await self.reset_password_for_email(email, options)
833+
834+
await self.reset_password_for_email(email, options or {})
830835

831836
# MFA methods
832837

@@ -1090,7 +1095,7 @@ async def _start_auto_refresh_token(self, value: float) -> None:
10901095
if value <= 0 or not self._auto_refresh_token:
10911096
return
10921097

1093-
async def refresh_token_function():
1098+
async def refresh_token_function() -> None:
10941099
self._network_retries += 1
10951100
try:
10961101
session = await self.get_session()
@@ -1275,7 +1280,7 @@ def __del__(self) -> None:
12751280
try:
12761281
# Try to cancel the timer
12771282
self._refresh_token_timer.cancel()
1278-
except:
1283+
except Exception:
12791284
# Ignore errors if event loop is closed or selector is not registered
12801285
pass
12811286
finally:

src/auth/src/supabase_auth/_sync/gotrue_admin_api.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from __future__ import annotations
22

3-
from typing import Any, Dict, List, Optional
3+
from typing import Dict, List, Optional
44

5-
from httpx import QueryParams, Response
6-
from pydantic import TypeAdapter
5+
from httpx import QueryParams
76

87
from ..helpers import (
98
model_validate,
@@ -42,15 +41,16 @@ def __init__(
4241
self,
4342
*,
4443
url: str = "",
45-
headers: Dict[str, str] = {},
44+
headers: Optional[Dict[str, str]] = None,
4645
http_client: Optional[SyncClient] = None,
4746
verify: bool = True,
4847
proxy: Optional[str] = None,
4948
) -> None:
49+
http_headers = headers or {}
5050
SyncGoTrueBaseAPI.__init__(
5151
self,
5252
url=url,
53-
headers=headers,
53+
headers=http_headers,
5454
http_client=http_client,
5555
verify=verify,
5656
proxy=proxy,
@@ -82,16 +82,17 @@ def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
8282
def invite_user_by_email(
8383
self,
8484
email: str,
85-
options: InviteUserByEmailOptions = {},
85+
options: Optional[InviteUserByEmailOptions] = None,
8686
) -> UserResponse:
8787
"""
8888
Sends an invite link to an email address.
8989
"""
90+
email_options = options or {}
9091
response = self._request(
9192
"POST",
9293
"invite",
93-
body={"email": email, "data": options.get("data")},
94-
redirect_to=options.get("redirect_to"),
94+
body={"email": email, "data": email_options.get("data")},
95+
redirect_to=email_options.get("redirect_to"),
9596
)
9697
return parse_user_response(response)
9798

src/auth/src/supabase_auth/_sync/gotrue_base_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, Callable, Dict, Optional, TypeVar, overload
3+
from typing import Any, Dict, Optional
44

55
from httpx import HTTPStatusError, QueryParams, Response
66
from pydantic import BaseModel
@@ -20,7 +20,7 @@ def __init__(
2020
http_client: Optional[SyncClient],
2121
verify: bool = True,
2222
proxy: Optional[str] = None,
23-
):
23+
) -> None:
2424
self._url = url
2525
self._headers = headers
2626
self._http_client = http_client or SyncClient(
@@ -74,4 +74,4 @@ def _request(
7474
response.raise_for_status()
7575
return response
7676
except (HTTPStatusError, RuntimeError) as e:
77-
raise handle_exception(e)
77+
raise handle_exception(e) # noqa

0 commit comments

Comments
 (0)