Skip to content

Commit

Permalink
ref: change ModelManager type params to PEP 695
Browse files Browse the repository at this point in the history
  • Loading branch information
e-kondr01 committed Sep 13, 2024
1 parent d0fde0d commit 72533c6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions fastapi_sqlalchemy_toolkit/model_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ruff: noqa: UP006
from collections.abc import Callable, Iterable
from typing import Any, Generic, List, TypeVar # noqa: UP035
from typing import Any, List # noqa: UP035

from fastapi import HTTPException, status
from fastapi_pagination.bases import BasePage
Expand Down Expand Up @@ -30,19 +30,20 @@

from .filters import null_query_values

ModelT = TypeVar("ModelT", bound=DeclarativeBase)
CreateSchemaT = TypeVar("CreateSchemaT", bound=BaseModel)
UpdateSchemaT = TypeVar("UpdateSchemaT", bound=BaseModel)
ModelDict = dict[str, Any]


def sqlalchemy_model_to_dict(model: ModelT) -> dict:
def sqlalchemy_model_to_dict(model: DeclarativeBase) -> dict:
db_obj_dict = model.__dict__.copy()
del db_obj_dict["_sa_instance_state"]
return db_obj_dict


class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
class ModelManager[
ModelT: DeclarativeBase,
CreateSchemaT: BaseModel,
UpdateSchemaT: BaseModel,
]:
def __init__(
self,
model: type[ModelT],
Expand Down

0 comments on commit 72533c6

Please sign in to comment.