Skip to content

Commit

Permalink
♻️ Refactor code to use the walrus operator for PYDANTIC_V2 check
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 committed Oct 20, 2024
1 parent 40d0a98 commit b28b5cc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
5 changes: 1 addition & 4 deletions authx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
TokenLocations,
)

PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")


if PYDANTIC_V2:
if PYDANTIC_V2 := PYDANTIC_VERSION.startswith("2."):
from pydantic_settings import BaseSettings # pragma: no cover
else:
from pydantic import BaseSettings # type: ignore # pragma: no cover
Expand Down
4 changes: 1 addition & 3 deletions authx/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
TokenType,
)

PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")

if PYDANTIC_V2:
if PYDANTIC_V2 := PYDANTIC_VERSION.startswith("2."):
from pydantic import ConfigDict, field_validator # pragma: no cover
else:
from pydantic import Extra, validator # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion authx/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create_token(
if data:
jwt_claims.update(data)

payload = {**additional_claims, **jwt_claims}
payload = additional_claims | jwt_claims

return jwt.encode(payload=payload, key=key, algorithm=algorithm, headers=headers)

Expand Down

0 comments on commit b28b5cc

Please sign in to comment.