diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 53628b2ff46..4eece1d8d78 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -789,6 +789,14 @@ base64 (Contributed by Gregory P. Smith in :gh:`146311`.) +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`.) + + binascii -------- diff --git a/Lib/bdb.py b/Lib/bdb.py index 50cf2b3f5b3..9d4243d8ff7 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 f15dae13eb3..53fda185eb7 100644 --- a/Lib/test/test_bdb.py +++ b/Lib/test/test_bdb.py @@ -1237,6 +1237,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 00000000000..69df9f1f6da --- /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.