Skip to content

Commit

Permalink
fix local
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Mar 12, 2024
1 parent f3778e6 commit b83bfec
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions spyder_kernels/customize/spyderpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def default(self, line):
# The pdb command is masked by something
self.print_exclamation_warning()
try:
is_magic = line.startswith("%")
line = TransformerManager().transform_cell(line)
save_stdout = sys.stdout
save_stdin = sys.stdin
Expand All @@ -203,7 +204,16 @@ def default(self, line):

globals["__spyder_builtins__"] = builtins

use_locals_hack = False
if locals is not globals:
if not is_magic:
# For runcell and all magic using locals
# Because the locals() can not be modified
use_locals_hack = False
else:
locals = None

if use_locals_hack:
# Mitigates a behaviour of CPython that makes it difficult
# to work with exec and the local namespace
# See:
Expand Down Expand Up @@ -262,16 +272,16 @@ def default(self, line):
code_ast = fun_ast

try:
exec(compile(code_ast, "<stdin>", "exec"), globals)
exec(compile(code_ast, "<stdin>", "exec"), globals, locals)
finally:
if locals is not globals:
# CLeanup code
if use_locals_hack:
# Cleanup code
globals.pop("_spyderpdb_code", None)
if len(globals["_spyderpdb_locals"]) > 1:
del globals["_spyderpdb_locals"][-1]
else:
del globals["_spyderpdb_locals"]


if capture_last_expression:
out = globals.pop("_spyderpdb_out", None)
Expand Down Expand Up @@ -360,7 +370,7 @@ def stop_here(self, frame):
# This is spyder-kernels internals
return False
return True

def should_continue(self, frame):
"""
Jump to first breakpoint if needed.
Expand Down

0 comments on commit b83bfec

Please sign in to comment.