Skip to content
Merged
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
  • Loading branch information
gaogaotiantian and brandtbucher authored May 6, 2024
commit 7650aa95828b12dc285c7dfd7768824f43d81bfc
11 changes: 4 additions & 7 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,7 @@ def _exec_in_closure(self, source, globals, locals):
# Otherwise, we can just raise an exception and normal exec will be used.

code = compile(source, "<string>", "exec")
for const in code.co_consts:
if isinstance(const, CodeType):
break
else:
if any(isinstance(const, CodeType) for const in code.co_consts):
return False

# locals could be a proxy which does not support pop
Expand All @@ -665,7 +662,7 @@ def _exec_in_closure(self, source, globals, locals):
source = ("try:\n" +
textwrap.indent(source, " ") + "\n" +
"finally:\n" +
" __pdb_eval__['write_back'].update(locals())")
" __pdb_eval__['write_back'] = locals()")

local_vars = list(locals_copy.keys())
Comment thread
gaogaotiantian marked this conversation as resolved.
Outdated

Expand All @@ -687,7 +684,7 @@ def _exec_in_closure(self, source, globals, locals):
# Get the code object of __pdb_scope()
# The exec fills locals_copy with the __pdb_outer() function and we can call
# that to get the code object of __pdb_scope()
code = exec(source_with_closure, {}, locals_copy)
exec(source_with_closure, {}, locals_copy)
code = locals_copy.pop("__pdb_outer")()

cells = tuple(types.CellType(locals_copy.get(var)) for var in code.co_freevars)
Expand All @@ -698,7 +695,7 @@ def _exec_in_closure(self, source, globals, locals):
return False
Comment thread
brandtbucher marked this conversation as resolved.

# get the data we need from the statement
pdb_eval = locals_copy.pop("__pdb_eval__")
pdb_eval = locals_copy["__pdb_eval__]

# __pdb_eval__ should not be updated back to locals
pdb_eval["write_back"].pop("__pdb_eval__")
Comment thread
brandtbucher marked this conversation as resolved.
Expand Down