]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make the pdb displayhook compatible with the standard displayhook: do not print Nones...
authorGeorg Brandl <georg@python.org>
Wed, 16 Sep 2009 16:36:39 +0000 (16:36 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 16 Sep 2009 16:36:39 +0000 (16:36 +0000)
Lib/pdb.py
Lib/test/test_pdb.py

index eae62960ce92184a96074ec52c5320cf20aab6a6..0751c17667d4bc5c4c2a27137993e5bd25c718bb 100755 (executable)
@@ -210,7 +210,9 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         """Custom displayhook for the exec in default(), which prevents
         assignment of the _ variable in the builtins.
         """
-        print repr(obj)
+        # reproduce the behavior of the standard displayhook, not printing None
+        if obj is not None:
+            print repr(obj)
 
     def default(self, line):
         if line[:1] == '!': line = line[1:]
index a15538cbf7e2ba84b51b953e0ccd39a8d90e72e2..6017edc5e2e9192ac1b371f91d2fcbada0467976 100644 (file)
@@ -26,6 +26,38 @@ class PdbTestInput(object):
         sys.stdin = self.real_stdin
 
 
+def write(x):
+    print x
+
+def test_pdb_displayhook():
+    """This tests the custom displayhook for pdb.
+
+    >>> def test_function(foo, bar):
+    ...     import pdb; pdb.Pdb().set_trace()
+    ...     pass
+
+    >>> with PdbTestInput([
+    ...     'foo',
+    ...     'bar',
+    ...     'for i in range(5): write(i)',
+    ...     'continue',
+    ... ]):
+    ...     test_function(1, None)
+    > <doctest test.test_pdb.test_pdb_displayhook[0]>(3)test_function()
+    -> pass
+    (Pdb) foo
+    1
+    (Pdb) bar
+    (Pdb) for i in range(5): write(i)
+    0
+    1
+    2
+    3
+    4
+    (Pdb) continue
+    """
+
+
 def test_pdb_skip_modules():
     """This illustrates the simple case of module skipping.
 
@@ -36,7 +68,7 @@ def test_pdb_skip_modules():
 
     >>> with PdbTestInput([
     ...     'step',
-    ...     'continue'
+    ...     'continue',
     ... ]):
     ...     skip_module()
     > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()