Skip to content

Commit

Permalink
Preserve changes to frame locals when going up/down in the stack frame
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jul 11, 2021
1 parent 6c01e9b commit 1337bbf
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions IPython/core/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ def __init__(self, color_scheme=None, completekey=None,
# list of predicates we use to skip frames
self._predicates = self.default_predicates

# To save frame locals so we can restore them on up/down
self.frame_locals = []

def set_colors(self, scheme):
"""Shorthand access to the color table scheme selector method."""
self.color_scheme_table.set_active_scheme(scheme)
Expand Down Expand Up @@ -351,6 +354,17 @@ def hidden_frames(self, stack):
ip_hide = [h if i > ip_start[0] else True for (i, h) in enumerate(ip_hide)]
return ip_hide

def preloop(self):
"""
Save a copy of all frame locals so changes to them are not lost
when going up/down in the stack frame.
"""
self.frame_locals = [
stack_entry[0].f_locals.copy() for stack_entry in self.stack
]
self.curframe_locals = self.frame_locals[self.curindex]
super().preloop()

def interaction(self, frame, traceback):
try:
OldPdb.interaction(self, frame, traceback)
Expand All @@ -369,6 +383,11 @@ def precmd(self, line):

return line

def postcmd(self, stop, line):
"""Set current frame locals using the ones we saved in preloop."""
self.curframe_locals = self.frame_locals[self.curindex]
return super().postcmd(stop, line)

def new_do_frame(self, arg):
OldPdb.do_frame(self, arg)

Expand Down

0 comments on commit 1337bbf

Please sign in to comment.