-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as duplicate of#137576
Closed as duplicate of#137576
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
When PYTHONSTARTUP
environment variable is set, the startup file execution permanently leaves a __loader__
attribute in the __main__
module's __dict__
. This causes linecache to use __loader__.get_source()
for source code retrieval, resulting in tracebacks in the interactive console incorrectly showing source lines from the PYTHONSTARTUP
file instead of the actual executed code.
The issue occurs in Modules/main.c
in pymain_run_startup()
:
pymain_run_startup()
calls_PyRun_SimpleFileObject(fp, startup, 0, &cf)
_PyRun_SimpleFileObject()
inPython/pythonrun.c
sets__loader__
viaset_main_loader(dict, filename, "SourceFileLoader")
- The cleanup code only removes
__file__
and__cached__
but not__loader__
:
Lines 533 to 543 in 04c4628
done: if (set_file_name) { if (PyDict_PopString(dict, "__file__", NULL) < 0) { PyErr_Print(); } if (PyDict_PopString(dict, "__cached__", NULL) < 0) { PyErr_Print(); } } Py_XDECREF(main_module); return ret;
CPython versions tested on:
3.13
Operating systems tested on:
Windows (It seems this issue only appears on Windows)
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error