Adding some more new lints (#393)

Enable `UP` and `TRY` lint
This commit is contained in:
Marcel Hellwig
2026-02-01 18:04:15 +01:00
committed by GitHub
parent 311e625eee
commit 96b84d45db
33 changed files with 345 additions and 340 deletions

View File

@@ -1,7 +1,8 @@
import logging
import os
from collections.abc import Generator
from contextvars import ContextVar
from typing import Annotated, Any, Generator, Optional
from typing import Annotated
from fastapi import Depends
from sqlalchemy import create_engine
@@ -15,8 +16,8 @@ log = logging.getLogger(__name__)
Base = declarative_base()
engine: Optional[Engine] = None
SessionLocal: Optional[sessionmaker] = None
engine: Engine | None = None
SessionLocal: sessionmaker | None = None
def build_db_url(
@@ -83,7 +84,7 @@ def get_engine() -> Engine:
return engine
def get_session() -> Generator[Session, Any, None]:
def get_session() -> Generator[Session]:
if SessionLocal is None:
msg = "Session factory not initialized. Call init_engine(...) first."
raise RuntimeError(msg)
@@ -91,9 +92,9 @@ def get_session() -> Generator[Session, Any, None]:
try:
yield db
db.commit()
except Exception as e:
except Exception:
db.rollback()
log.critical(f"error occurred: {e}")
log.critical("", exc_info=True)
raise
finally:
db.close()