Files
onion-arch/app/domain/shared/base_entity.py
2026-01-30 16:34:56 +03:00

20 lines
456 B
Python

from __future__ import annotations
from dataclasses import dataclass
from typing import Generic, TypeVar
TId = TypeVar("TId")
@dataclass(eq=False)
class Entity(Generic[TId]):
id: TId
def __eq__(self, other: object) -> bool:
if not isinstance(other, Entity):
return False
return self.id == other.id and self.__class__ is other.__class__
def __hash__(self) -> int:
return hash((self.__class__, self.id))