[docs]@law_definitiondefreflexive_law(first:_EqualType,)->None:"""Value should be equal to itself."""assertfirst.equals(first)
[docs]@law_definitiondefsymmetry_law(first:_EqualType,second:_EqualType,)->None:"""If ``A == B`` then ``B == A``."""assertfirst.equals(second)==second.equals(first)
[docs]@law_definitiondeftransitivity_law(first:_EqualType,second:_EqualType,third:_EqualType,)->None:"""If ``A == B`` and ``B == C`` then ``A == C``."""# We use this notation, because `first` might be equal to `third`,# but not to `second`. Example: Some(1), Some(2), Some(1)iffirst.equals(second)andsecond.equals(third):assertfirst.equals(third)
[docs]classEquable(Lawful['Equable']):""" Interface for types that can be compared with real values. Not all types can, because some don't have the value at a time: - ``Future`` has to be awaited to get the value - ``Reader`` has to be called to get the value """__slots__=()_laws:ClassVar[Sequence[Law]]=(Law1(_LawSpec.reflexive_law),Law2(_LawSpec.symmetry_law),Law3(_LawSpec.transitivity_law),)
[docs]@abstractmethoddefequals(self:_EqualType,other:_EqualType)->bool:"""Type-safe equality check for values of the same type."""