File tree 5 files changed +50
-12
lines changed
5 files changed +50
-12
lines changed Original file line number Diff line number Diff line change @@ -602,9 +602,17 @@ can be overridden by the local file.
602
602
603
603
Execute the (one-line) *statement * in the context of the current stack frame.
604
604
The exclamation point can be omitted unless the first word of the statement
605
- resembles a debugger command. To set a global variable, you can prefix the
606
- assignment command with a :keyword: `global ` statement on the same line,
607
- e.g.::
605
+ resembles a debugger command, e.g.:
606
+
607
+ .. code-block :: none
608
+
609
+ (Pdb) ! n=42
610
+ (Pdb)
611
+
612
+ To set a global variable, you can prefix the assignment command with a
613
+ :keyword: `global ` statement on the same line, e.g.:
614
+
615
+ .. code-block :: none
608
616
609
617
(Pdb) global list_options; list_options = ['-l']
610
618
(Pdb)
Original file line number Diff line number Diff line change @@ -440,7 +440,7 @@ def displayhook(self, obj):
440
440
self .message (repr (obj ))
441
441
442
442
def default (self , line ):
443
- if line [:1 ] == '!' : line = line [1 :]
443
+ if line [:1 ] == '!' : line = line [1 :]. strip ()
444
444
locals = self .curframe_locals
445
445
globals = self .curframe .f_globals
446
446
try :
@@ -1642,9 +1642,12 @@ def help_exec(self):
1642
1642
1643
1643
Execute the (one-line) statement in the context of the current
1644
1644
stack frame. The exclamation point can be omitted unless the
1645
- first word of the statement resembles a debugger command. To
1646
- assign to a global variable you must always prefix the command
1647
- with a 'global' command, e.g.:
1645
+ first word of the statement resembles a debugger command, e.g.:
1646
+ (Pdb) ! n=42
1647
+ (Pdb)
1648
+
1649
+ To assign to a global variable you must always prefix the command with
1650
+ a 'global' command, e.g.:
1648
1651
(Pdb) global list_options; list_options = ['-l']
1649
1652
(Pdb)
1650
1653
"""
Original file line number Diff line number Diff line change 5283
5283
'current\n'
5284
5284
' stack frame. The exclamation point can be omitted unless the '
5285
5285
'first\n'
5286
- ' word of the statement resembles a debugger command. To set '
5287
- 'a\n'
5288
- ' global variable, you can prefix the assignment command with '
5289
- 'a\n'
5290
- ' "global" statement on the same line, e.g.:\n'
5286
+ ' word of the statement resembles a debugger command, e.g.:'
5287
+ '\n'
5288
+ ' (Pdb) ! n=42\n'
5289
+ ' (Pdb)\n'
5290
+ '\n'
5291
+ ' To set a global variable, you can prefix the assignment command '
5292
+ ' with \n'
5293
+ ' a "global" statement on the same line, e.g.:\n'
5291
5294
'\n'
5292
5295
" (Pdb) global list_options; list_options = ['-l']\n"
5293
5296
' (Pdb)\n'
Original file line number Diff line number Diff line change @@ -1798,6 +1798,29 @@ def test_pdb_issue_gh_101517():
1798
1798
(Pdb) continue
1799
1799
"""
1800
1800
1801
+ def test_pdb_ambiguous_statements ():
1802
+ """See GH-104301
1803
+
1804
+ Make sure that ambiguous statements prefixed by '!' are properly disambiguated
1805
+
1806
+ >>> with PdbTestInput([
1807
+ ... '! n = 42', # disambiguated statement: reassign the name n
1808
+ ... 'n', # advance the debugger into the print()
1809
+ ... 'continue'
1810
+ ... ]):
1811
+ ... n = -1
1812
+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1813
+ ... print(f"The value of n is {n}")
1814
+ > <doctest test.test_pdb.test_pdb_ambiguous_statements[0]>(8)<module>()
1815
+ -> print(f"The value of n is {n}")
1816
+ (Pdb) ! n = 42
1817
+ (Pdb) n
1818
+ The value of n is 42
1819
+ > <doctest test.test_pdb.test_pdb_ambiguous_statements[0]>(1)<module>()
1820
+ -> with PdbTestInput([
1821
+ (Pdb) continue
1822
+ """
1823
+
1801
1824
1802
1825
@support .requires_subprocess ()
1803
1826
class PdbTestCase (unittest .TestCase ):
Original file line number Diff line number Diff line change
1
+ Allow leading whitespace in disambiguated statements in :mod: `pdb `.
You can’t perform that action at this time.
0 commit comments