From fc235985508d0431192405b46c6fbfb209069048 Mon Sep 17 00:00:00 2001 From: telamonian Date: Mon, 2 May 2022 19:40:28 -0400 Subject: [PATCH] fix uncaught `BdbQuit` exceptions on ipdb `exit` - `BdbQuit` is now handled in the top-most scope of `InteractiveShell.run_code`. This ensures that `BdbQuit` is correctly handled but can still do its job of breaking out of all user code/loops/further breakpoint requests. Hopefully will work better than previous attempts, which put the `BdqQuit` handling in `Pdb.set_trace` - fixes: - jupyterlab/jupyterlab#12501 - refs: - ipython/ipython#876 - ipython/ipython#1273 - ipython/ipython#4474 - ipython/ipython#5306 - ipython/ipython#9731 - ipython/ipython#9942 - ipython/ipython#9950 - ipython/ipython#10006 - ipython/ipython#12378 --- .gitignore | 10 +++++++++- IPython/core/debugger.py | 1 - IPython/core/interactiveshell.py | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5b45fd4d6b8..f4736530e10 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,13 @@ __pycache__ .pytest_cache .python-version venv*/ -.idea/ .mypy_cache/ + +# jetbrains ide stuff +*.iml +.idea/ + +# vscode ide stuff +*.code-workspace +.history +.vscode diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py index 8e3dd9678cd..ba12e3eac39 100644 --- a/IPython/core/debugger.py +++ b/IPython/core/debugger.py @@ -101,7 +101,6 @@ # #***************************************************************************** -import bdb import inspect import linecache import sys diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index ea9f6310ba5..371a3dad77e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -14,6 +14,7 @@ import abc import ast import atexit +import bdb import builtins as builtin_mod import dis import functools @@ -3403,6 +3404,11 @@ async def run_code(self, code_obj, result=None, *, async_=False): result.error_in_exec = e self.showtraceback(exception_only=True) warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1) + except bdb.BdbQuit: + etype, value, tb = sys.exc_info() + if result is not None: + result.error_in_exec = value + # the BdbQuit stops here except self.custom_exceptions: etype, value, tb = sys.exc_info() if result is not None: