Fixed the _contains__ dunder method
This commit is contained in:
parent
c45acc07d8
commit
439eb85652
|
@ -2,7 +2,7 @@
|
|||
|
||||
class TTLItem(object):
|
||||
|
||||
"""An abstraction layer over a queue item. This class is meant
|
||||
"""An abstraction layer over a TTLed item. This class is meant
|
||||
to be used internally and should not be instantiated directly
|
||||
|
||||
:param obj: The object to be wrapped
|
||||
|
@ -21,3 +21,8 @@ class TTLItem(object):
|
|||
if isinstance(other, TTLItem):
|
||||
other = other.obj
|
||||
return self.obj.__lt__(other)
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, TTLItem):
|
||||
other = other.obj
|
||||
return self.obj.__eq__(other)
|
||||
|
|
|
@ -114,7 +114,7 @@ class TTLQueue:
|
|||
def __contains__(self, item):
|
||||
"""Implements item in self"""
|
||||
|
||||
return self._queue.__contains__(item)
|
||||
return self._queue.__contains__(TTLitem(item, None))
|
||||
|
||||
class TTLStack:
|
||||
"""A stack (LIFO) with per-item time to live (TTL)
|
||||
|
@ -220,7 +220,7 @@ class TTLStack:
|
|||
def __contains__(self, item):
|
||||
"""Implements item in self"""
|
||||
|
||||
return self._stack.__contains__(item)
|
||||
return self._stack.__contains__(TTLItem(item, None))
|
||||
|
||||
|
||||
class TTLHeap(TTLQueue):
|
||||
|
@ -272,7 +272,7 @@ class TTLHeap(TTLQueue):
|
|||
def __contains__(self, item):
|
||||
"""Implements item in self"""
|
||||
|
||||
return self._queue.__contains__(item)
|
||||
return self._queue.__contains__(TTLitem(item, None))
|
||||
|
||||
def put(self, element, ttl: int = 0):
|
||||
"""Puts an item onto the queue
|
||||
|
|
Loading…
Reference in New Issue