-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-93696: Locate frozen module source with __file__ #93697
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
JelleZijlstra
merged 14 commits into
python:main
from
SnoopJ:gh-93696-pdb-find-frozen-source
Oct 25, 2022
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c91afc1
Locate frozen module source with __file__
SnoopJ 4baf238
Add NEWS entry
SnoopJ a9e9c7a
Merge branch 'main' into gh-93696-pdb-find-frozen-source
SnoopJ ff51687
Add test for listing source for frozen modules
SnoopJ e58c4dc
Merge branch 'main' into gh-93696-pdb-find-frozen-source
SnoopJ 793f2bf
Merge branch 'main' into gh-93696-pdb-find-frozen-source
SnoopJ e88d3a5
Add issue reference to frozen_list test
SnoopJ 47eae63
Merge branch 'main' into gh-93696-pdb-find-frozen-source
SnoopJ 116c26b
Use assertIn() instead of assertTrue()
SnoopJ 163f3df
Link to pdb module docs in news fragment
SnoopJ c716862
Merge branch 'main' into gh-93696-pdb-find-frozen-source
SnoopJ 55f2a0f
Clarify that gh-89815 is a superceding issue
SnoopJ 3facf2f
Merge branch 'main' into gh-93696-pdb-find-frozen-source
SnoopJ a2589c9
Only apply filename workaround for string attribute
SnoopJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2104,6 +2104,52 @@ def inner(v): pass | |
stdout, stderr = self.run_pdb_script(script, commands) | ||
self.assertFalse(stderr) | ||
|
||
def test_gh_93696_frozen_list(self): | ||
frozen_src = """ | ||
def func(): | ||
x = "Sentinel string for gh-93696" | ||
print(x) | ||
""" | ||
host_program = """ | ||
import os | ||
import sys | ||
|
||
def _create_fake_frozen_module(): | ||
with open('gh93696.py') as f: | ||
src = f.read() | ||
|
||
# this function has a co_filename as if it were in a frozen module | ||
dummy_mod = compile(src, "<frozen gh93696>", "exec") | ||
func_code = dummy_mod.co_consts[0] | ||
|
||
mod = type(sys)("gh93696") | ||
mod.func = type(lambda: None)(func_code, mod.__dict__) | ||
mod.__file__ = 'gh93696.py' | ||
|
||
return mod | ||
|
||
mod = _create_fake_frozen_module() | ||
mod.func() | ||
""" | ||
commands = """ | ||
break 20 | ||
continue | ||
step | ||
list | ||
quit | ||
""" | ||
with open('gh93696.py', 'w') as f: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little weird that we're writing into the CWD, but that appears to be what the other tests in this file are doing too. |
||
f.write(textwrap.dedent(frozen_src)) | ||
|
||
with open('gh93696_host.py', 'w') as f: | ||
f.write(textwrap.dedent(host_program)) | ||
|
||
self.addCleanup(os_helper.unlink, 'gh93696.py') | ||
self.addCleanup(os_helper.unlink, 'gh93696_host.py') | ||
stdout, stderr = self._run_pdb(["gh93696_host.py"], commands) | ||
# verify that pdb found the source of the "frozen" function | ||
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found") | ||
|
||
class ChecklineTests(unittest.TestCase): | ||
def setUp(self): | ||
linecache.clearcache() # Pdb.checkline() uses linecache.getline() | ||
|
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allow :mod:`pdb` to locate source for frozen modules in the standard library. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if
__file__
is not a string? It looks likeget_file_breaks
will crash in that case. We should probably just ignore__file__
in that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's a good point. I would think it's a small edge, but it's easy to be more cautious about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it's important for a debugger to be resilient in the face of unusual program state.