Skip to content

Commit 986a4e1

Browse files
Cleanup unnecessary curframe_locals usage (#124369)
1 parent d7248cd commit 986a4e1

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

Lib/pdb.py

+11-19
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,6 @@ def setup(self, f, tb):
403403
self.tb_lineno[tb.tb_frame] = lineno
404404
tb = tb.tb_next
405405
self.curframe = self.stack[self.curindex][0]
406-
# The f_locals dictionary used to be updated from the actual frame
407-
# locals whenever the .f_locals accessor was called, so it was
408-
# cached here to ensure that modifications were not overwritten. While
409-
# the caching is no longer required now that f_locals is a direct proxy
410-
# on optimized frames, it's also harmless, so the code structure has
411-
# been left unchanged.
412-
self.curframe_locals = self.curframe.f_locals
413406
self.set_convenience_variable(self.curframe, '_frame', self.curframe)
414407

415408
if self._chained_exceptions:
@@ -732,7 +725,7 @@ def _exec_in_closure(self, source, globals, locals):
732725

733726
def default(self, line):
734727
if line[:1] == '!': line = line[1:].strip()
735-
locals = self.curframe_locals
728+
locals = self.curframe.f_locals
736729
globals = self.curframe.f_globals
737730
try:
738731
buffer = line
@@ -960,7 +953,7 @@ def _complete_expression(self, text, line, begidx, endidx):
960953
# Collect globals and locals. It is usually not really sensible to also
961954
# complete builtins, and they clutter the namespace quite heavily, so we
962955
# leave them out.
963-
ns = {**self.curframe.f_globals, **self.curframe_locals}
956+
ns = {**self.curframe.f_globals, **self.curframe.f_locals}
964957
if text.startswith("$"):
965958
# Complete convenience variables
966959
conv_vars = self.curframe.f_globals.get('__pdb_convenience_variables', {})
@@ -991,7 +984,7 @@ def completedefault(self, text, line, begidx, endidx):
991984
# Use rlcompleter to do the completion
992985
state = 0
993986
matches = []
994-
completer = Completer(self.curframe.f_globals | self.curframe_locals)
987+
completer = Completer(self.curframe.f_globals | self.curframe.f_locals)
995988
while (match := completer.complete(text, state)) is not None:
996989
matches.append(match)
997990
state += 1
@@ -1153,7 +1146,7 @@ def do_break(self, arg, temporary = 0):
11531146
try:
11541147
func = eval(arg,
11551148
self.curframe.f_globals,
1156-
self.curframe_locals)
1149+
self.curframe.f_locals)
11571150
except:
11581151
func = arg
11591152
try:
@@ -1458,7 +1451,6 @@ def _select_frame(self, number):
14581451
assert 0 <= number < len(self.stack)
14591452
self.curindex = number
14601453
self.curframe = self.stack[self.curindex][0]
1461-
self.curframe_locals = self.curframe.f_locals
14621454
self.set_convenience_variable(self.curframe, '_frame', self.curframe)
14631455
self.print_stack_entry(self.stack[self.curindex])
14641456
self.lineno = None
@@ -1704,7 +1696,7 @@ def do_debug(self, arg):
17041696
"""
17051697
sys.settrace(None)
17061698
globals = self.curframe.f_globals
1707-
locals = self.curframe_locals
1699+
locals = self.curframe.f_locals
17081700
p = Pdb(self.completekey, self.stdin, self.stdout)
17091701
p.prompt = "(%s) " % self.prompt.strip()
17101702
self.message("ENTERING RECURSIVE DEBUGGER")
@@ -1749,7 +1741,7 @@ def do_args(self, arg):
17491741
self._print_invalid_arg(arg)
17501742
return
17511743
co = self.curframe.f_code
1752-
dict = self.curframe_locals
1744+
dict = self.curframe.f_locals
17531745
n = co.co_argcount + co.co_kwonlyargcount
17541746
if co.co_flags & inspect.CO_VARARGS: n = n+1
17551747
if co.co_flags & inspect.CO_VARKEYWORDS: n = n+1
@@ -1769,23 +1761,23 @@ def do_retval(self, arg):
17691761
if arg:
17701762
self._print_invalid_arg(arg)
17711763
return
1772-
if '__return__' in self.curframe_locals:
1773-
self.message(self._safe_repr(self.curframe_locals['__return__'], "retval"))
1764+
if '__return__' in self.curframe.f_locals:
1765+
self.message(self._safe_repr(self.curframe.f_locals['__return__'], "retval"))
17741766
else:
17751767
self.error('Not yet returned!')
17761768
do_rv = do_retval
17771769

17781770
def _getval(self, arg):
17791771
try:
1780-
return eval(arg, self.curframe.f_globals, self.curframe_locals)
1772+
return eval(arg, self.curframe.f_globals, self.curframe.f_locals)
17811773
except:
17821774
self._error_exc()
17831775
raise
17841776

17851777
def _getval_except(self, arg, frame=None):
17861778
try:
17871779
if frame is None:
1788-
return eval(arg, self.curframe.f_globals, self.curframe_locals)
1780+
return eval(arg, self.curframe.f_globals, self.curframe.f_locals)
17891781
else:
17901782
return eval(arg, frame.f_globals, frame.f_locals)
17911783
except BaseException as exc:
@@ -2029,7 +2021,7 @@ def do_interact(self, arg):
20292021
Start an interactive interpreter whose global namespace
20302022
contains all the (global and local) names found in the current scope.
20312023
"""
2032-
ns = {**self.curframe.f_globals, **self.curframe_locals}
2024+
ns = {**self.curframe.f_globals, **self.curframe.f_locals}
20332025
console = _PdbInteractiveConsole(ns, message=self.message)
20342026
console.interact(banner="*pdb interact start*",
20352027
exitmsg="*exit from pdb interact command*")

0 commit comments

Comments
 (0)