[issue42125] linecache cannot get source for the __main__ module with a custom loader
Eugene Toder
report at bugs.python.org
Fri Oct 23 01:26:53 EDT 2020
New submission from Eugene Toder <eltoder at gmail.com>:
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.
----------
components: Library (Lib)
files: t.zip
messages: 379408
nosy: eltoder
priority: normal
severity: normal
status: open
title: linecache cannot get source for the __main__ module with a custom loader
type: behavior
versions: Python 3.10
Added file: https://bugs.python.org/file49536/t.zip
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42125>
_______________________________________
More information about the Python-bugs-list
mailing list