New submission from Eugene Toder <elto...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue42125>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to