FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-60115: Support frozen modules for linecache.getline() by gaogaotiantian · Pull Request #131638 · python/cpython · GitHub

/ cpython Public

gh-60115: Support frozen modules for linecache.getline() - #131638

Merged
gaogaotiantian merged 7 commits into
python:mainfrom
gaogaotiantian:frozen-source
Apr 2, 2025
Merged

gh-60115: Support frozen modules for linecache.getline()#131638
gaogaotiantian merged 7 commits into
python:mainfrom
gaogaotiantian:frozen-source

Conversation

gaogaotiantian commented Mar 23, 2025
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

When we try to get source lines for frozen modules with linecache.getlines(), it will be rejected because frozen modules have file names starting with <. However, we can deal with that case, if we have module_globals - we can read __file__ in module_globals to get the real file and read it.

pdb suffers from it when debugging frozen modules - list deals with it but stack entry and ll does not. I could fix it in pdb, but I think linecache could benefit from this change so it helps all users. This is also a pretty straighforward change, just convert the filename passed in to the actual file name and the rest is the same.

Copy link
Copy Markdown
Member Author

Not sure if a whatsnew entry should be added for 3.14. Is this a significant enough change?

picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Just some small nits. Maybe a test with a frozen module with some content or do we have no way to do it easily?

Comment thread Lib/linecache.py Outdated
Comment thread Lib/linecache.py Outdated
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

Copy link
Copy Markdown
Member Author

Maybe a test with a frozen module with some content or do we have no way to do it easily?

The difficult part is to get the module global of it. It's not trivial to get the frame of a frozen module in linecache tests. However, after this, I'll polish pdb and I'll add more tests there to cover the real case. It's much easier (and practical) to do it in pdb.

gaogaotiantian changed the title gh-60115: Support frozen modules for linecache.getlines() gh-60115: Support frozen modules for linecache.getline() Mar 23, 2025

Copy link
Copy Markdown
Member Author

Hey @iritkatriel , do you mind taking a quick look at this?

iritkatriel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, though I wouldn't backport this.

Copy link
Copy Markdown
Member Author

I don't plan to backport this. I think it's a new feature. Should we put something in the whatsnew entry?

Copy link
Copy Markdown
Member

Might as well, in case someone is surprised by something.

Copy link
Copy Markdown
Member Author

Not sure if my claim is entirely correct. There might be cases when __file__ is not available for frozen modules?

Copy link
Copy Markdown
Member

I don't know.

Copy link
Copy Markdown
Member Author

Okay I updated the documentation, which should clear things up a bit.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL