diff --git a/Lib/bdb.py b/Lib/bdb.py index 50cf2b3f5b3e453..0ed8379bac8c1be 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 f15dae13eb384ef..6a1df6e083e9e90 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 000000000000000..a7bcbc4b1aa3224 --- /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.