Skip to content
This repository

Raise repr limit for strings to 80 characters (from 30). #1793

Merged
merged 2 commits into from almost 2 years ago

2 participants

Fernando Perez Min RK
Fernando Perez
Owner
fperez commented May 30, 2012

The python pdb debugger doesn't call the builtin repr function but
instead a custom one from the repr module that limits strings to
30 characters. Raise this limit to 80 for more informative printouts.

Closes #1788.

Fernando Perez Raise repr limit for strings to 80 characters (from 30).
The python pdb debugger doesn't call the builtin `repr` function but
instead a custom one from the `repr` *module* that limits strings to
30 characters.  Raise this limit to 80 for more informative printouts.
ba59d05
Min RK
Owner
minrk commented May 30, 2012

Python docs say repr is renamed reprlib, and is handled by 2to3, so this should be fine. Do you want to add a test?

Fernando Perez
Owner
fperez commented May 30, 2012

Good idea, done.

Min RK
Owner
minrk commented May 30, 2012

Test results for commit 999481b merged into master
Platform: linux2

  • python2.7: OK (libraries not available: pymongo wx wx.aui)
  • python3.2: OK (libraries not available: matplotlib pymongo qt wx wx.aui)

Not available for testing:

Min RK
Owner
minrk commented May 30, 2012

Thanks, merging.

Min RK minrk merged commit 798c5cd into from May 30, 2012
Min RK minrk closed this May 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

May 30, 2012
Fernando Perez Raise repr limit for strings to 80 characters (from 30).
The python pdb debugger doesn't call the builtin `repr` function but
instead a custom one from the `repr` *module* that limits strings to
30 characters.  Raise this limit to 80 for more informative printouts.
ba59d05
Fernando Perez Add simple test for modified repr as per review. 999481b
This page is out of date. Refresh to see the latest.
16  IPython/core/debugger.py
@@ -123,6 +123,22 @@ def __init__(self,colors=None):
123 123
 
124 124
         if colors is None:
125 125
             colors = def_colors
  126
+
  127
+        # The stdlib debugger internally uses a modified repr from the `repr`
  128
+        # module, that limits the length of printed strings to a hardcoded
  129
+        # limit of 30 characters.  That much trimming is too aggressive, let's
  130
+        # at least raise that limit to 80 chars, which should be enough for
  131
+        # most interactive uses.
  132
+        try:
  133
+            from repr import aRepr
  134
+            aRepr.maxstring = 80
  135
+        except:
  136
+            # This is only a user-facing convenience, so any error we encounter
  137
+            # here can be warned about but can be otherwise ignored.  These
  138
+            # printouts will tell us about problems if this API changes 
  139
+            import traceback
  140
+            traceback.print_exc()
  141
+
126 142
         self.debugger = Pdb(colors)
127 143
 
128 144
     def __call__(self):
35  IPython/core/tests/test_debugger.py
... ...
@@ -0,0 +1,35 @@
  1
+"""Tests for debugging machinery.
  2
+"""
  3
+#-----------------------------------------------------------------------------
  4
+#  Copyright (c) 2012, The IPython Development Team.
  5
+#
  6
+#  Distributed under the terms of the Modified BSD License.
  7
+#
  8
+#  The full license is in the file COPYING.txt, distributed with this software.
  9
+#-----------------------------------------------------------------------------
  10
+
  11
+#-----------------------------------------------------------------------------
  12
+# Imports
  13
+#-----------------------------------------------------------------------------
  14
+
  15
+# third-party
  16
+import nose.tools as nt
  17
+
  18
+# Our own
  19
+from IPython.core import debugger
  20
+
  21
+#-----------------------------------------------------------------------------
  22
+# Tests
  23
+#-----------------------------------------------------------------------------
  24
+
  25
+def test_longer_repr():
  26
+    from repr import repr as trepr
  27
+    
  28
+    a = '1234567890'* 7
  29
+    ar = "'1234567890123456789012345678901234567890123456789012345678901234567890'"
  30
+    a_trunc = "'123456789012...8901234567890'"
  31
+    nt.assert_equals(trepr(a), a_trunc)
  32
+    # The creation of our tracer modifies the repr module's repr function
  33
+    # in-place, since that global is used directly by the stdlib's pdb module.
  34
+    t = debugger.Tracer()
  35
+    nt.assert_equals(trepr(a), ar)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.