]> granicus.if.org Git - python/commitdiff
Fix error introduced by r58288; if a tuple is length 0 return its repr and
authorBrett Cannon <bcannon@gmail.com>
Sun, 30 Sep 2007 20:37:19 +0000 (20:37 +0000)
committerBrett Cannon <bcannon@gmail.com>
Sun, 30 Sep 2007 20:37:19 +0000 (20:37 +0000)
don't worry about any self-referring tuples.

Objects/tupleobject.c

index 38304dda18f16b3669e4a8df1481282befa2e89c..b1704f7be4c25f078de7276389805721f2a4ecba 100644 (file)
@@ -216,6 +216,10 @@ tuplerepr(PyTupleObject *v)
        PyObject *s, *temp;
        PyObject *pieces, *result = NULL;
 
+       n = Py_Size(v);
+       if (n == 0)
+               return PyString_FromString("()");
+
        /* While not mutable, it is still possible to end up with a cycle in a
           tuple through an object that stores itself within a tuple (and thus
           infinitely asks for the repr of itself). This should only be
@@ -225,10 +229,6 @@ tuplerepr(PyTupleObject *v)
                return i > 0 ? PyString_FromString("(...)") : NULL;
        }
 
-       n = Py_Size(v);
-       if (n == 0)
-               return PyString_FromString("()");
-
        pieces = PyTuple_New(n);
        if (pieces == NULL)
                return NULL;