This commit is contained in:
Tian Gao 2026-05-03 22:52:19 +00:00 committed by GitHub
commit c4191da3d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 1 deletions

View file

@ -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
--------

View file

@ -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."""

View file

@ -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()

View file

@ -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.