Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 2 commits into from

2 participants

@fperez
Owner

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.

@fperez fperez 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
@minrk
Owner

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

@fperez
Owner

Good idea, done.

@minrk
Owner

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:

@minrk
Owner

Thanks, merging.

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

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

    fperez authored
    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.
Commits on May 31, 2012
  1. @fperez
This page is out of date. Refresh to see the latest.
Showing with 51 additions and 0 deletions.
  1. +16 −0 IPython/core/debugger.py
  2. +35 −0 IPython/core/tests/test_debugger.py
View
16 IPython/core/debugger.py
@@ -123,6 +123,22 @@ def __init__(self,colors=None):
if colors is None:
colors = def_colors
+
+ # The stdlib debugger internally uses a modified repr from the `repr`
+ # module, that limits the length of printed strings to a hardcoded
+ # limit of 30 characters. That much trimming is too aggressive, let's
+ # at least raise that limit to 80 chars, which should be enough for
+ # most interactive uses.
+ try:
+ from repr import aRepr
+ aRepr.maxstring = 80
+ except:
+ # This is only a user-facing convenience, so any error we encounter
+ # here can be warned about but can be otherwise ignored. These
+ # printouts will tell us about problems if this API changes
+ import traceback
+ traceback.print_exc()
+
self.debugger = Pdb(colors)
def __call__(self):
View
35 IPython/core/tests/test_debugger.py
@@ -0,0 +1,35 @@
+"""Tests for debugging machinery.
+"""
+#-----------------------------------------------------------------------------
+# Copyright (c) 2012, The IPython Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
+# Imports
+#-----------------------------------------------------------------------------
+
+# third-party
+import nose.tools as nt
+
+# Our own
+from IPython.core import debugger
+
+#-----------------------------------------------------------------------------
+# Tests
+#-----------------------------------------------------------------------------
+
+def test_longer_repr():
+ from repr import repr as trepr
+
+ a = '1234567890'* 7
+ ar = "'1234567890123456789012345678901234567890123456789012345678901234567890'"
+ a_trunc = "'123456789012...8901234567890'"
+ nt.assert_equals(trepr(a), a_trunc)
+ # The creation of our tracer modifies the repr module's repr function
+ # in-place, since that global is used directly by the stdlib's pdb module.
+ t = debugger.Tracer()
+ nt.assert_equals(trepr(a), ar)
Something went wrong with that request. Please try again.