Commit 78d692f9 authored by R David Murray's avatar R David Murray

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.
parent 2fe9bac4
......@@ -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
......
......@@ -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
------
......
......@@ -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',
]
......
......@@ -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
......
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment