Skip to content

Commit e281176

Browse files
committed
duck test linked list also in __hash__
1 parent 24e2362 commit e281176

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

unpythonic/llist.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ def __eq__(self, other):
193193
return self.car == other.car and self.cdr == other.cdr
194194
return False
195195
def __hash__(self):
196-
return hash((hash(self.car), hash(self.cdr)))
196+
try: # duck test linked list
197+
tpl = tuple(self)
198+
except TypeError:
199+
tpl = (self.car, self.cdr)
200+
return hash(tpl)
197201

198202
def _car(x):
199203
return _typecheck(x).car

0 commit comments

Comments
 (0)