Author: Mark Young <[email protected]>
Branch: 33_fix_itertools
Changeset: r84045:4608f2a4e438
Date: 2016-04-29 15:01 -0400
http://bitbucket.org/pypy/pypy/changeset/4608f2a4e438/
Log: Respond to review.
diff --git a/lib-python/3/test/test_itertools.py
b/lib-python/3/test/test_itertools.py
--- a/lib-python/3/test/test_itertools.py
+++ b/lib-python/3/test/test_itertools.py
@@ -4,7 +4,7 @@
from weakref import proxy
from decimal import Decimal
from fractions import Fraction
-import sys
+import sys, gc
import operator
import random
import copy
@@ -1204,7 +1204,8 @@
p = proxy(a)
self.assertEqual(getattr(p, '__class__'), type(b))
del a
- #self.assertRaises(ReferenceError, getattr, p, '__class__')
+ gc.collect()
+ self.assertRaises(ReferenceError, getattr, p, '__class__')
ans = list('abc')
long_ans = list(range(10000))
@@ -1569,6 +1570,7 @@
'Test multiple tiers of iterators'
return chain(map(lambda x:x, R(Ig(G(seqn)))))
+
class TestVariousIteratorArgs(unittest.TestCase):
def test_accumulate(self):
diff --git a/pypy/module/itertools/interp_itertools.py
b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -1,5 +1,5 @@
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
from rpython.rlib import jit
@@ -922,15 +922,14 @@
state = self.space.unpackiterable(w_state)
num_args = len(state)
if num_args != 2:
- raise OperationError(self.space.w_TypeError,
- self.space.wrap("function takes exactly 2
arguments "
- "(" + str(num_args) + " given)"))
+ raise oefmt(self.space.w_TypeError,
+ "function takes exactly 2 arguments (%d given)",
+ num_args)
w_iterator, w_chained_list = state
if not isinstance(w_chained_list, W_TeeChainedListNode):
- raise OperationError(
- self.space.w_TypeError,
- self.space.wrap("must be itertools._tee_dataobject, not " +
- self.space.type(w_chained_list).name))
+ raise oefmt(self.space.w_TypeError,
+ "must be itertools._tee_dataobject, not %s",
+ self.space.type(w_chained_list).name)
self.w_iterator = w_iterator
self.w_chained_list = w_chained_list
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
@@ -14,7 +14,7 @@
self.index = index
def getlength(self, space):
- if self.w_seq is None or space.is_w(self.w_seq, space.w_None):
+ if space.is_none(self.w_seq):
return space.wrap(0)
index = self.index
w_length = space.len(self.w_seq)
@@ -60,7 +60,7 @@
"""Sequence iterator implementation for general sequences."""
def descr_next(self, space):
- if self.w_seq is None or space.is_w(self.w_seq, space.w_None):
+ if space.is_none(self.w_seq):
raise OperationError(space.w_StopIteration, space.w_None)
try:
w_item = space.getitem(self.w_seq, space.wrap(self.index))
@@ -79,7 +79,7 @@
def descr_next(self, space):
from pypy.objspace.std.listobject import W_ListObject
w_seq = self.w_seq
- if w_seq is None or space.is_w(w_seq, space.w_None):
+ if space.is_none(w_seq):
raise OperationError(space.w_StopIteration, space.w_None)
assert isinstance(w_seq, W_ListObject)
index = self.index
@@ -129,7 +129,7 @@
return space.newtuple([new_inst, space.newtuple(tup)])
def descr_length_hint(self, space):
- if self.w_seq is None or space.is_w(self.w_seq, space.w_None):
+ if space.is_none(self.w_seq):
return space.wrap(0)
index = self.index + 1
w_length = space.len(self.w_seq)
@@ -147,9 +147,7 @@
return self
def descr_next(self, space):
- if (self.w_seq is None
- or space.is_w(self.w_seq, space.w_None)
- or self.index < 0):
+ if space.is_none(self.w_seq) or self.index < 0:
raise OperationError(space.w_StopIteration, space.w_None)
try:
w_item = space.getitem(self.w_seq, space.wrap(self.index))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit