Repository navigation
Commit 7ea2321
Fix mismatched traceback in
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:
<img width="1199" height="732" alt="image"
src="https://github.com/user-attachments/assets/7c68a20b-7b3c-4f32-bc76-3e73a61282e5"
/>
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](https://github.com/python/cpython/blob/a756a4b95341cda63298fb5628b56c32f43f4f1e/Lib/linecache.py#L231),
causing the mismatch.
After this PR, the traceback points to the right source now:
<img width="1223" height="488" alt="image"
src="https://github.com/user-attachments/assets/b4d1635b-9137-463d-91ab-34b7d178e98d"
/>
In the [`_pyrepl.__main__`
module](https://github.com/python/cpython/blob/main/Lib/_pyrepl/__main__.py),
there was some comment mentioning this behavior and they set `__loader__
= None` to avoid this. See python/cpython#129098 for more information
---------
Co-authored-by: Eleanor Boyd <26030610+eleanorjboyd@users.noreply.github.com>
Co-authored-by: Eduardo Villalpando Mello <eduardovil@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>pythonrc.py injection (#25480)1 parent bbd2d7d commit 7ea2321
2 files changed
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
1 | 8 | | |
2 | 9 | | |
3 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
84 | 103 | | |
85 | 104 | | |
86 | 105 | | |
| |||
0 commit comments