https://github.com/python/cpython/commit/da6629cf667769f7740f27c4a56795d75616996c
commit: da6629cf667769f7740f27c4a56795d75616996c
branch: main
author: Tian Gao <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2026-10-19T15:41:59-07:00
summary:
gh-149309: Use BaseException as BdbQuit's base class (#149337)
files:
A Misc/NEWS.d/next/Library/2026-05-03-22-52-07.gh-issue-149309.gXhk9Y.rst
M Doc/library/bdb.rst
M Doc/whatsnew/3.16.rst
M Lib/bdb.py
M Lib/test/test_bdb.py
diff --git a/Doc/library/bdb.rst b/Doc/library/bdb.rst
index c8b48901901f98c..a94625773632dbc 100644
--- a/Doc/library/bdb.rst
+++ b/Doc/library/bdb.rst
@@ -17,6 +17,10 @@ The following exception is defined:
Exception raised by the :class:`Bdb` class for quitting the debugger.
+ .. versionchanged:: 3.16
+ :exc:`BdbQuit` now inherits from :exc:`BaseException` instead of
+ :exc:`Exception`.
+
The :mod:`!bdb` module also defines two classes:
diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst
index a1d7d1eaae7d526..09087c2fefda554 100644
--- a/Doc/whatsnew/3.16.rst
+++ b/Doc/whatsnew/3.16.rst
@@ -119,6 +119,15 @@ asyncio
(Contributed by Sam Bull in :gh:`94984`.)
+bdb
+---
+
+* :exc:`bdb.BdbQuit` is now a subclass of :exc:`BaseException`, instead of
+ :exc:`Exception`, to allow it to be used for cleanly exiting the debugger
without
+ being accidentally caught by user code.
+ (Contributed by Tian Gao in :gh:`149337`.)
+
+
bz2
---
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 0ed8379bac8c1be..f0601913ab3c8df 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -13,7 +13,7 @@
GENERATOR_AND_COROUTINE_FLAGS = CO_GENERATOR | CO_COROUTINE |
CO_ASYNC_GENERATOR
-class BdbQuit(Exception):
+class BdbQuit(BaseException):
"""Exception to give up completely."""
diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py
index 6a1df6e083e9e90..8805d098ff22dc2 100644
--- a/Lib/test/test_bdb.py
+++ b/Lib/test/test_bdb.py
@@ -1248,6 +1248,15 @@ def test_format_stack_entry_no_lineno(self):
self.assertIn('Warning: lineno is None',
Bdb().format_stack_entry((sys._getframe(), None)))
+ def test_bdb_quit_base_exception(self):
+ # gh-149309
+ try:
+ raise _bdb.BdbQuit()
+ except Exception:
+ self.fail(f'BdbQuit should not be caught by Exception')
+ except BaseException:
+ pass
+
if __name__ == "__main__":
unittest.main()
diff --git
a/Misc/NEWS.d/next/Library/2026-05-03-22-52-07.gh-issue-149309.gXhk9Y.rst
b/Misc/NEWS.d/next/Library/2026-05-03-22-52-07.gh-issue-149309.gXhk9Y.rst
new file mode 100644
index 000000000000000..69df9f1f6daff3f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-05-03-22-52-07.gh-issue-149309.gXhk9Y.rst
@@ -0,0 +1 @@
+:exc:`bdb.BdbQuit` is now a subclass of :exc:`BaseException`, instead of
:exc:`Exception`, to allow it to be used for cleanly exiting the debugger
without being accidentally caught by user code.
_______________________________________________
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]