Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update .pre-commit-config.yaml #487

Merged
merged 8 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: '^.*\.(md|MD)$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand All @@ -10,7 +10,7 @@ repos:
args: ["--fix=lf"]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
args:
Expand All @@ -25,7 +25,7 @@ repos:
]

- repo: https://github.com/myint/autoflake.git
rev: v2.2.1
rev: v2.3.1
hooks:
- id: autoflake
args:
Expand All @@ -36,18 +36,18 @@ repos:
]

- repo: https://github.com/ambv/black
rev: 22.6.0
rev: 24.4.0
hooks:
- id: black

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
rev: v3.15.2
hooks:
- id: pyupgrade
args: ["--py37-plus", "--keep-runtime-typing"]

- repo: https://github.com/commitizen-tools/commitizen
rev: v2.32.1
rev: v3.22.0
hooks:
- id: commitizen
stages: [commit-msg]
8 changes: 5 additions & 3 deletions supabase_auth/_async/gotrue_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ async def list_users(self, page: int = None, per_page: int = None) -> List[User]
"GET",
"admin/users",
query={"page": page, "per_page": per_page},
xform=lambda data: [model_validate(User, user) for user in data["users"]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Consider the impact of changing lambda expressions to include additional parentheses.

This change might improve readability by making the structure of the lambda function clearer, but it could also introduce unnecessary complexity if not widely adopted across the project.

Suggested change
xform=lambda data: [model_validate(User, user) for user in data["users"]]
xform=lambda data: [
model_validate(User, user) for user in data.get("users", [])
]

if "users" in data
else [],
xform=lambda data: (
[model_validate(User, user) for user in data["users"]]
if "users" in data
else []
),
)

async def get_user_by_id(self, uid: str) -> UserResponse:
Expand Down
9 changes: 3 additions & 6 deletions supabase_auth/_async/gotrue_base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ async def _request(
body: Union[Any, None] = None,
no_resolve_json: Literal[False] = False,
xform: Callable[[Any], T],
) -> T:
... # pragma: no cover
) -> T: ... # pragma: no cover

@overload
async def _request(
Expand All @@ -62,8 +61,7 @@ async def _request(
body: Union[Any, None] = None,
no_resolve_json: Literal[True],
xform: Callable[[Response], T],
) -> T:
... # pragma: no cover
) -> T: ... # pragma: no cover

@overload
async def _request(
Expand All @@ -77,8 +75,7 @@ async def _request(
query: Union[Dict[str, str], None] = None,
body: Union[Any, None] = None,
no_resolve_json: bool = False,
) -> None:
... # pragma: no cover
) -> None: ... # pragma: no cover

async def _request(
self,
Expand Down
9 changes: 3 additions & 6 deletions supabase_auth/_async/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@

class AsyncSupportedStorage(ABC):
@abstractmethod
async def get_item(self, key: str) -> Optional[str]:
... # pragma: no cover
async def get_item(self, key: str) -> Optional[str]: ... # pragma: no cover

@abstractmethod
async def set_item(self, key: str, value: str) -> None:
... # pragma: no cover
async def set_item(self, key: str, value: str) -> None: ... # pragma: no cover

@abstractmethod
async def remove_item(self, key: str) -> None:
... # pragma: no cover
async def remove_item(self, key: str) -> None: ... # pragma: no cover


class AsyncMemoryStorage(AsyncSupportedStorage):
Expand Down
8 changes: 5 additions & 3 deletions supabase_auth/_sync/gotrue_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ def list_users(self, page: int = None, per_page: int = None) -> List[User]:
"GET",
"admin/users",
query={"page": page, "per_page": per_page},
xform=lambda data: [model_validate(User, user) for user in data["users"]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Assess the addition of parentheses in lambda functions for consistency.

While this might enhance readability in some contexts, ensure it aligns with the coding standards and practices within the rest of the project.

Suggested change
xform=lambda data: [model_validate(User, user) for user in data["users"]]
xform=lambda data: [model_validate(User, user) for user in data.get("users", [])]

if "users" in data
else [],
xform=lambda data: (
[model_validate(User, user) for user in data["users"]]
if "users" in data
else []
),
)

def get_user_by_id(self, uid: str) -> UserResponse:
Expand Down
9 changes: 3 additions & 6 deletions supabase_auth/_sync/gotrue_base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def _request(
body: Union[Any, None] = None,
no_resolve_json: Literal[False] = False,
xform: Callable[[Any], T],
) -> T:
... # pragma: no cover
) -> T: ... # pragma: no cover

@overload
def _request(
Expand All @@ -62,8 +61,7 @@ def _request(
body: Union[Any, None] = None,
no_resolve_json: Literal[True],
xform: Callable[[Response], T],
) -> T:
... # pragma: no cover
) -> T: ... # pragma: no cover

@overload
def _request(
Expand All @@ -77,8 +75,7 @@ def _request(
query: Union[Dict[str, str], None] = None,
body: Union[Any, None] = None,
no_resolve_json: bool = False,
) -> None:
... # pragma: no cover
) -> None: ... # pragma: no cover

def _request(
self,
Expand Down
9 changes: 3 additions & 6 deletions supabase_auth/_sync/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@

class SyncSupportedStorage(ABC):
@abstractmethod
def get_item(self, key: str) -> Optional[str]:
... # pragma: no cover
def get_item(self, key: str) -> Optional[str]: ... # pragma: no cover

@abstractmethod
def set_item(self, key: str, value: str) -> None:
... # pragma: no cover
def set_item(self, key: str, value: str) -> None: ... # pragma: no cover

@abstractmethod
def remove_item(self, key: str) -> None:
... # pragma: no cover
def remove_item(self, key: str) -> None: ... # pragma: no cover


class SyncMemoryStorage(SyncSupportedStorage):
Expand Down
4 changes: 2 additions & 2 deletions supabase_auth/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def parse_sso_response(data: Any) -> SSOResponse:

def get_error_message(error: Any) -> str:
props = ["msg", "message", "error_description", "error"]
filter = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Review the necessity of changing the lambda function to a single line.

This change might slightly reduce readability by compacting the logic into a single line. Consider if the benefits of this change outweigh the potential decrease in clarity.

lambda prop: prop in error if isinstance(error, dict) else hasattr(error, prop)
filter = lambda prop: (
prop in error if isinstance(error, dict) else hasattr(error, prop)
)
return next((error[prop] for prop in props if filter(prop)), str(error))

Expand Down