Skip to content

Commit 33c26d9

Browse files
committed
Merge pull request #17 from ihmpdcc/pr-16
Pull request from @schwager-hsph merged along with another commit.
2 parents 602bfa7 + 8f47f2f commit 33c26d9

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

CHANGES

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
cutlass 0.6
2+
3+
* Added convenience methods to make objects hashable, equal-able.
4+
Contributed by schwager-hsph@github.com.
5+
6+
- Victor <victor73@github.com> Thu, l9 Nov 2015 12:00:00 -0400
7+
18
cutlass 0.5
29

310
* Fixed requirement for both 'part_of' and 'subset_of' linkages

cutlass/Base.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,31 @@ def delete(self):
271271
"Reason: %s" % visit_node_id, e.strerror)
272272

273273
return success
274+
275+
276+
def __str__(self):
277+
_id = "no ID" if not self._id else self._id[-8:]
278+
name = None
279+
for attr in ("_name", "_rand_subject_id", "_date", "_local_file"):
280+
if hasattr(self, attr):
281+
name = getattr(self, attr)
282+
break
283+
if name:
284+
return "<{} `{}' ({})>".format(self.__class__.__name__, name, _id)
285+
else:
286+
return "<{} ({})>".format(self.__class__.__name__, _id)
287+
288+
289+
__repr__ = __str__
290+
291+
292+
def __hash__(self):
293+
if not self._id:
294+
raise TypeError("unhashable; must have ID: '{}')".format(str(self)))
295+
return hash(self._id)
296+
297+
298+
def __eq__(self, other):
299+
if self._id and other._id:
300+
return self._id == other._id
301+
return False

0 commit comments

Comments
 (0)