Skip to content

Commit

Permalink
♻️ Refactor import statements and clean up docstrings for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 committed Dec 8, 2024
1 parent afb9341 commit 52be8d7
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 24 deletions.
3 changes: 1 addition & 2 deletions authx/_internal/_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@


class _CallbackHandler(Generic[T]):
"""
Base class for callback handlers in AuthX.
"""Base class for callback handlers in AuthX.
Args:
Generic (T): Model type
Expand Down
3 changes: 1 addition & 2 deletions authx/_internal/_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class MemoryIO:
"""

def __init__(self) -> None:
"""
Initialize an instance of MemoryIO.
"""Initialize an instance of MemoryIO.
Creates a dictionary to store the session data.
"""
Expand Down
8 changes: 2 additions & 6 deletions authx/_internal/_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@


class SignatureSerializer:
"""
A class that implements a URL-safe timed serializer.
"""
"""A class that implements a URL-safe timed serializer."""

def __init__(self, secret_key: str, expired_in: int = 0) -> None:
"""
Initialize the serializer with a secret key and an optional expiration time.
"""
"""Initialize the serializer with a secret key and an optional expiration time."""
self.ser = URLSafeTimedSerializer(secret_key)
self.expired_in = expired_in

Expand Down
3 changes: 2 additions & 1 deletion authx/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Sequence
from datetime import timedelta
from typing import List, Optional, Sequence
from typing import List, Optional

from jwt.algorithms import get_default_algorithms, requires_cryptography
from pydantic import Field
Expand Down
3 changes: 1 addition & 2 deletions authx/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import contextlib
import datetime
from collections.abc import Awaitable, Coroutine
from typing import (
Any,
Awaitable,
Callable,
Coroutine,
Dict,
Literal,
Optional,
Expand Down
5 changes: 3 additions & 2 deletions authx/schema.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import datetime
import sys
from collections.abc import Sequence
from hmac import compare_digest
from typing import Any, Dict, List, Optional, Sequence, Union
from typing import Any, Dict, List, Optional, Union

from pydantic import BaseModel, Field, ValidationError
from pydantic.version import VERSION as PYDANTIC_VERSION

if sys.version_info >= (3, 8): # pragma: no cover
from typing import Set # pragma: no cover
else:
from typing_extensions import Set # pragma: no cover
from typing import Set # pragma: no cover

from authx._internal._utils import get_now, get_now_ts, get_uuid
from authx.exceptions import (
Expand Down
3 changes: 2 additions & 1 deletion authx/token.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
from typing import Any, Dict, List, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Dict, List, Optional, Union

import jwt

Expand Down
3 changes: 2 additions & 1 deletion authx/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import sys
from typing import Callable, Literal, Optional, Sequence, TypeVar, Union
from collections.abc import Sequence
from typing import Callable, Literal, Optional, TypeVar, Union

if sys.version_info >= (3, 10): # pragma: no cover
from typing import ParamSpecKwargs # pragma: no cover
Expand Down
2 changes: 0 additions & 2 deletions tests/app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
@pytest.fixture(scope="function")
def config():
"""Fixture for AuthX Configuration"""

return AuthXConfig(
JWT_SECRET_KEY="secret",
JWT_TOKEN_LOCATION=["headers", "json", "query", "cookies"],
Expand All @@ -28,7 +27,6 @@ def config():
@pytest.fixture(scope="function")
def api(config: AuthXConfig):
"""Fixture for FastAPI TestClient"""

app, security = init_app(config=config)
create_protected_routes(app, security)
create_token_routes(app, security)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import Any, Coroutine, Dict, List
from collections.abc import Coroutine
from typing import Any, Dict, List

import pytest
from fastapi import Request
Expand Down
4 changes: 0 additions & 4 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class SecuritiesTuple(NamedTuple):

def init_app(config: Optional[AuthXConfig] = None) -> "tuple[FastAPI, AuthX]":
"""Initialize FastAPI app and AuthX instance."""

app = FastAPI()
security = AuthX(config=(config or AuthXConfig()))

Expand All @@ -29,7 +28,6 @@ def init_app(config: Optional[AuthXConfig] = None) -> "tuple[FastAPI, AuthX]":

def create_securities(security: AuthX) -> SecuritiesTuple:
"""Create a named tuple with all AuthX dependencies."""

return SecuritiesTuple(
access_token_headers=Depends(
security.token_required(
Expand Down Expand Up @@ -170,7 +168,6 @@ async def _protected_fresh_route():

def create_blocklist_routes(app: FastAPI, security: AuthX) -> None:
"""Create routes to test AuthX dependencies."""

BLOCKLIST = set()

@security.set_callback_token_blocklist
Expand All @@ -195,7 +192,6 @@ async def _blocklist_access_route(

def create_subject_routes(app: FastAPI, security: AuthX) -> None:
"""Create routes to test AuthX dependencies."""

USER_DB = {
"test": {"uid": "test", "email": "test@test.com"},
"foo": {"uid": "foo", "email": "foo@bar.com"},
Expand Down

0 comments on commit 52be8d7

Please sign in to comment.