Fix mismatched traceback in pythonrc.py
injection
#25480
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since vscode-python injects
PYTHONSTARTUP
intopythonrc.py
to show the "Ctrl click to launch VS Code Native REPL" message, traceback always shows lines insidepythonrc.py
in the interactive console.Example:
That's because python sets
__main__
to thepythonrc.py
module, which has a__loader__
attribute. The__loader__
object is then exposed in the global namespace of the interactive console. However, linecache uses__loader__
to get the source code, causing the mismatch.After this PR, the traceback points to the right source now:
In the
_pyrepl.__main__
module, there was some comment mentioning this behavior and they set__loader__ = None
to avoid this. See python/cpython#129098 for more information