Skip to content

Commit

Permalink
Implement __hash__ on Digest class
Browse files Browse the repository at this point in the history
In Python 3, if a class defines __eq__() but not __hash__(), its
instances will not be usable as items in hashable collections (e.g sets).
  • Loading branch information
kleesc committed Jan 24, 2020
1 parent bf10095 commit b77fe47
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions digest/digest_tools.py
Expand Up @@ -25,6 +25,9 @@ def __str__(self):
def __eq__(self, rhs):
return isinstance(rhs, Digest) and str(self) == str(rhs)

def __hash__(self):
return hash((self._hash_alg, self._hash_bytes))

@staticmethod
def parse_digest(digest):
""" Returns the digest parsed out to its components. """
Expand Down

0 comments on commit b77fe47

Please sign in to comment.