init
This commit is contained in:
19
app/domain/shared/base_entity.py
Normal file
19
app/domain/shared/base_entity.py
Normal file
@@ -0,0 +1,19 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user