8000 gh-93696: Locate frozen module source with __file__ by SnoopJ · Pull Request #93697 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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
merged 14 commits into from
Oct 25, 2022
Merged
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
Next Next commit
Locate frozen module source with __file__
  • Loading branch information
SnoopJ committed Jun 10, 2022
commit c91afc1c0a7b5ba780e960ca495f1b064d410fb5
4 changes: 4 additions & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,10 @@ def do_list(self, arg):
if last is None:
last = first + 10
filename = self.curframe.f_code.co_filename
# gh-93696: stdlib frozen modules provide a useful __file__ (see also gh-89815)
if filename.startswith("<frozen"):
if "__file__" in self.curframe.f_globals:
filename = self.curframe.f_globals["__file__"]
Copy link
Member
@JelleZijlstra JelleZijlstra Oct 25, 2022

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 like get_file_breaks will crash in that case. We should probably just ignore __file__ in that case.

Copy link
Contributor Author

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.

Copy link
Member

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.

breaklist = self.get_file_breaks(filename)
try:
lines = linecache.getlines(filename, self.curframe.f_globals)
Expand Down
0