https://github.com/python/cpython/commit/630920e45e2ee9fe9bef44bf4a70c95868c58afb
commit: 630920e45e2ee9fe9bef44bf4a70c95868c58afb
branch: main
author: Tian Gao <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2026-10-19T15:03:14-07:00
summary:

gh-149015: Fix clear_all_file_breaks for breakpoints sharing a line in bdb 
(#159748)

files:
A Misc/NEWS.d/next/Library/2026-10-19-00-00-00.gh-issue-149015.bdb.rst
M Lib/bdb.py
M Lib/test/test_bdb.py

diff --git a/Lib/bdb.py b/Lib/bdb.py
index 50cf2b3f5b3e45..0ed8379bac8c1b 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -747,7 +747,7 @@ def clear_all_file_breaks(self, filename):
             return 'There are no breakpoints in %s' % filename
         for line in self.breaks[filename]:
             blist = Breakpoint.bplist[filename, line]
-            for bp in blist:
+            for bp in blist[:]:
                 bp.deleteMe()
         del self.breaks[filename]
         return None
diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py
index f15dae13eb384e..6a1df6e083e9e9 100644
--- a/Lib/test/test_bdb.py
+++ b/Lib/test/test_bdb.py
@@ -965,6 +965,17 @@ def main():
             with TracerRun(self) as tracer:
                 tracer.runcall(tfunc_import)
 
+    def test_clear_all_file_breaks_same_line(self):
+        reset_Breakpoint()
+        self.addCleanup(reset_Breakpoint)
+        debugger = Bdb()
+        for _ in range(3):
+            self.assertIsNone(debugger.set_break(__file__, 1))
+        self.assertIsNone(debugger.clear_all_file_breaks(__file__))
+        self.assertEqual(debugger.get_all_breaks(), {})
+        self.assertEqual(_bdb.Breakpoint.bplist, {})
+        self.assertTrue(all(bp is None for bp in _bdb.Breakpoint.bpbynumber))
+
     def test_clear_at_no_bp(self):
         self.expect_set = [
             ('line', 2, 'tfunc_import'), ('clear', (__file__, 1))
diff --git 
a/Misc/NEWS.d/next/Library/2026-10-19-00-00-00.gh-issue-149015.bdb.rst 
b/Misc/NEWS.d/next/Library/2026-10-19-00-00-00.gh-issue-149015.bdb.rst
new file mode 100644
index 00000000000000..a7bcbc4b1aa322
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-10-19-00-00-00.gh-issue-149015.bdb.rst
@@ -0,0 +1,2 @@
+Fix :meth:`bdb.Bdb.clear_all_file_breaks` leaving breakpoints behind when
+multiple breakpoints are set on the same line.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to