Source code for src.share_kernel.domain.base_entity

import uuid


[docs] class Entity: """ Base pour toutes les entités. L'égalité est basée sur l'identité (id), pas les attributs. """ def __init__(self, entity_id: uuid.UUID | None = None): self._id: uuid.UUID = entity_id or uuid.uuid4() @property def id(self) -> uuid.UUID: return self._id def __eq__(self, other: object) -> bool: if not isinstance(other, self.__class__): return False return self._id == other._id def __hash__(self) -> int: return hash(self._id) def __repr__(self) -> str: return f"<{self.__class__.__name__} id={self._id}>"