Skip to content

Cleanup unnecessary curframe_locals usage #124369

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

Merged
merged 1 commit into from
Sep 26, 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
30 changes: 11 additions & 19 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,6 @@ def setup(self, f, tb):
self.tb_lineno[tb.tb_frame] = lineno
tb = tb.tb_next
self.curframe = self.stack[self.curindex][0]
# The f_locals dictionary used to be updated from the actual frame
# locals whenever the .f_locals accessor was called, so it was
# cached here to ensure that modifications were not overwritten. While
# the caching is no longer required now that f_locals is a direct proxy
# on optimized frames, it's also harmless, so the code structure has
# been left unchanged.
self.curframe_locals = self.curframe.f_locals
self.set_convenience_variable(self.curframe, '_frame', self.curframe)

if self._chained_exceptions:
Expand Down Expand Up @@ -727,7 +720,7 @@ def _exec_in_closure(self, source, globals, locals):

def default(self, line):
if line[:1] == '!': line = line[1:].strip()
locals = self.curframe_locals
locals = self.curframe.f_locals
globals = self.curframe.f_globals
try:
buffer = line
Expand Down Expand Up @@ -955,7 +948,7 @@ def _complete_expression(self, text, line, begidx, endidx):
# Collect globals and locals. It is usually not really sensible to also
# complete builtins, and they clutter the namespace quite heavily, so we
# leave them out.
ns = {**self.curframe.f_globals, **self.curframe_locals}
ns = {**self.curframe.f_globals, **self.curframe.f_locals}
if text.startswith("$"):
# Complete convenience variables
conv_vars = self.curframe.f_globals.get('__pdb_convenience_variables', {})
Expand Down Expand Up @@ -986,7 +979,7 @@ def completedefault(self, text, line, begidx, endidx):
# Use rlcompleter to do the completion
state = 0
matches = []
completer = Completer(self.curframe.f_globals | self.curframe_locals)
completer = Completer(self.curframe.f_globals | self.curframe.f_locals)
while (match := completer.complete(text, state)) is not None:
matches.append(match)
state += 1
Expand Down Expand Up @@ -1148,7 +1141,7 @@ def do_break(self, arg, temporary = 0):
try:
func = eval(arg,
self.curframe.f_globals,
self.curframe_locals)
self.curframe.f_locals)
except:
func = arg
try:
Expand Down Expand Up @@ -1453,7 +1446,6 @@ def _select_frame(self, number):
assert 0 <= number < len(self.stack)
self.curindex = number
self.curframe = self.stack[self.curindex][0]
self.curframe_locals = self.curframe.f_locals
self.set_convenience_variable(self.curframe, '_frame', self.curframe)
self.print_stack_entry(self.stack[self.curindex])
self.lineno = None
Expand Down Expand Up @@ -1694,7 +1686,7 @@ def do_debug(self, arg):
"""
sys.settrace(None)
globals = self.curframe.f_globals
locals = self.curframe_locals
locals = self.curframe.f_locals
p = Pdb(self.completekey, self.stdin, self.stdout)
p.prompt = "(%s) " % self.prompt.strip()
self.message("ENTERING RECURSIVE DEBUGGER")
Expand Down Expand Up @@ -1739,7 +1731,7 @@ def do_args(self, arg):
self._print_invalid_arg(arg)
return
co = self.curframe.f_code
dict = self.curframe_locals
dict = self.curframe.f_locals
n = co.co_argcount + co.co_kwonlyargcount
if co.co_flags & inspect.CO_VARARGS: n = n+1
if co.co_flags & inspect.CO_VARKEYWORDS: n = n+1
Expand All @@ -1759,23 +1751,23 @@ def do_retval(self, arg):
if arg:
self._print_invalid_arg(arg)
return
if '__return__' in self.curframe_locals:
self.message(self._safe_repr(self.curframe_locals['__return__'], "retval"))
if '__return__' in self.curframe.f_locals:
self.message(self._safe_repr(self.curframe.f_locals['__return__'], "retval"))
else:
self.error('Not yet returned!')
do_rv = do_retval

def _getval(self, arg):
try:
return eval(arg, self.curframe.f_globals, self.curframe_locals)
return eval(arg, self.curframe.f_globals, self.curframe.f_locals)
except:
self._error_exc()
raise

def _getval_except(self, arg, frame=None):
try:
if frame is None:
return eval(arg, self.curframe.f_globals, self.curframe_locals)
return eval(arg, self.curframe.f_globals, self.curframe.f_locals)
else:
return eval(arg, frame.f_globals, frame.f_locals)
except BaseException as exc:
Expand Down Expand Up @@ -2019,7 +2011,7 @@ def do_interact(self, arg):
Start an interactive interpreter whose global namespace
contains all the (global and local) names found in the current scope.
"""
ns = {**self.curframe.f_globals, **self.curframe_locals}
ns = {**self.curframe.f_globals, **self.curframe.f_locals}
console = _PdbInteractiveConsole(ns, message=self.message)
console.interact(banner="*pdb interact start*",
exitmsg="*exit from pdb interact command*")
Expand Down
Loading