18764: remove the problematic 'print' alias for the PDB 'p' command.

So that it no longer shadows the print function.

Patch by Connor Osborn, doc and test changes by R. David Murray.
This commit is contained in:
R David Murray 2013-10-10 17:23:26 -04:00
parent 2fe9bac4dc
commit 78d692f98e
5 changed files with 31 additions and 11 deletions

View file

@ -41,7 +41,7 @@ of the debugger is::
.. versionchanged:: 3.3 .. versionchanged:: 3.3
Tab-completion via the :mod:`readline` module is available for commands and 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 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 :file:`pdb.py` can also be invoked as a script to debug other scripts. For
example:: example::
@ -309,7 +309,7 @@ by the local file.
``end`` to terminate the commands. An example:: ``end`` to terminate the commands. An example::
(Pdb) commands 1 (Pdb) commands 1
(com) print some_variable (com) p some_variable
(com) end (com) end
(Pdb) (Pdb)
@ -409,7 +409,7 @@ by the local file.
.. pdbcommand:: pp expression .. 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. pretty-printed using the :mod:`pprint` module.
.. pdbcommand:: whatis expression .. pdbcommand:: whatis expression

View file

@ -302,6 +302,22 @@ descriptors or a Windows handle:
* :func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable` * :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 poplib
------ ------

View file

@ -1159,15 +1159,13 @@ class Pdb(bdb.Bdb, cmd.Cmd):
return _rstr('** raised %s **' % err) return _rstr('** raised %s **' % err)
def do_p(self, arg): def do_p(self, arg):
"""p(rint) expression """p expression
Print the value of the expression. Print the value of the expression.
""" """
try: try:
self.message(repr(self._getval(arg))) self.message(repr(self._getval(arg)))
except: except:
pass pass
# make "print" an alias of "p" since print isn't a Python statement anymore
do_print = do_p
def do_pp(self, arg): def do_pp(self, arg):
"""pp expression """pp expression
@ -1388,7 +1386,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
placed in the .pdbrc file): placed in the .pdbrc file):
# Print instance variables (usage "pi classInst") # 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 # Print instance variables in self
alias ps pi self alias ps pi self
""" """
@ -1546,7 +1544,7 @@ if __doc__ is not None:
'help', 'where', 'down', 'up', 'break', 'tbreak', 'clear', 'disable', 'help', 'where', 'down', 'up', 'break', 'tbreak', 'clear', 'disable',
'enable', 'ignore', 'condition', 'commands', 'step', 'next', 'until', 'enable', 'ignore', 'condition', 'commands', 'step', 'next', 'until',
'jump', 'return', 'retval', 'run', 'continue', 'list', 'longlist', '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', 'interact', 'alias', 'unalias', 'debug', 'quit',
] ]

View file

@ -205,7 +205,8 @@ def test_pdb_breakpoint_commands():
... 'enable 1', ... 'enable 1',
... 'clear 1', ... 'clear 1',
... 'commands 2', ... 'commands 2',
... 'print 42', ... 'p "42"',
... 'print("42", 7*6)', # Issue 18764 (not about breakpoints)
... 'end', ... 'end',
... 'continue', # will stop at breakpoint 2 (line 4) ... 'continue', # will stop at breakpoint 2 (line 4)
... 'clear', # clear all! ... 'clear', # clear all!
@ -252,11 +253,13 @@ def test_pdb_breakpoint_commands():
(Pdb) clear 1 (Pdb) clear 1
Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3 Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
(Pdb) commands 2 (Pdb) commands 2
(com) print 42 (com) p "42"
(com) print("42", 7*6)
(com) end (com) end
(Pdb) continue (Pdb) continue
1 1
42 '42'
42 42
> <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(4)test_function() > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(4)test_function()
-> print(2) -> print(2)
(Pdb) clear (Pdb) clear

View file

@ -34,6 +34,9 @@ Core and Builtins
Library 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 - Issue #19158: a rare race in BoundedSemaphore could allow .release() too
often. often.