diff --git a/backend/src/kwai/core/db/table.py b/backend/src/kwai/core/db/table.py index 144cfd70..0cbcf393 100644 --- a/backend/src/kwai/core/db/table.py +++ b/backend/src/kwai/core/db/table.py @@ -1,15 +1,13 @@ """Module for the table decorator.""" from dataclasses import fields, is_dataclass -from typing import Any, Callable, Generic, TypeVar +from typing import Any, Callable from sql_smith.functions import alias from sql_smith.functions import field as sql_field -T = TypeVar("T", bound=Callable) - -class Table(Generic[T]): +class Table[T: Callable]: """Represent a table in the database. With this class a table row can be transformed into a dataclass. It can also diff --git a/backend/src/kwai/core/domain/use_case.py b/backend/src/kwai/core/domain/use_case.py index 1ccbbd08..52d6e092 100644 --- a/backend/src/kwai/core/domain/use_case.py +++ b/backend/src/kwai/core/domain/use_case.py @@ -1,7 +1,8 @@ """Module for defining common classes, functions, ... for use cases.""" + from abc import ABC, abstractmethod from dataclasses import dataclass -from typing import AsyncIterator, Generic, NamedTuple, TypeVar +from typing import AsyncIterator, NamedTuple class UseCaseResult(ABC): @@ -13,11 +14,8 @@ def to_message(self) -> str: raise NotImplementedError -T = TypeVar("T") - - @dataclass(kw_only=True, frozen=True, slots=True) -class NotFoundResult(UseCaseResult, Generic[T]): +class NotFoundResult[T](UseCaseResult): """A result that indicates that an entity was not found.""" entity_name: str @@ -28,7 +26,7 @@ def to_message(self) -> str: @dataclass(kw_only=True, frozen=True, slots=True) -class EntitiesResult(UseCaseResult, Generic[T]): +class EntitiesResult[T](UseCaseResult): """A result that returns an iterator for entities and the number of entities.""" count: int @@ -39,7 +37,7 @@ def to_message(self) -> str: @dataclass(kw_only=True, frozen=True, slots=True) -class EntityResult(UseCaseResult, Generic[T]): +class EntityResult[T](UseCaseResult): """A result that returns an entity.""" entity: T diff --git a/backend/src/kwai/core/domain/value_objects/identifier.py b/backend/src/kwai/core/domain/value_objects/identifier.py index 0e1008a9..02c1b092 100644 --- a/backend/src/kwai/core/domain/value_objects/identifier.py +++ b/backend/src/kwai/core/domain/value_objects/identifier.py @@ -1,11 +1,9 @@ """Module that defines identifiers.""" -from abc import ABC, abstractmethod -from typing import Generic, TypeVar -T = TypeVar("T") +from abc import ABC, abstractmethod -class Identifier(ABC, Generic[T]): +class Identifier[T](ABC): """Abstract and generic class for an identifier.""" def __init__(self, id_: T):