8000 gh-83151: Make closure work on pdb by gaogaotiantian · Pull Request #111094 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-83151: Make closure work on pdb #111094

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 13 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Always update local variables
  • Loading branch information
gaogaotiantian committed Oct 20, 2023
commit 8232457a7c6fcccb2da482d65e99f7697877ac93
5 changes: 4 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,10 @@ def _exec_in_closure(self, source, globals, locals):

# Add write-back to update the locals
locals["__pdb_write_back__"] = {}
source += """\nfor key, val in locals().items():\n __pdb_write_back__[key] = val"""
source = ("try:\n" +
textwrap.indent(source, " ") + "\n" +
"finally:\n" +
" for key, val in locals().items():\n __pdb_write_back__[key] = val")

try:
local_vars = list(locals.keys())
Expand Down
8 changes: 7 additions & 1 deletion Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,8 @@ def test_pdb_closure():
... 'lst = [n for n in range(10) if (n % x) == 0]',
... 'lst',
... 'sum(n for n in lst if n > x)',
... 'x = 1; raise Exception()',
... 'x',
... 'def f():',
... ' return x',
... '',
Expand All @@ -2075,11 +2077,15 @@ def test_pdb_closure():
[0, 2, 4, 6, 8]
(Pdb) sum(n for n in lst if n > x)
18
(Pdb) x = 1; raise Exception()
*** Exception
(Pdb) x
1
(Pdb) def f():
... return x
...
(Pdb) f()
2
1
(Pdb) c
"""

Expand Down
0