Author: Armin Rigo <[email protected]>
Branch: set-strategies
Changeset: r54006:f56f0aee6c50
Date: 2012-03-26 20:36 +0200
http://bitbucket.org/pypy/pypy/changeset/f56f0aee6c50/
Log: Extend the test to all types with strategies.
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1064,17 +1064,17 @@
init_defaults = [None]
def init__List(space, w_list, __args__):
- from pypy.objspace.std.tupleobject import W_TupleObject
+ from pypy.objspace.std.tupleobject import W_AbstractTupleObject
# this is on the silly side
w_iterable, = __args__.parse_obj(
None, 'list', init_signature, init_defaults)
w_list.clear(space)
if w_iterable is not None:
- if isinstance(w_iterable, W_ListObject):
+ if type(w_iterable) is W_ListObject:
w_iterable.copy_into(w_list)
return
- elif isinstance(w_iterable, W_TupleObject):
- W_ListObject(space, w_iterable.wrappeditems[:]).copy_into(w_list)
+ elif isinstance(w_iterable, W_AbstractTupleObject):
+ w_list.__init__(space, w_iterable.getitems_copy())
return
intlist = space.listview_int(w_iterable)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -25,7 +25,6 @@
from pypy.objspace.std.objectobject import W_ObjectObject
from pypy.objspace.std.ropeobject import W_RopeObject
from pypy.objspace.std.iterobject import W_SeqIterObject
-from pypy.objspace.std.setobject import W_BaseSetObject
from pypy.objspace.std.setobject import W_SetObject, W_FrozensetObject
from pypy.objspace.std.sliceobject import W_SliceObject
from pypy.objspace.std.smallintobject import W_SmallIntObject
@@ -401,7 +400,7 @@
def unpackiterable(self, w_obj, expected_length=-1):
if isinstance(w_obj, W_AbstractTupleObject):
t = w_obj.getitems_copy()
- elif isinstance(w_obj, W_ListObject):
+ elif type(w_obj) is W_ListObject:
t = w_obj.getitems_copy()
else:
return ObjSpace.unpackiterable(self, w_obj, expected_length)
@@ -415,7 +414,7 @@
"""
if isinstance(w_obj, W_AbstractTupleObject):
t = w_obj.tolist()
- elif isinstance(w_obj, W_ListObject):
+ elif type(w_obj) is W_ListObject:
if unroll:
t = w_obj.getitems_unroll()
else:
@@ -436,7 +435,7 @@
return self.fixedview(w_obj, expected_length, unroll=True)
def listview(self, w_obj, expected_length=-1):
- if isinstance(w_obj, W_ListObject):
+ if type(w_obj) is W_ListObject:
t = w_obj.getitems()
elif isinstance(w_obj, W_AbstractTupleObject):
t = w_obj.getitems_copy()
@@ -447,22 +446,24 @@
return t
def listview_str(self, w_obj):
- if isinstance(w_obj, W_ListObject):
+ # note: uses exact type checking for objects with strategies,
+ # and isinstance() for others. See test_listobject.test_uses_custom...
+ if type(w_obj) is W_ListObject:
return w_obj.getitems_str()
- if isinstance(w_obj, W_BaseSetObject):
+ if type(w_obj) is W_DictMultiObject:
return w_obj.listview_str()
- if type(w_obj) is W_DictMultiObject: # test_listobject.test_uses_cus.
+ if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
return w_obj.listview_str()
if isinstance(w_obj, W_StringObject):
return w_obj.listview_str()
return None
def listview_int(self, w_obj):
- if isinstance(w_obj, W_ListObject):
+ if type(w_obj) is W_ListObject:
return w_obj.getitems_int()
- if isinstance(w_obj, W_BaseSetObject):
+ if type(w_obj) is W_DictMultiObject:
return w_obj.listview_int()
- if type(w_obj) is W_DictMultiObject: # test_listobject.test_uses_cus.
+ if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
return w_obj.listview_int()
return None
diff --git a/pypy/objspace/std/test/test_listobject.py
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -1184,10 +1184,15 @@
def test_uses_custom_iterator(self):
# obscure corner case: space.listview*() must not shortcut subclasses
# of dicts, because the OrderedDict in the stdlib relies on this.
- class SubClass(dict):
- def __iter__(self):
- return iter("foobar")
- for arg in [[], [(5,6)], [('x',7)]]:
+ # we extend the use case to lists and sets, i.e. all types that have
+ # strategies, to avoid surprizes depending on the strategy.
+ for base, arg in [(list, []), (list, [5]), (list, ['x']),
+ (set, []), (set, [5]), (set, ['x']),
+ (dict, []), (dict, [(5,6)]), (dict, [('x',7)])]:
+ print base, arg
+ class SubClass(base):
+ def __iter__(self):
+ return iter("foobar")
assert list(SubClass(arg)) == ['f', 'o', 'o', 'b', 'a', 'r']
class AppTestForRangeLists(AppTestW_ListObject):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit