[pypy-commit] pypy SpecialisedTuples: (mwp) reinstate inherited tuple tests, and add mul__SpecialisedTuple_ANY to fix identity test failure

mwp noreply at buildbot.pypy.org
Thu Nov 10 10:47:57 CET 2011


Author: Mark Pearse <mark.pearse at skynet.be>
Branch: SpecialisedTuples
Changeset: r49109:2d6ad2a8c19c
Date: 2011-11-08 11:44 +0100
http://bitbucket.org/pypy/pypy/changeset/2d6ad2a8c19c/

Log:	(mwp) reinstate inherited tuple tests, and add
	mul__SpecialisedTuple_ANY to fix identity test failure

diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -161,6 +161,24 @@
         start += step
     return space.newtuple(subitems)
 
+def mul_specialisedtuple_times(space, w_tuple, w_times):
+    try:
+        times = space.getindex_w(w_times, space.w_OverflowError)
+    except OperationError, e:
+        if e.match(space, space.w_TypeError):
+            raise FailedToImplement
+        raise
+    if times == 1 and space.type(w_tuple) == space.w_tuple:
+        return w_tuple
+    items = w_tuple.tolist()
+    return space.newtuple(items * times)
+
+def mul__SpecialisedTuple_ANY(space, w_tuple, w_times):
+    return mul_specialisedtuple_times(space, w_tuple, w_times)
+
+def mul__ANY_SpecialisedTuple(space, w_times, w_tuple):
+    return mul_specialisedtuple_times(space, w_tuple, w_times)
+
 def eq__SpecialisedTuple_SpecialisedTuple(space, w_tuple1, w_tuple2):
     return w_tuple1.eq(space, w_tuple2)
 
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -3,7 +3,7 @@
 from pypy.objspace.std.specialisedtupleobject import W_SpecialisedTupleObject,W_SpecialisedTupleObjectIntInt
 from pypy.interpreter.error import OperationError
 from pypy.conftest import gettestobjspace
-#from pypy.objspace.std.test.test_tupleobject import AppTestW_TupleObject
+from pypy.objspace.std.test.test_tupleobject import AppTestW_TupleObject
 from pypy.interpreter import gateway
 
 
@@ -52,7 +52,7 @@
         assert len(list_w) == 1
         assert self.space.eq_w(list_w[0], self.space.wrap(5))        
 
-class AppTestW_SpecialisedTupleObject(object):
+class AppTestW_SpecialisedTupleObject(AppTestW_TupleObject):
 
     def setup_class(cls):
         cls.space = gettestobjspace(**{"objspace.std.withspecialisedtuple": True})


More information about the pypy-commit mailing list