Skip to content

Commit 6a20f00

Browse files
committed
chore: more linting rules
1 parent 7757d13 commit 6a20f00

File tree

14 files changed

+77
-55
lines changed

14 files changed

+77
-55
lines changed

src/auth/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ select = [
5959
# pyupgrade
6060
"UP",
6161
# flake8-bugbear
62-
# "B",
62+
"B",
6363
# flake8-simplify
6464
# "SIM",
6565
# isort

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ def __init__(
4141
self,
4242
*,
4343
url: str = "",
44-
headers: Dict[str, str] = {},
44+
headers: Optional[Dict[str, str]] = None,
4545
http_client: Optional[AsyncClient] = None,
4646
verify: bool = True,
4747
proxy: Optional[str] = None,
4848
) -> None:
49+
http_headers = headers or {}
4950
AsyncGoTrueBaseAPI.__init__(
5051
self,
5152
url=url,
52-
headers=headers,
53+
headers=http_headers,
5354
http_client=http_client,
5455
verify=verify,
5556
proxy=proxy,
@@ -81,16 +82,17 @@ async def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
8182
async def invite_user_by_email(
8283
self,
8384
email: str,
84-
options: InviteUserByEmailOptions = {},
85+
options: Optional[InviteUserByEmailOptions] = None,
8586
) -> UserResponse:
8687
"""
8788
Sends an invite link to an email address.
8889
"""
90+
email_options = options or {}
8991
response = await self._request(
9092
"POST",
9193
"invite",
92-
body={"email": email, "data": options.get("data")},
93-
redirect_to=options.get("redirect_to"),
94+
body={"email": email, "data": email_options.get("data")},
95+
redirect_to=email_options.get("redirect_to"),
9496
)
9597
return parse_user_response(response)
9698

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -673,19 +673,20 @@ async def get_user(self, jwt: Optional[str] = None) -> Optional[UserResponse]:
673673
return parse_user_response(await self._request("GET", "user", jwt=jwt))
674674

675675
async def update_user(
676-
self, attributes: UserAttributes, options: UpdateUserOptions = {}
676+
self, attributes: UserAttributes, options: Optional[UpdateUserOptions]
677677
) -> UserResponse:
678678
"""
679679
Updates user data, if there is a logged in user.
680680
"""
681681
session = await self.get_session()
682682
if not session:
683683
raise AuthSessionMissingError()
684+
update_options = options or {}
684685
response = await self._request(
685686
"PUT",
686687
"user",
687688
body=attributes,
688-
redirect_to=options.get("email_redirect_to"),
689+
redirect_to=update_options.get("email_redirect_to"),
689690
jwt=session.access_token,
690691
)
691692
user_response = parse_user_response(response)
@@ -761,7 +762,7 @@ async def refresh_session(
761762
session = await self._call_refresh_token(refresh_token)
762763
return AuthResponse(session=session, user=session.user)
763764

764-
async def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
765+
async def sign_out(self, options: Optional[SignOutOptions] = None) -> None:
765766
"""
766767
`sign_out` will remove the logged in user from the
767768
current session and log them out - removing all items from storage and then trigger a `"SIGNED_OUT"` event.
@@ -771,13 +772,14 @@ async def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
771772
There is no way to revoke a user's access token jwt until it expires.
772773
It is recommended to set a shorter expiry on the jwt for this reason.
773774
"""
775+
signout_options = options or {"scope": "global"}
774776
with suppress(AuthApiError):
775777
session = await self.get_session()
776778
access_token = session.access_token if session else None
777779
if access_token:
778-
await self.admin.sign_out(access_token, options["scope"])
780+
await self.admin.sign_out(access_token, signout_options["scope"])
779781

780-
if options["scope"] != "others":
782+
if signout_options["scope"] != "others":
781783
await self._remove_session()
782784
self._notify_all_subscribers("SIGNED_OUT", None)
783785

@@ -801,31 +803,35 @@ def _unsubscribe() -> None:
801803
self._state_change_emitters[unique_id] = subscription
802804
return subscription
803805

804-
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:
805809
"""
806810
Sends a password reset request to an email address.
807811
"""
812+
reset_options = options or {}
808813
await self._request(
809814
"POST",
810815
"recover",
811816
body={
812817
"email": email,
813818
"gotrue_meta_security": {
814-
"captcha_token": options.get("captcha_token"),
819+
"captcha_token": reset_options.get("captcha_token"),
815820
},
816821
},
817-
redirect_to=options.get("redirect_to"),
822+
redirect_to=reset_options.get("redirect_to"),
818823
)
819824

820825
async def reset_password_email(
821826
self,
822827
email: str,
823-
options: Options = {},
828+
options: Optional[Options] = None,
824829
) -> None:
825830
"""
826831
Sends a password reset request to an email address.
827832
"""
828-
await self.reset_password_for_email(email, options)
833+
834+
await self.reset_password_for_email(email, options or {})
829835

830836
# MFA methods
831837

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ def __init__(
4141
self,
4242
*,
4343
url: str = "",
44-
headers: Dict[str, str] = {},
44+
headers: Optional[Dict[str, str]] = None,
4545
http_client: Optional[SyncClient] = None,
4646
verify: bool = True,
4747
proxy: Optional[str] = None,
4848
) -> None:
49+
http_headers = headers or {}
4950
SyncGoTrueBaseAPI.__init__(
5051
self,
5152
url=url,
52-
headers=headers,
53+
headers=http_headers,
5354
http_client=http_client,
5455
verify=verify,
5556
proxy=proxy,
@@ -81,16 +82,17 @@ def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
8182
def invite_user_by_email(
8283
self,
8384
email: str,
84-
options: InviteUserByEmailOptions = {},
85+
options: Optional[InviteUserByEmailOptions] = None,
8586
) -> UserResponse:
8687
"""
8788
Sends an invite link to an email address.
8889
"""
90+
email_options = options or {}
8991
response = self._request(
9092
"POST",
9193
"invite",
92-
body={"email": email, "data": options.get("data")},
93-
redirect_to=options.get("redirect_to"),
94+
body={"email": email, "data": email_options.get("data")},
95+
redirect_to=email_options.get("redirect_to"),
9496
)
9597
return parse_user_response(response)
9698

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

src/auth/src/supabase_auth/_sync/gotrue_client.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,19 +669,20 @@ def get_user(self, jwt: Optional[str] = None) -> Optional[UserResponse]:
669669
return parse_user_response(self._request("GET", "user", jwt=jwt))
670670

671671
def update_user(
672-
self, attributes: UserAttributes, options: UpdateUserOptions = {}
672+
self, attributes: UserAttributes, options: Optional[UpdateUserOptions]
673673
) -> UserResponse:
674674
"""
675675
Updates user data, if there is a logged in user.
676676
"""
677677
session = self.get_session()
678678
if not session:
679679
raise AuthSessionMissingError()
680+
update_options = options or {}
680681
response = self._request(
681682
"PUT",
682683
"user",
683684
body=attributes,
684-
redirect_to=options.get("email_redirect_to"),
685+
redirect_to=update_options.get("email_redirect_to"),
685686
jwt=session.access_token,
686687
)
687688
user_response = parse_user_response(response)
@@ -755,7 +756,7 @@ def refresh_session(self, refresh_token: Optional[str] = None) -> AuthResponse:
755756
session = self._call_refresh_token(refresh_token)
756757
return AuthResponse(session=session, user=session.user)
757758

758-
def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
759+
def sign_out(self, options: Optional[SignOutOptions] = None) -> None:
759760
"""
760761
`sign_out` will remove the logged in user from the
761762
current session and log them out - removing all items from storage and then trigger a `"SIGNED_OUT"` event.
@@ -765,13 +766,14 @@ def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
765766
There is no way to revoke a user's access token jwt until it expires.
766767
It is recommended to set a shorter expiry on the jwt for this reason.
767768
"""
769+
signout_options = options or {"scope": "global"}
768770
with suppress(AuthApiError):
769771
session = self.get_session()
770772
access_token = session.access_token if session else None
771773
if access_token:
772-
self.admin.sign_out(access_token, options["scope"])
774+
self.admin.sign_out(access_token, signout_options["scope"])
773775

774-
if options["scope"] != "others":
776+
if signout_options["scope"] != "others":
775777
self._remove_session()
776778
self._notify_all_subscribers("SIGNED_OUT", None)
777779

@@ -795,31 +797,35 @@ def _unsubscribe() -> None:
795797
self._state_change_emitters[unique_id] = subscription
796798
return subscription
797799

798-
def reset_password_for_email(self, email: str, options: Options = {}) -> None:
800+
def reset_password_for_email(
801+
self, email: str, options: Optional[Options] = None
802+
) -> None:
799803
"""
800804
Sends a password reset request to an email address.
801805
"""
806+
reset_options = options or {}
802807
self._request(
803808
"POST",
804809
"recover",
805810
body={
806811
"email": email,
807812
"gotrue_meta_security": {
808-
"captcha_token": options.get("captcha_token"),
813+
"captcha_token": reset_options.get("captcha_token"),
809814
},
810815
},
811-
redirect_to=options.get("redirect_to"),
816+
redirect_to=reset_options.get("redirect_to"),
812817
)
813818

814819
def reset_password_email(
815820
self,
816821
email: str,
817-
options: Options = {},
822+
options: Optional[Options] = None,
818823
) -> None:
819824
"""
820825
Sends a password reset request to an email address.
821826
"""
822-
self.reset_password_for_email(email, options)
827+
828+
self.reset_password_for_email(email, options or {})
823829

824830
# MFA methods
825831

src/auth/src/supabase_auth/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ def decode_jwt(token: str) -> DecodedJWT:
226226
header = base64url_to_bytes(parts[0])
227227
payload = base64url_to_bytes(parts[1])
228228
signature = base64url_to_bytes(parts[2])
229-
except binascii.Error:
230-
raise AuthInvalidJwtError("Invalid JWT structure")
229+
except binascii.Error as e:
230+
raise AuthInvalidJwtError("Invalid JWT structure") from e
231231

232232
return DecodedJWT(
233233
header=JWTHeaderParser.validate_json(header),

src/auth/tests/_async/clients.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ class Credentials:
3535

3636

3737
def mock_user_credentials(
38-
options: OptionalCredentials = {},
38+
options: Optional[OptionalCredentials] = None,
3939
) -> Credentials:
4040
fake = Faker()
41+
user_options = options or {}
4142
rand_numbers = str(int(time()))
4243
return Credentials(
43-
email=options.get("email") or fake.email(),
44-
phone=options.get("phone") or f"1{rand_numbers[-11:]}",
45-
password=options.get("password") or fake.password(),
44+
email=user_options.get("email") or fake.email(),
45+
phone=user_options.get("phone") or f"1{rand_numbers[-11:]}",
46+
password=user_options.get("password") or fake.password(),
4647
)
4748

4849

src/auth/tests/_async/test_gotrue.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,16 @@ async def test_sign_in_with_password() -> None:
464464
"password": "wrong_password",
465465
}
466466
)
467-
assert False, "Expected AuthApiError for wrong password"
467+
raise AssertionError("Expected AuthApiError for wrong password")
468468
except AuthApiError:
469469
pass
470470

471471
# Test error case: missing credentials
472472
try:
473473
await test_client.sign_in_with_password({}) # type: ignore
474-
assert False, "Expected AuthInvalidCredentialsError for missing credentials"
474+
raise AssertionError(
475+
"Expected AuthInvalidCredentialsError for missing credentials"
476+
)
475477
except AuthInvalidCredentialsError:
476478
pass
477479

@@ -569,7 +571,7 @@ async def test_sign_in_with_otp() -> None:
569571

570572
try:
571573
await client.sign_in_with_otp({}) # type: ignore
572-
assert False, "Expected AuthInvalidCredentialsError"
574+
raise AssertionError("Expected AuthInvalidCredentialsError")
573575
except AuthInvalidCredentialsError:
574576
pass
575577

0 commit comments

Comments
 (0)