diff options
author | Richard Maw <richard.maw@gmail.com> | 2014-09-18 15:29:34 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@gmail.com> | 2014-09-19 12:43:26 +0000 |
commit | e3400ec5a25b5163293adcb0d007d0a8cae53a4c (patch) | |
tree | 21809ec87b4ecfb64d8866dabc40d07780532289 | |
parent | 960c84e111111d0b203d6aa16f23552cc9978c99 (diff) | |
download | morph-e3400ec5a25b5163293adcb0d007d0a8cae53a4c.tar.gz |
Make morphologies hashable
I need to be able to deduplicate a list of morphologies. Putting it in a
set is the easiest way, but it needs to be hashable.
It's not included in dicts by default, since they're stored by
reference, and you can change them while they're in the dict, so the
hash value can change.
I don't need to deduplicate morphologies by their contents, just by
reference though, so using `id` as the hash function is sufficient.
-rw-r--r-- | morphlib/morphology.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/morphlib/morphology.py b/morphlib/morphology.py index 01f332c6..9bd9bb5b 100644 --- a/morphlib/morphology.py +++ b/morphlib/morphology.py @@ -46,3 +46,6 @@ class Morphology(UserDict.IterableUserDict): @property def needs_artifact_metadata_cached(self): # pragma: no cover return self.get('kind') == 'stratum' + + def __hash__(self): + return id(self) |