Skip to content

Commit

Permalink
Docstrings for Comparable.
Browse files Browse the repository at this point in the history
  • Loading branch information
lumip committed May 6, 2016
1 parent caf7100 commit 6085724
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion qctoolkit/comparable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@


class Comparable(metaclass=ABCMeta):
"""An object that can be queried for equality with other Comparable object."""

@abstractproperty
def _compare_key(self) -> Any:
"""Return a unique key used in comparison and hashing operations."""
"""Return a unique key used in comparison and hashing operations.
The key must describe the essential properties of the object. Two objects are equal iff their keys are identical.
"""

def __hash__(self) -> int:
"""Returns a hash value of the comparable object."""
return hash(self._compare_key)

def __eq__(self, other: Any) -> bool:
"""True, if other is equal to self."""
return isinstance(other, self.__class__) and self._compare_key == other._compare_key

def __ne__(self, other: Any) -> bool:
"""True, if other is not equal to self."""
return not self == other

0 comments on commit 6085724

Please sign in to comment.