This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: linecache cannot get source for the __main__ module with a custom loader
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: FFY00, eltoder, ncoghlan, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2020-10-23 05:26 by eltoder, last changed 2022-04-11 14:59 by admin.

File name Uploaded Description Edit eltoder, 2020-10-23 05:26
Pull Requests
URL Status Linked Edit
PR 22908 open python-dev, 2020-10-23 05:30
Messages (1)
msg379408 - (view) Author: Eugene Toder (eltoder) * Date: 2020-10-23 05:26
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
Traceback (most recent call last):
  File "", line 11, in <module>
  File "", line 8, in f
  File "", line 8, in f
  File "", line 8, in f
  [Previous line repeated 2 more times]
  File "", line 7, in f

Note that entries from don't have source code lines.
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86291
2021-05-29 17:12:41FFY00setnosy: + FFY00
2020-12-18 23:30:30eltodersetnosy: + ncoghlan, vstinner
2020-12-16 22:00:43brett.cannonsetnosy: - brett.cannon
2020-12-16 03:07:02eltodersetnosy: + brett.cannon
2020-10-23 05:30:25python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request21839
stage: patch review
2020-10-23 05:26:53eltodercreate