Skip to content

Commit

Permalink
fix sqalalchemy 2+ typing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenstr committed Nov 26, 2024
1 parent f8106a3 commit b2b4dcc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion jwthenticator/keys.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import

from typing import Optional
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from hashlib import sha512
from uuid import UUID

Expand Down
2 changes: 1 addition & 1 deletion jwthenticator/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import random
from os import environ
from string import ascii_letters
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from hashlib import sha512
from uuid import uuid4

Expand Down
14 changes: 6 additions & 8 deletions jwthenticator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import asyncio
from os.path import isfile
from typing import Any, Dict, Tuple, Optional
from typing import Any, Dict, Tuple, Optional, Type
from urllib.parse import urlparse

from datetime import datetime, timezone
from jwt.utils import base64url_encode
from Cryptodome.PublicKey import RSA
from Cryptodome.Hash import SHA1
try:
from sqlalchemy.ext.asyncio import async_sessionmaker
except ImportError:
from sqlalchemy.orm import sessionmaker as async_sessionmaker # type:ignore
from sqlalchemy.ext.asyncio import async_sessionmaker
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, AsyncEngine
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.pool import NullPool

from jwthenticator.consts import RSA_KEY_STRENGTH, RSA_PUBLIC_KEY, RSA_PRIVATE_KEY, RSA_PUBLIC_KEY_PATH, RSA_PRIVATE_KEY_PATH
Expand Down Expand Up @@ -105,11 +103,11 @@ def fix_url_path(url: str) -> str:
"""
return url if url.endswith("/") else url + "/"

async def create_base(engine: AsyncEngine, base: Any) -> None:
async def create_base(engine: AsyncEngine, base: Type[DeclarativeBase]) -> None:
async with engine.begin() as conn:
await conn.run_sync(base.metadata.create_all)

def create_async_session_factory(uri: str, base: Optional[Any] = None, **engine_kwargs: Dict[Any, Any]) -> Any:
def create_async_session_factory(uri: str, base: Optional[Type[DeclarativeBase]] = None, **engine_kwargs: Dict[Any, Any]) -> async_sessionmaker[AsyncSession]:
"""
:param uri: Database uniform resource identifier
:param base: Declarative SQLAlchemy class to base off table initialization
Expand All @@ -122,4 +120,4 @@ def create_async_session_factory(uri: str, base: Optional[Any] = None, **engine_
return async_sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)

def utcnow() -> datetime:
return datetime.now(timezone.utc)
return datetime.now(timezone.utc)

0 comments on commit b2b4dcc

Please sign in to comment.