]> granicus.if.org Git - python/commitdiff
18764: remove the problematic 'print' alias for the PDB 'p' command.
authorR David Murray <rdmurray@bitdance.com>
Thu, 10 Oct 2013 21:23:26 +0000 (17:23 -0400)
committerR David Murray <rdmurray@bitdance.com>
Thu, 10 Oct 2013 21:23:26 +0000 (17:23 -0400)
So that it no longer shadows the print function.

Patch by Connor Osborn, doc and test changes by R. David Murray.

Doc/library/pdb.rst
Doc/whatsnew/3.4.rst
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS

index f4e37ac2a6b7800517fa7f718235a6e9c54f0081..66a78d05a504f1addf0a615735f58d9b6225ff90 100644 (file)
@@ -41,7 +41,7 @@ of the debugger is::
 .. versionchanged:: 3.3
    Tab-completion via the :mod:`readline` module is available for commands and
    command arguments, e.g. the current global and local names are offered as
-   arguments of the ``print`` command.
+   arguments of the ``p`` command.
 
 :file:`pdb.py` can also be invoked as a script to debug other scripts.  For
 example::
@@ -309,7 +309,7 @@ by the local file.
    ``end`` to terminate the commands. An example::
 
       (Pdb) commands 1
-      (com) print some_variable
+      (com) p some_variable
       (com) end
       (Pdb)
 
@@ -409,7 +409,7 @@ by the local file.
 
 .. pdbcommand:: pp expression
 
-   Like the :pdbcmd:`print` command, except the value of the expression is
+   Like the :pdbcmd:`p` command, except the value of the expression is
    pretty-printed using the :mod:`pprint` module.
 
 .. pdbcommand:: whatis expression
index ed4ea176ef5c6cb419f462efde900e7a70435385..373f8de1ff45092ec4bfaf049504238a2db501db 100644 (file)
@@ -302,6 +302,22 @@ descriptors or a Windows handle:
 * :func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable`
 
 
+pdb
+---
+
+The ``print`` command has been removed from :mod:`pdb`, restoring access to the
+``print`` function.
+
+Rationale: Python2's ``pdb`` did not have a ``print`` command; instead,
+entering ``print`` executed the ``print`` statement.  In Python3 ``print`` was
+mistakenly made an alias for the pdb :pdbcmd:`p` command.  ``p``, however,
+prints the ``repr`` of its argument, not the ``str`` like the Python2 ``print``
+command did.  Worse, the Python3 ``pdb print`` command shadowed the Python3
+``print`` function, making it inaccessible at the ``pdb`` prompt.
+
+(Contributed by Connor Osborn in :issue:`18764`.)
+
+
 poplib
 ------
 
index 45fe477c6cf751aaddfc4e5783da639b62bfad86..1ec83daf439a901deba178bbcf42da66475e040f 100755 (executable)
@@ -1159,15 +1159,13 @@ class Pdb(bdb.Bdb, cmd.Cmd):
             return _rstr('** raised %s **' % err)
 
     def do_p(self, arg):
-        """p(rint) expression
+        """p expression
         Print the value of the expression.
         """
         try:
             self.message(repr(self._getval(arg)))
         except:
             pass
-    # make "print" an alias of "p" since print isn't a Python statement anymore
-    do_print = do_p
 
     def do_pp(self, arg):
         """pp expression
@@ -1388,7 +1386,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         placed in the .pdbrc file):
 
         # Print instance variables (usage "pi classInst")
-        alias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k]
+        alias pi for k in %1.__dict__.keys(): print("%1.",k,"=",%1.__dict__[k])
         # Print instance variables in self
         alias ps pi self
         """
@@ -1546,7 +1544,7 @@ if __doc__ is not None:
         'help', 'where', 'down', 'up', 'break', 'tbreak', 'clear', 'disable',
         'enable', 'ignore', 'condition', 'commands', 'step', 'next', 'until',
         'jump', 'return', 'retval', 'run', 'continue', 'list', 'longlist',
-        'args', 'print', 'pp', 'whatis', 'source', 'display', 'undisplay',
+        'args', 'p', 'pp', 'whatis', 'source', 'display', 'undisplay',
         'interact', 'alias', 'unalias', 'debug', 'quit',
     ]
 
index 0babaa01a0986a563fda64aa9f375839e614f623..e17f933d80e5f0a91af725bef91fd2c8b3f89f92 100644 (file)
@@ -205,7 +205,8 @@ def test_pdb_breakpoint_commands():
     ...     'enable 1',
     ...     'clear 1',
     ...     'commands 2',
-    ...     'print 42',
+    ...     'p "42"',
+    ...     'print("42", 7*6)',     # Issue 18764 (not about breakpoints)
     ...     'end',
     ...     'continue',  # will stop at breakpoint 2 (line 4)
     ...     'clear',     # clear all!
@@ -252,11 +253,13 @@ def test_pdb_breakpoint_commands():
     (Pdb) clear 1
     Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
     (Pdb) commands 2
-    (com) print 42
+    (com) p "42"
+    (com) print("42", 7*6)
     (com) end
     (Pdb) continue
     1
-    42
+    '42'
+    42 42
     > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(4)test_function()
     -> print(2)
     (Pdb) clear
index 3044d85205696952ed67a8996dad2407f5f40dbe..ab9cea7883d7b89b894b519de0c9a443e636c054 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #18764: remove the 'print' alias for the PDB 'p' command so that it no
+  longer shadows the print function.
+
 - Issue #19158:  a rare race in BoundedSemaphore could allow .release() too
   often.