Author: Lukas Diekmann <[email protected]>
Branch: 
Changeset: r44430:c8bdf2dc5966
Date: 2011-01-18 17:33 +0100
http://bitbucket.org/pypy/pypy/changeset/c8bdf2dc5966/

Log:    Implemented multiply for small tuples to fix identity error:
        (1,2,3)*1 is (1,2,3)

diff --git a/pypy/objspace/std/smalltupleobject.py 
b/pypy/objspace/std/smalltupleobject.py
--- a/pypy/objspace/std/smalltupleobject.py
+++ b/pypy/objspace/std/smalltupleobject.py
@@ -76,5 +76,23 @@
         start += step
     return space.newtuple(subitems)
 
+def mul_smalltuple_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__SmallTuple_ANY(space, w_tuple, w_times):
+    return mul_smalltuple_times(space, w_tuple, w_times)
+
+def mul__ANY_SmallTuple(space, w_times, w_tuple):
+    return mul_smalltuple_times(space, w_tuple, w_times)
+
 from pypy.objspace.std import tupletype
 register_all(vars(), tupletype)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to