[pypy-commit] pypy SpecialisedTuples: Re-add and review this code. Needed to ensure that "tup*1 is tup",

arigo noreply at buildbot.pypy.org
Thu Dec 8 18:18:07 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: SpecialisedTuples
Changeset: r50315:d896533b28af
Date: 2011-12-08 18:15 +0100
http://bitbucket.org/pypy/pypy/changeset/d896533b28af/

Log:	Re-add and review this code. Needed to ensure that "tup*1 is tup",
	in case obscure code depends on it.

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
@@ -249,23 +249,23 @@
         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_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__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 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
@@ -222,5 +222,4 @@
 
 
 class AppTestAll(test_tupleobject.AppTestW_TupleObject):
-    def test_mul_identity(self):
-        skip("not working with specialisedtuple")
+    pass


More information about the pypy-commit mailing list