Skip to content

Conversation

CNSeniorious000
Copy link

@CNSeniorious000 CNSeniorious000 commented Sep 22, 2025

Since vscode-python injects PYTHONSTARTUP into pythonrc.py to show the "Ctrl click to launch VS Code Native REPL" message, traceback always shows lines inside pythonrc.py in the interactive console.

Example:

image

That's because python sets __main__ to the pythonrc.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:

image

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant