Skip to content
8 changes: 7 additions & 1 deletion Doc/library/pdb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ The ``run*`` functions and :func:`set_trace` are aliases for instantiating the
access further features, you have to do this yourself:

.. class:: Pdb(completekey='tab', stdin=None, stdout=None, skip=None, \
nosigint=False, readrc=True)
nosigint=False, readrc=True, commands=None)

:class:`Pdb` is the debugger class.

Expand All @@ -211,6 +211,9 @@ access further features, you have to do this yourself:
The *readrc* argument defaults to true and controls whether Pdb will load
.pdbrc files from the filesystem.

The *commands* argument, if given, would be a list of commands to execute
when the debugger starts. It has similar effects to the :file:`.pdbrc` file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The *commands* argument, if given, would be a list of commands to execute
when the debugger starts. It has similar effects to the :file:`.pdbrc` file.
The *commands* argument, if given, is a list of commands to execute
when the debugger starts. Those commands are executed after those
optionally provided by the :file:`.pdbrc` file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think two "those" is a little bit confusing here? How about These commands are executed after any commands optionally provided by the :file:.pdbrc file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the double "those" is confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups, you're right! I'm sorry I didn't reply to your question 3 weeks ago btw, but yes your suggestion is way better!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The phrase “similar effects” is kind of vague. I am not sure how to say it more precisely. Link to the .pdbrc documentation? Not sure.


Example call to enable tracing with *skip*::

import pdb; pdb.Pdb(skip=['django.*']).set_trace()
Expand All @@ -227,6 +230,9 @@ access further features, you have to do this yourself:
.. versionchanged:: 3.6
The *readrc* argument.

.. versionadded:: 3.14
The *commands* argument.

.. method:: run(statement, globals=None, locals=None)
runeval(expression, globals=None, locals=None)
runcall(function, *args, **kwds)
Expand Down
5 changes: 4 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
_file_mtime_table = {}

def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
nosigint=False, readrc=True):
nosigint=False, readrc=True, commands=None):
bdb.Bdb.__init__(self, skip=skip)
cmd.Cmd.__init__(self, completekey, stdin, stdout)
sys.audit("pdb.Pdb")
Expand Down Expand Up @@ -346,6 +346,9 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
except OSError:
pass

if commands is not None:
self.rcLines.extend(commands)

self.commands = {} # associates a command list to breakpoint numbers
self.commands_doprompt = {} # for each bp num, tells if the prompt
# must be disp. after execing the cmd list
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,18 @@ def test_pdb_where_command():
"""


def test_pdb_commands_at_init():
"""Test that commands can be passed to the constructor

>>> def test_function():
... x = 1
... import pdb; pdb.Pdb(nosigint=True, readrc=False, commands=['p x', 'c']).set_trace()

>>> test_function()
1
"""


# skip this test if sys.flags.no_site = True;
# exit() isn't defined unless there's a site module.
if not sys.flags.no_site:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``commands`` argument to :class:`pdb.Pdb` which allows user to send debugger commands in the source file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Added ``commands`` argument to :class:`pdb.Pdb` which allows user to send debugger commands in the source file.
Added ``commands`` argument to :class:`pdb.Pdb` which allows users to send debugger commands in the source file.