Skip to content

Commit 76a633e

Browse files
Add commands argument to pdb.Pdb
1 parent d50a7c4 commit 76a633e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Lib/pdb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
307307
_file_mtime_table = {}
308308

309309
def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
310-
nosigint=False, readrc=True):
310+
nosigint=False, readrc=True, commands=None):
311311
bdb.Bdb.__init__(self, skip=skip)
312312
cmd.Cmd.__init__(self, completekey, stdin, stdout)
313313
sys.audit("pdb.Pdb")
@@ -346,6 +346,9 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
346346
except OSError:
347347
pass
348348

349+
if commands is not None:
350+
self.rcLines.extend(commands)
351+
349352
self.commands = {} # associates a command list to breakpoint numbers
350353
self.commands_doprompt = {} # for each bp num, tells if the prompt
351354
# must be disp. after execing the cmd list

Lib/test/test_pdb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,18 @@ def test_pdb_where_command():
833833
"""
834834

835835

836+
def test_pdb_commands_at_init():
837+
"""Test that commands can be passed to the constructor
838+
839+
>>> def test_function():
840+
... x = 1
841+
... import pdb; pdb.Pdb(nosigint=True, readrc=False, commands=['p x', 'c']).set_trace()
842+
843+
>>> test_function()
844+
1
845+
"""
846+
847+
836848
# skip this test if sys.flags.no_site = True;
837849
# exit() isn't defined unless there's a site module.
838850
if not sys.flags.no_site:

0 commit comments

Comments
 (0)