From b9002bfee9877d8ffa64d9e632054612854d9802 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 16 Dec 2025 12:55:15 +0000 Subject: [PATCH 01/11] commands command with no bpnumber should use last available breakpoint --- Lib/pdb.py | 7 ++++++- Lib/test/test_pdb.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index c1a5db080dc7ef..022989f741f040 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1315,7 +1315,12 @@ def do_commands(self, arg): reached. """ if not arg: - bnum = len(bdb.Breakpoint.bpbynumber) - 1 + for bnum in range(len(bdb.Breakpoint.bpbynumber) - 1, -1, -1): + if bdb.Breakpoint.bpbynumber[bnum] is not None: + break + if bnum == 0: + self.error('no breakpoints setted') + return else: try: bnum = int(arg) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index f4c870036a7a20..336e71ff3ad04f 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3478,6 +3478,43 @@ def test_pdb_issue_gh_65052(): (Pdb) continue """ +def test_pdb_issue_142834(): + """See issue-142834 + + >>> def test_function(): + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... foo = 1 + ... bar = 2 + + >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + ... 'break 4', + ... 'break 3', + ... 'clear 2', + ... 'commands', + ... 'p "success"', + ... 'end', + ... 'continue', + ... '', + ... ]): + ... test_function() + > (2)test_function() + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) break 4 + Breakpoint 1 at :4 + (Pdb) break 3 + Breakpoint 2 at :3 + (Pdb) clear 2 + Deleted breakpoint 2 at :3 + (Pdb) commands + (com) p "success" + (com) end + (Pdb) continue + 'success' + > (4)test_function() + -> bar = 2 + (Pdb) + """ + @support.force_not_colorized_test_class @support.requires_subprocess() From 4027544035aa8ff848d01d49772126e0fbb43783 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 16 Dec 2025 15:32:42 +0000 Subject: [PATCH 02/11] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst diff --git a/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst b/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst new file mode 100644 index 00000000000000..4850d54fc8470b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst @@ -0,0 +1,2 @@ +:mod:`pdb` ``commands`` command to use the last available breakpoint +instead of failing when the most recently created breakpoint was deleted. From a3dc3c32bebebc7ef9341a0df450a78119c52fc0 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 16 Dec 2025 15:42:02 +0000 Subject: [PATCH 03/11] fix test --- Lib/test/test_pdb.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 336e71ff3ad04f..f9974ced9ef416 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3497,20 +3497,20 @@ def test_pdb_issue_142834(): ... '', ... ]): ... test_function() - > (2)test_function() + > (2)test_function() -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() (Pdb) break 4 - Breakpoint 1 at :4 + Breakpoint 1 at :4 (Pdb) break 3 - Breakpoint 2 at :3 + Breakpoint 2 at :3 (Pdb) clear 2 - Deleted breakpoint 2 at :3 + Deleted breakpoint 2 at :3 (Pdb) commands (com) p "success" (com) end (Pdb) continue 'success' - > (4)test_function() + > (4)test_function() -> bar = 2 (Pdb) """ From 5e4813779d863b4fd9e859d4fc743df36adc6730 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 16 Dec 2025 23:43:36 +0800 Subject: [PATCH 04/11] Fix formatting in NEWS entry for pdb commands --- .../Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst b/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst index 4850d54fc8470b..34c8bf4c12f483 100644 --- a/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst +++ b/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst @@ -1,2 +1 @@ -:mod:`pdb` ``commands`` command to use the last available breakpoint -instead of failing when the most recently created breakpoint was deleted. +:mod:`pdb` ``commands`` command to use the last available breakpoint instead of failing when the most recently created breakpoint was deleted. From 0c0627114ead97a72b3da7e86f2f6dd9ab90c2f6 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 16 Dec 2025 23:45:42 +0800 Subject: [PATCH 05/11] Update Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst Co-authored-by: AN Long --- .../next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst b/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst index 34c8bf4c12f483..8cde592e7c937d 100644 --- a/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst +++ b/Misc/NEWS.d/next/Library/2025-12-16-15-32-41.gh-issue-142834.g7mHw_.rst @@ -1 +1 @@ -:mod:`pdb` ``commands`` command to use the last available breakpoint instead of failing when the most recently created breakpoint was deleted. +Change the :mod:`pdb` ``commands`` command to use the last available breakpoint instead of failing when the most recently created breakpoint was deleted. From 5bc30379eb68c5e859f95a0ad64ad341ef46b50a Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Wed, 17 Dec 2025 00:06:38 +0800 Subject: [PATCH 06/11] Update Lib/pdb.py Co-authored-by: AN Long --- Lib/pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 022989f741f040..3a1e2ea4c57ce3 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1319,7 +1319,7 @@ def do_commands(self, arg): if bdb.Breakpoint.bpbynumber[bnum] is not None: break if bnum == 0: - self.error('no breakpoints setted') + self.error('no breakpoints set') return else: try: From 875668c40f08541f176d9c912392c55fa166b2a7 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Wed, 17 Dec 2025 00:31:06 +0800 Subject: [PATCH 07/11] Update Lib/pdb.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartosz Sławecki --- Lib/pdb.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 3a1e2ea4c57ce3..3ed819e285442d 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1315,12 +1315,14 @@ def do_commands(self, arg): reached. """ if not arg: - for bnum in range(len(bdb.Breakpoint.bpbynumber) - 1, -1, -1): - if bdb.Breakpoint.bpbynumber[bnum] is not None: - break - if bnum == 0: - self.error('no breakpoints set') - return + for bp in reversed(bdb.Breakpoint.bpbynumber): + if not bp: + continue + bnum = bp.number + break + else: + self.error('no breakpoints set') + return else: try: bnum = int(arg) From b309dd371e6db1f01f1d27b8b7d220d12deddb5e Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 16 Dec 2025 16:41:38 +0000 Subject: [PATCH 08/11] update test case --- Lib/test/test_pdb.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index f9974ced9ef416..9a96c5c4d62014 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3478,8 +3478,8 @@ def test_pdb_issue_gh_65052(): (Pdb) continue """ -def test_pdb_issue_142834(): - """See issue-142834 +def test_pdb_commands_last_breakpoint(): + """See GH-142834 >>> def test_function(): ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() @@ -3494,25 +3494,31 @@ def test_pdb_issue_142834(): ... 'p "success"', ... 'end', ... 'continue', - ... '', + ... 'clear 1', + ... 'commands', + ... 'continue', ... ]): ... test_function() - > (2)test_function() + > (2)test_function() -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() (Pdb) break 4 - Breakpoint 1 at :4 + Breakpoint 1 at :4 (Pdb) break 3 - Breakpoint 2 at :3 + Breakpoint 2 at :3 (Pdb) clear 2 - Deleted breakpoint 2 at :3 + Deleted breakpoint 2 at :3 (Pdb) commands (com) p "success" (com) end (Pdb) continue 'success' - > (4)test_function() + > (4)test_function() -> bar = 2 - (Pdb) + (Pdb) clear 1 + Deleted breakpoint 1 at :4 + (Pdb) commands + *** no breakpoints set + (Pdb) continue """ From 37a16bb8b4c09c8f5d43a660dcffdf1a95d17c7b Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Wed, 17 Dec 2025 09:43:25 +0000 Subject: [PATCH 09/11] update err msg and doc --- Doc/library/pdb.rst | 3 ++- Lib/pdb.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index 0bbdc42535290a..8ab3e7ec9ef9d2 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -520,7 +520,8 @@ can be overridden by the local file. To remove all commands from a breakpoint, type ``commands`` and follow it immediately with ``end``; that is, give no commands. - With no *bpnumber* argument, ``commands`` refers to the last breakpoint set. + With no *bpnumber* argument, ``commands`` refers to the most recently set + breakpoint that still exists. You can use breakpoint commands to start your program up again. Simply use the :pdbcmd:`continue` command, or :pdbcmd:`step`, diff --git a/Lib/pdb.py b/Lib/pdb.py index 3ed819e285442d..7060b1f3641c80 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1321,7 +1321,7 @@ def do_commands(self, arg): bnum = bp.number break else: - self.error('no breakpoints set') + self.error('cannot set commands: no existing breakpoint') return else: try: From ba31a407eb2423f2fce2efad3def3c984d6e83cb Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:00:58 +0000 Subject: [PATCH 10/11] fix test --- Lib/test/test_pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 9a96c5c4d62014..32bfc3c90964c5 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3517,7 +3517,7 @@ def test_pdb_commands_last_breakpoint(): (Pdb) clear 1 Deleted breakpoint 1 at :4 (Pdb) commands - *** no breakpoints set + *** cannot set commands: no existing breakpoint (Pdb) continue """ From 482f260b437b47fe2aeac8c3d1d03f38b582dd5f Mon Sep 17 00:00:00 2001 From: Hai Zhu <35182391+cocolato@users.noreply.github.com> Date: Sat, 20 Dec 2025 07:56:56 +0800 Subject: [PATCH 11/11] Fix None value check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartosz Sławecki --- Lib/pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 7060b1f3641c80..4a6bc17e91cf0c 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1316,7 +1316,7 @@ def do_commands(self, arg): """ if not arg: for bp in reversed(bdb.Breakpoint.bpbynumber): - if not bp: + if bp is None: continue bnum = bp.number break