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

Set sys.last_value / sys.last_exc before entering the debugger #380

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
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
8 changes: 8 additions & 0 deletions lib/python/pyflyby/_dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ def _debug_exception(*exc_info, **kwargs):
# will cause print_verbose_tb to include a line with just a colon.
# TODO: avoid that line.
exc_info = ("", "", exc_info)
if exc_info[1]:
# Explicitly set sys.last_value / sys.last_exc to ensure they are available
# in the debugger. One use case is that this allows users to call
# pyflyby.saveframe() within the debugger.
if sys.version_info < (3, 12):
sys.last_value = exc_info[1]
else:
sys.last_exc = exc_info[1]

with _DebuggerCtx(tty=tty) as pdb:
if debugger_attached:
Expand Down
Loading