Rev 4758: Change the repr to print out 'StaticTuple' in http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple

John Arbash Meinel john at arbash-meinel.com
Wed Oct 7 17:13:05 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple

------------------------------------------------------------
revno: 4758
revision-id: john at arbash-meinel.com-20091007161250-s9lqf98ci6i5mkqe
parent: john at arbash-meinel.com-20091007160652-cvcgqllfgml48uq4
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-static-tuple
timestamp: Wed 2009-10-07 11:12:50 -0500
message:
  Change the repr to print out 'StaticTuple'
-------------- next part --------------
=== modified file 'bzrlib/_static_tuple_c.c'
--- a/bzrlib/_static_tuple_c.c	2009-10-07 15:57:25 +0000
+++ b/bzrlib/_static_tuple_c.c	2009-10-07 16:12:50 +0000
@@ -217,14 +217,19 @@
 static PyObject *
 StaticTuple_repr(StaticTuple *self)
 {
-    PyObject *as_tuple, *result;
+    PyObject *as_tuple, *tuple_repr, *result;
 
     as_tuple = StaticTuple_as_tuple(self);
     if (as_tuple == NULL) {
         return NULL;
     }
-    result = PyObject_Repr(as_tuple);
+    tuple_repr = PyObject_Repr(as_tuple);
     Py_DECREF(as_tuple);
+    if (tuple_repr == NULL) {
+        return NULL;
+    }
+    result = PyString_FromFormat("%s%s", Py_TYPE(self)->tp_name,
+                                         PyString_AsString(tuple_repr));
     return result;
 }
 

=== modified file 'bzrlib/_static_tuple_py.py'
--- a/bzrlib/_static_tuple_py.py	2009-10-07 16:06:52 +0000
+++ b/bzrlib/_static_tuple_py.py	2009-10-07 16:12:50 +0000
@@ -42,8 +42,8 @@
         # already handled in __new__.
         tuple.__init__(self)
 
-    # def __repr__(self):
-    #     return tuple.__repr__(self)
+    def __repr__(self):
+        return '%s%s' % (self.__class__.__name__, tuple.__repr__(self))
 
     def as_tuple(self):
         return self

=== modified file 'bzrlib/tests/test__static_tuple.py'
--- a/bzrlib/tests/test__static_tuple.py	2009-10-07 16:06:52 +0000
+++ b/bzrlib/tests/test__static_tuple.py	2009-10-07 16:12:50 +0000
@@ -145,7 +145,7 @@
 
     def test__repr__(self):
         k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
-        self.assertEqual("('foo', 'bar', 'baz', 'bing')", repr(k))
+        self.assertEqual("StaticTuple('foo', 'bar', 'baz', 'bing')", repr(k))
 
     def assertCompareEqual(self, k1, k2):
         self.assertTrue(k1 == k2)



More information about the bazaar-commits mailing list