Author: Lukas Diekmann <[email protected]>
Branch: 
Changeset: r44431:41a61689e25c
Date: 2011-01-18 17:34 +0100
http://bitbucket.org/pypy/pypy/changeset/41a61689e25c/

Log:    Added small tuple with length 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
@@ -24,7 +24,8 @@
     iter_n = unrolling_iterable(range(n))
     class cls(W_SmallTupleObject):
 
-        def __init__(self, *values):
+        def __init__(self, values):
+            assert len(values) == n
             for i in iter_n:
                 setattr(self, 'w_value%s' % i, values[i])
 
@@ -47,6 +48,7 @@
     return cls
 
 W_SmallTupleObject2 = make_specialized_class(2)
+W_SmallTupleObject3 = make_specialized_class(3)
 
 registerimplementation(W_SmallTupleObject)
 
diff --git a/pypy/objspace/std/test/test_smalltupleobject.py 
b/pypy/objspace/std/test/test_smalltupleobject.py
--- a/pypy/objspace/std/test/test_smalltupleobject.py
+++ b/pypy/objspace/std/test/test_smalltupleobject.py
@@ -14,18 +14,29 @@
             return issmall
         """)
 
+    def test_smalltuple(self):
+        self.issmall((1,2))
+        self.issmall((1,2,3))
+
     def test_slicing_to_small(self):
-        self.issmall((1, 2, 3)[0:2])
+        self.issmall((1, 2, 3)[0:2])    # SmallTuple2
         self.issmall((1, 2, 3)[0:2:1])
 
+        self.issmall((1, 2, 3, 4)[0:3])    # SmallTuple3
+        self.issmall((1, 2, 3, 4)[0:3:1])
+
     def test_adding_to_small(self):
-        self.issmall((1,)+(2,))
+        self.issmall((1,)+(2,))       # SmallTuple2
+        self.issmall((1,1)+(2,))      # SmallTuple3
+        self.issmall((1,)+(2,3))
 
     def test_multiply_to_small(self):
         self.issmall((1,)*2)
+        self.issmall((1,)*3)
 
     def test_slicing_from_small(self):
         assert (1,2)[0:1:1] == (1,)
+        assert (1,2,3)[0:2:1] == (1,2)
 
 class TestW_SmallTupleObject():
 
diff --git a/pypy/objspace/std/tupletype.py b/pypy/objspace/std/tupletype.py
--- a/pypy/objspace/std/tupletype.py
+++ b/pypy/objspace/std/tupletype.py
@@ -5,11 +5,13 @@
 
 def wraptuple(space, list_w):
     from pypy.objspace.std.tupleobject import W_TupleObject
-    from pypy.objspace.std.smalltupleobject import W_SmallTupleObject2
-    if space.config.objspace.std.withsmalltuple and len(list_w) == 2:
-        return W_SmallTupleObject2(list_w[0], list_w[1])
-    else:
-        return W_TupleObject(list_w)
+    from pypy.objspace.std.smalltupleobject import W_SmallTupleObject2, 
W_SmallTupleObject3
+    if space.config.objspace.std.withsmalltuple:
+        if len(list_w) == 2:
+            return W_SmallTupleObject2(list_w)
+        if len(list_w) == 3:
+            return W_SmallTupleObject3(list_w)
+    return W_TupleObject(list_w)
 
 tuple_count = SMM("count", 2,
                   doc="count(obj) -> number of times obj appears in the tuple")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to