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
linecache cannot get source for the __main__ module with a custom loader #86291
Comments
If a module has a loader, linecache calls its get_source() passing __name__ as the argument. This works most of the time, except that the __main__ module has it set to "__main__", which is commonly not the real name of the module. Luckily, we now have __spec__ which has the real name, so we can just use it. Attached zip file reproduces the problem:
$ python t.zip
Traceback (most recent call last):
...
File "t.zip/t.py", line 11, in <module>
File "t.zip/t.py", line 8, in f
File "t.zip/t.py", line 8, in f
File "t.zip/t.py", line 8, in f
[Previous line repeated 2 more times]
File "t.zip/t.py", line 7, in f
ValueError Note that entries from t.py don't have source code lines. |
eltoder
mannequin
added
3.10
only security fixes
stdlib
Python modules in the Lib dir
type-bug
An unexpected behavior, bug, or error
labels
Oct 23, 2020
serhiy-storchaka
pushed a commit
that referenced
this issue
Feb 20, 2024
…2908) This allows getting source code for the __main__ module when a custom loader is used.
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Feb 20, 2024
…pythonGH-22908) This allows getting source code for the __main__ module when a custom loader is used. (cherry picked from commit e976bab) Co-authored-by: Eugene Toder <eltoder@users.noreply.github.com>
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Feb 20, 2024
…pythonGH-22908) This allows getting source code for the __main__ module when a custom loader is used. (cherry picked from commit e976bab) Co-authored-by: Eugene Toder <eltoder@users.noreply.github.com>
This was referenced Feb 20, 2024
serhiy-storchaka
added
3.11
only security fixes
3.12
bugs and security fixes
3.13
new features, bugs and security fixes
labels
Feb 20, 2024
serhiy-storchaka
pushed a commit
that referenced
this issue
Feb 20, 2024
serhiy-storchaka
pushed a commit
that referenced
this issue
Feb 20, 2024
woodruffw
pushed a commit
to woodruffw-forks/cpython
that referenced
this issue
Mar 4, 2024
…pythonGH-22908) This allows getting source code for the __main__ module when a custom loader is used.
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
…pythonGH-22908) This allows getting source code for the __main__ module when a custom loader is used.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: