Skip to content

Commit bfecf81

Browse files
committed
fix deque __contains__
1 parent 3be7ac4 commit bfecf81

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

graalpython/lib-graalpython/_collections.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,12 @@ def __repr__(self):
304304
maxlen_repr = ', maxlen=%d' % (self.maxlen,)
305305
return 'deque(%s%s)' % (list_repr, maxlen_repr)
306306

307-
def __compare__(self, w_other, op):
308-
if not isinstance(w_other, deque):
307+
def __compare__(self, other, op):
308+
if not isinstance(other, deque):
309309
return NotImplemented
310310

311-
def _next_or_none(_iter):
312-
try:
313-
return next(_iter)
314-
except StopIteration:
315-
return None
316-
317311
it1 = iter(self)
318-
it2 = iter(w_other)
312+
it2 = iter(other)
319313
while True:
320314
x1 = _next_or_none(it1)
321315
x2 = _next_or_none(it2)
@@ -349,6 +343,12 @@ def _next_or_none(_iter):
349343
return x1 >= x2
350344
assert False, "bad value for op"
351345

346+
def __contains__(self, item):
347+
for itm in self:
348+
if itm == item:
349+
return True
350+
return False
351+
352352
def __lt__(self, other):
353353
return self.__compare__(other, 'lt')
354354

@@ -438,6 +438,13 @@ def maxlen(self):
438438
return self._maxlen
439439

440440

441+
def _next_or_none(_iter):
442+
try:
443+
return next(_iter)
444+
except StopIteration:
445+
return None
446+
447+
441448
class _DequeIter(object):
442449
def __init__(self, dq):
443450
self._deque = dq

0 commit comments

Comments
 (0)