Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
brandtbucher merged 13 commits intopython:mainfromgaogaotiantian:pdb-closure
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
720a584
Make closure work on pdb
gaogaotiantianOct 20, 2023
8232457
Always update local variables
gaogaotiantianOct 20, 2023
8df6d2b
📜🤖 Added by blurb_it.
blurb-it[bot]Oct 20, 2023
9c68aef
Merge branch 'main' into pdb-closure
gaogaotiantianMay 4, 2024
fe5a6f6
Update the code for pep 667
gaogaotiantianMay 5, 2024
cc21873
Remove blank line
gaogaotiantianMay 5, 2024
d37b5a7
Merge branch 'main' into pdb-closure
gaogaotiantianMay 5, 2024
cd46a05
Update 2023-10-20-03-50-17.gh-issue-83151.bcsD40.rst
gaogaotiantianMay 5, 2024
d04bc5d
Merge branch 'main' into pdb-closure
gaogaotiantianMay 5, 2024
aa91238
Fix test for breakpoint change
gaogaotiantianMay 5, 2024
7650aa9
Apply suggestions from code review
gaogaotiantianMay 6, 2024
3c44f88
Fix some typos in review and add exception check
gaogaotiantianMay 6, 2024
18e7a16
Apply suggestions from code review
gaogaotiantianMay 6, 2024
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
PrevPrevious commit
NextNext commit
Fix some typos in review and add exception check
  • Loading branch information
@gaogaotiantian
gaogaotiantian committedMay 6, 2024
commit3c44f8814767f0713c0987d15664dba9a8d8db1d
15 changes: 8 additions & 7 deletionsLib/pdb.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -638,7 +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")
if any(isinstance(const, CodeType) for const in code.co_consts):
ifnotany(isinstance(const, CodeType) for const in code.co_consts):
return False

# locals could be a proxy which does not support pop
Expand All@@ -664,8 +664,6 @@ def _exec_in_closure(self, source, globals, locals):
"finally:\n" +
" __pdb_eval__['write_back'] = locals()")

local_vars = list(locals_copy.keys())

# Build a closure source code with freevars from locals like:
# def outer():
# var = None
Expand All@@ -674,17 +672,20 @@ def _exec_in_closure(self, source, globals, locals):
# <source>
# return __pdb_scope.__code__
source_with_closure = ("def __pdb_outer():\n" +
"\n".join(f" {var} = None" for var inlocal_vars) + "\n" +
"\n".join(f" {var} = None" for var inlocals_copy) + "\n" +
" def __pdb_scope():\n" +
"\n".join(f" nonlocal {var}" for var inlocal_vars) + "\n" +
"\n".join(f" nonlocal {var}" for var inlocals_copy) + "\n" +
textwrap.indent(source, " ") + "\n" +
" return __pdb_scope.__code__"
)

# 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()
exec(source_with_closure, {}, locals_copy)
try:
exec(source_with_closure, {}, locals_copy)
except Exception:
return False
code = locals_copy.pop("__pdb_outer")()

cells = tuple(types.CellType(locals_copy.get(var)) for var in code.co_freevars)
Expand All@@ -695,7 +696,7 @@ def _exec_in_closure(self, source, globals, locals):
return False

# get the data we need from the statement
pdb_eval = locals_copy["__pdb_eval__]
pdb_eval = locals_copy["__pdb_eval__"]

# __pdb_eval__ should not be updated back to locals
pdb_eval["write_back"].pop("__pdb_eval__")
Expand Down
3 changes: 3 additions & 0 deletionsLib/test/test_pdb.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2239,6 +2239,7 @@ def test_pdb_closure():
... 'g',
... 'y = y',
... 'global g; g',
... 'global g; (lambda: g)()',
... '(lambda: x)()',
... '(lambda: g)()',
... 'lst = [n for n in range(10) if (n % x) == 0]',
Expand All@@ -2263,6 +2264,8 @@ def test_pdb_closure():
*** NameError: name 'y' is not defined
(Pdb) global g; g
1
(Pdb) global g; (lambda: g)()
1
(Pdb) (lambda: x)()
2
(Pdb) (lambda: g)()
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp