Skip to content

Commit da6629c

Browse files
gh-149309: Use BaseException as BdbQuit's base class (#149337)
1 parent 4e3d5ec commit da6629c

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎Doc/library/bdb.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ The following exception is defined:
1717

1818
Exception raised by the :class:`Bdb` class for quitting the debugger.
1919

20+
.. versionchanged:: 3.16
21+
:exc:`BdbQuit` now inherits from :exc:`BaseException` instead of
22+
:exc:`Exception`.
23+
2024

2125
The :mod:`!bdb` module also defines two classes:
2226

‎Doc/whatsnew/3.16.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ asyncio
119119
(Contributed by Sam Bull in :gh:`94984`.)
120120

121121

122+
bdb
123+
---
124+
125+
* :exc:`bdb.BdbQuit` is now a subclass of :exc:`BaseException`, instead of
126+
:exc:`Exception`, to allow it to be used for cleanly exiting the debugger without
127+
being accidentally caught by user code.
128+
(Contributed by Tian Gao in :gh:`149337`.)
129+
130+
122131
bz2
123132
---
124133

‎Lib/bdb.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
GENERATOR_AND_COROUTINE_FLAGS = CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR
1414

1515

16-
class BdbQuit(Exception):
16+
class BdbQuit(BaseException):
1717
"""Exception to give up completely."""
1818

1919

‎Lib/test/test_bdb.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,15 @@ def test_format_stack_entry_no_lineno(self):
12481248
self.assertIn('Warning: lineno is None',
12491249
Bdb().format_stack_entry((sys._getframe(), None)))
12501250

1251+
def test_bdb_quit_base_exception(self):
1252+
# gh-149309
1253+
try:
1254+
raise _bdb.BdbQuit()
1255+
except Exception:
1256+
self.fail(f'BdbQuit should not be caught by Exception')
1257+
except BaseException:
1258+
pass
1259+
12511260

12521261
if __name__ == "__main__":
12531262
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

0 commit comments

Comments
 (0)