[pypy-commit] pypy py3.5: (plan_rich, arigo) Tweak W_ReverseSeqIter
arigo
pypy.commits at gmail.com
Tue Oct 11 13:36:12 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r87717:368ee986dc8e
Date: 2016-10-11 19:35 +0200
http://bitbucket.org/pypy/pypy/changeset/368ee986dc8e/
Log: (plan_rich, arigo) Tweak W_ReverseSeqIter
diff --git a/pypy/module/_pickle_support/maker.py b/pypy/module/_pickle_support/maker.py
--- a/pypy/module/_pickle_support/maker.py
+++ b/pypy/module/_pickle_support/maker.py
@@ -48,7 +48,7 @@
def reverseseqiter_new(space, w_seq, w_index):
w_rev = instantiate(W_ReverseSeqIterObject)
if space.is_w(w_seq, space.w_None):
- w_rev.w_seq = None
+ w_rev.w_seq = space.w_None
w_rev.index = -1
else:
w_rev.w_seq = w_seq
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
@@ -150,6 +150,9 @@
class W_ReverseSeqIterObject(W_Root):
def __init__(self, space, w_seq, index=-1):
+ # w_seq is normally a list object, but can be space.w_None after
+ # the iterator is exhausted or after a reduce(). In that case,
+ # self.index == -1.
self.w_seq = w_seq
self.index = space.len_w(w_seq) + index
@@ -158,8 +161,7 @@
w_mod = space.getbuiltinmodule('_pickle_support')
mod = space.interp_w(MixedModule, w_mod)
new_inst = mod.get('reverseseqiter_new')
- w_seq = space.w_None if self.w_seq is None else self.w_seq
- tup = [w_seq, space.wrap(self.index)]
+ tup = [self.w_seq, space.wrap(self.index)]
# note that setstate is not called, because this setup already sets the index
return space.newtuple([new_inst, space.newtuple(tup)])
@@ -173,7 +175,7 @@
def descr_length_hint(self, space):
length = self.index + 1
- if self.w_seq is None or space.len_w(self.w_seq) < length:
+ if self.w_seq is space.w_None or space.len_w(self.w_seq) < length:
length = 0
return space.wrap(length)
@@ -198,7 +200,7 @@
# Done
self.index = -1
- self.w_seq = None
+ self.w_seq = space.w_None
raise OperationError(space.w_StopIteration, space.w_None)
W_ReverseSeqIterObject.typedef = TypeDef(
More information about the pypy-commit
mailing list