Skip to content

Commit

Permalink
'Refactored by Sourcery' (#175)
Browse files Browse the repository at this point in the history
Co-authored-by: Sourcery AI <>
  • Loading branch information
sourcery-ai[bot] committed Oct 18, 2022
1 parent 4e3be99 commit 9e4a1f2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
16 changes: 7 additions & 9 deletions gotrue/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ async def get_session(self) -> Union[Session, None]:
if current_session.expires_at
else False
)
if not has_expired:
return current_session
return await self._call_refresh_token(current_session.refresh_token)
return (
await self._call_refresh_token(current_session.refresh_token)
if has_expired
else current_session
)

async def get_user(self, jwt: Union[str, None] = None) -> UserResponse:
"""
Expand Down Expand Up @@ -582,7 +584,6 @@ async def _save_session(self, session: Session) -> None:
self._in_memory_session = session
expire_at = session.expires_at
if expire_at:
pass
time_now = round(time())
expire_in = expire_at - time_now
refresh_duration_before_expires = (
Expand Down Expand Up @@ -648,8 +649,7 @@ def _get_valid_session(
except ValueError:
return None
try:
session = Session.parse_obj(data)
return session
return Session.parse_obj(data)
except Exception:
return None

Expand All @@ -658,9 +658,7 @@ def _get_param(
query_params: Dict[str, List[str]],
name: str,
) -> Union[str, None]:
if name in query_params:
return query_params[name][0]
return None
return query_params[name][0] if name in query_params else None

def _is_implicit_grant_flow(self, url: str) -> bool:
result = urlparse(url)
Expand Down
16 changes: 7 additions & 9 deletions gotrue/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ def get_session(self) -> Union[Session, None]:
if current_session.expires_at
else False
)
if not has_expired:
return current_session
return self._call_refresh_token(current_session.refresh_token)
return (
self._call_refresh_token(current_session.refresh_token)
if has_expired
else current_session
)

def get_user(self, jwt: Union[str, None] = None) -> UserResponse:
"""
Expand Down Expand Up @@ -582,7 +584,6 @@ def _save_session(self, session: Session) -> None:
self._in_memory_session = session
expire_at = session.expires_at
if expire_at:
pass
time_now = round(time())
expire_in = expire_at - time_now
refresh_duration_before_expires = (
Expand Down Expand Up @@ -648,8 +649,7 @@ def _get_valid_session(
except ValueError:
return None
try:
session = Session.parse_obj(data)
return session
return Session.parse_obj(data)
except Exception:
return None

Expand All @@ -658,9 +658,7 @@ def _get_param(
query_params: Dict[str, List[str]],
name: str,
) -> Union[str, None]:
if name in query_params:
return query_params[name][0]
return None
return query_params[name][0] if name in query_params else None

def _is_implicit_grant_flow(self, url: str) -> bool:
result = urlparse(url)
Expand Down
5 changes: 1 addition & 4 deletions tests/_async/test_client_with_auto_confirm_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ async def test_sign_in(client: AsyncGoTrueClient):
async def test_sign_in_with_the_wrong_password(client: AsyncGoTrueClient):
expected_error_message = "Invalid login credentials"
try:
await client.sign_in(
email=email,
password=password + "2",
)
await client.sign_in(email=email, password=f"{password}2")
assert False
except APIError as e:
assert e.msg == expected_error_message
Expand Down
5 changes: 1 addition & 4 deletions tests/_sync/test_client_with_auto_confirm_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ def test_sign_in(client: SyncGoTrueClient):
def test_sign_in_with_the_wrong_password(client: SyncGoTrueClient):
expected_error_message = "Invalid login credentials"
try:
client.sign_in(
email=email,
password=password + "2",
)
client.sign_in(email=email, password=f"{password}2")
assert False
except APIError as e:
assert e.msg == expected_error_message
Expand Down

0 comments on commit 9e4a1f2

Please sign in to comment.