[pypy-commit] pypy stdlib-2.7.12: handle more cases, IndexError in builtins reversed
pjenvey
pypy.commits at gmail.com
Sun Oct 9 01:23:25 EDT 2016
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: stdlib-2.7.12
Changeset: r87651:512d0d073a9c
Date: 2016-10-08 22:22 -0700
http://bitbucket.org/pypy/pypy/changeset/512d0d073a9c/
Log: handle more cases, IndexError in builtins reversed
diff --git a/pypy/interpreter/test/test_zzpickle_and_slow.py b/pypy/interpreter/test/test_zzpickle_and_slow.py
--- a/pypy/interpreter/test/test_zzpickle_and_slow.py
+++ b/pypy/interpreter/test/test_zzpickle_and_slow.py
@@ -398,11 +398,17 @@
def test_pickle_reversed_stopped(self):
import pickle
- iter = reversed(())
- raises(StopIteration, iter.next)
- pckl = pickle.dumps(iter)
- result = pickle.loads(pckl)
- raises(StopIteration, result.next)
+ class IE(object):
+ def __len__(self):
+ return 1
+ def __getitem__(self, i):
+ raise IndexError
+ for it in (), IE():
+ iter = reversed(it)
+ raises(StopIteration, iter.next)
+ pckl = pickle.dumps(iter)
+ result = pickle.loads(pckl)
+ raises(StopIteration, result.next)
def test_pickle_enum(self):
import pickle
diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -363,8 +363,13 @@
try:
w_item = space.getitem(self.w_sequence, w_index)
except OperationError as e:
- if not e.match(space, space.w_StopIteration):
+ # Done
+ self.remaining = -1
+ self.w_sequence = None
+ if not (e.match(space, space.w_IndexError) or
+ e.match(space, space.w_StopIteration)):
raise
+ raise OperationError(space.w_StopIteration, space.w_None)
else:
self.remaining -= 1
return w_item
diff --git a/pypy/objspace/std/iterobject.py b/pypy/objspace/std/iterobject.py
--- a/pypy/objspace/std/iterobject.py
+++ b/pypy/objspace/std/iterobject.py
@@ -143,8 +143,12 @@
try:
w_item = space.getitem(self.w_seq, w_index)
except OperationError as e:
+ # Done
+ self.index = -1
+ self.w_seq = None
if not e.match(space, space.w_IndexError):
raise
+ raise OperationError(space.w_StopIteration, space.w_None)
else:
self.index -= 1
return w_item
More information about the pypy-commit
mailing list