From e3400ec5a25b5163293adcb0d007d0a8cae53a4c Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Thu, 18 Sep 2014 15:29:34 +0000 Subject: 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. --- morphlib/morphology.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'morphlib/morphology.py') 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) -- cgit v1.2.1