Skip to content

Commit 1acb746

Browse files
committed
Add the "interact" pdb command from pdb++.
1 parent 732324a commit 1acb746

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Doc/library/pdb.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,14 @@ by the local file.
407407

408408
.. versionadded:: 3.2
409409

410+
.. pdbcommand:: interact
411+
412+
Start an interative interpreter (using the :mod:`code` module) whose global
413+
namespace contains all the (global and local) names found in the current
414+
scope.
415+
416+
.. versionadded:: 3.2
417+
410418
.. _debugger-aliases:
411419

412420
.. pdbcommand:: alias [name [command]]

Lib/pdb.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,16 @@
6767
# commands and is appended to __doc__ after the class has been defined.
6868

6969
import sys
70-
import linecache
7170
import cmd
7271
import bdb
7372
import dis
7473
import os
7574
import re
75+
import code
7676
import pprint
77-
import traceback
7877
import inspect
78+
import traceback
79+
import linecache
7980

8081

8182
class Restart(Exception):
@@ -1167,6 +1168,16 @@ def do_whatis(self, arg):
11671168
# None of the above...
11681169
self.message(type(value))
11691170

1171+
def do_interact(self, arg):
1172+
"""interact
1173+
1174+
Start an interative interpreter whose global namespace
1175+
contains all the (global and local) names found in the current scope.
1176+
"""
1177+
ns = self.curframe.f_globals.copy()
1178+
ns.update(self.curframe_locals)
1179+
code.interact("*interactive*", local=ns)
1180+
11701181
def do_alias(self, arg):
11711182
"""alias [name [command [parameter parameter ...] ]]
11721183
Create an alias called 'name' that executes 'command'. The
@@ -1342,8 +1353,8 @@ def _runscript(self, filename):
13421353
'help', 'where', 'down', 'up', 'break', 'tbreak', 'clear', 'disable',
13431354
'enable', 'ignore', 'condition', 'commands', 'step', 'next', 'until',
13441355
'jump', 'return', 'retval', 'run', 'continue', 'list', 'longlist',
1345-
'args', 'print', 'pp', 'whatis', 'source', 'alias', 'unalias',
1346-
'debug', 'quit',
1356+
'args', 'print', 'pp', 'whatis', 'source', 'interact', 'alias',
1357+
'unalias', 'debug', 'quit',
13471358
]
13481359

13491360
for _command in _help_order:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Core and Builtins
4545
Library
4646
-------
4747

48+
- Add the "interact" pdb command.
49+
4850
- Issue #7905: Actually respect the keyencoding parameter to shelve.Shelf.
4951

5052
- Issue #1569291: Speed up array.repeat().

0 commit comments

Comments
 (0)