Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyflyby-dbg: Support chained exceptions #381

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/python/pyflyby/_dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,27 @@ def _debug_exception(*exc_info, **kwargs):
# keep the process waiting for debugger to attach.
pdb.postloop = _prompt_continue_waiting_for_debugger
print_verbose_tb(*exc_info)
pdb.interaction(None, exc_info[2])
# Starting Py3.13, pdb.interaction() supports chained exceptions in case
# exception (and not traceback) is specified. This support is backported
# to IPython8.16 for earlier Python versions. So the conditions where
# chained exceptions won't be supported from here would be with the
# Python version < 3.13 and ipython not installed, or IPython's version
# is lesser than 8.16.
tb_or_exc = exc_info[2]
if sys.version_info < (3, 13):
# Check if the instance is of IPython's Pdb and its version.
try:
import IPython
if IPython.__version__ >= '8.16':
Carreau marked this conversation as resolved.
Show resolved Hide resolved
from IPython.core.debugger import Pdb as IPdb
# This is expected to be True, hence just a safe check.
if isinstance(pdb, IPdb):
tb_or_exc = exc_info[1]
except ImportError:
umairanis03 marked this conversation as resolved.
Show resolved Hide resolved
pass
else:
tb_or_exc = exc_info[1]
pdb.interaction(None, tb_or_exc)


def _debug_code(arg, globals=None, locals=None, auto_import=True, tty="/dev/tty"):
Expand Down
Loading