Author: Armin Rigo <ar...@tunes.org>
Branch: array-overallocation-in-nursery
Changeset: r67496:a9b51ff40cf6
Date: 2013-10-22 11:46 +0200
http://bitbucket.org/pypy/pypy/changeset/a9b51ff40cf6/

Log:    Improve the repr

diff --git a/rpython/rtyper/lltypesystem/lltype.py 
b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -1715,6 +1715,10 @@
 
     def __str__(self):
         items = self.items
+        extra = ''
+        if self._TYPE._is_overallocated_array():
+            extra = ' allocated=%d' % len(items)
+            items = items[:self.used_len]
         if len(items) > 20:
             items = items[:12] + items[-5:]
             skipped_at = 12
@@ -1723,7 +1727,7 @@
         items = [self._str_item(item) for item in items]
         if skipped_at:
             items.insert(skipped_at, '(...)')
-        return 'array [ %s ]' % (', '.join(items),)
+        return 'array%s [ %s ]' % (extra, ', '.join(items))
 
     def getlength(self):
         return len(self.items)
diff --git a/rpython/rtyper/lltypesystem/test/test_lltype.py 
b/rpython/rtyper/lltypesystem/test/test_lltype.py
--- a/rpython/rtyper/lltypesystem/test/test_lltype.py
+++ b/rpython/rtyper/lltypesystem/test/test_lltype.py
@@ -824,6 +824,9 @@
     py.test.raises(IndexError, "a[3] = 43")
     a.used_length = 5
     py.test.raises(UninitializedMemoryAccess, "a[3]")
+    a[0] = 100
+    a[3] = 200
+    assert repr(a) == '<* array allocated=10 [ 100, #, #, 200, # ]>'
 
 class TestTrackAllocation:
     def test_automatic_tracking(self):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to