Source code for ascetic_ddd.seedwork.domain.aggregate.hashable_entity
from abc import ABCMeta, abstractmethod
from ascetic_ddd.specification.domain.interfaces import IEqualOperand
from ascetic_ddd.seedwork.domain.aggregate.interfaces import IHashable
__all__ = ("HashableEntity",)
[docs]
class HashableEntity(IHashable, metaclass=ABCMeta):
@property
@abstractmethod
def id(self) -> IEqualOperand: # noqa: A003 # id shadowing Python builtin
"""
See also IsTransient
https://github.com/dotnet-architecture/eShopOnContainers/blob/dev/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs#L42.
"""
raise NotImplementedError
def __hash__(self):
id_ = self.id
if id_ is None:
raise TypeError("Model instances without primary key value are unhashable")
return hash(id_)
def __eq__(self, other: IEqualOperand):
assert isinstance(other, HashableEntity)
return self.id == other.id