20 lines
456 B
Python
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))
|