Skip to content

Shell integration shows pythonrc.py source for dynamically compiled code #26234

Closed

Description

Behaviour

Python shell integration causes tracebacks for dynamically compiled code to display unrelated lines from pythonrc.py. This tracks the remaining case addressed by #25480.

Environment

  • VS Code 1.141.2 (16507d91be0dc1ce4f94c04d4d0430210b8685d9)
  • Python extension 2026.10.0 (darwin-arm64)
  • Python 3.14.8
  • macOS 27.0.1, arm64

Steps to reproduce

  1. Open a folder containing a Python file in VS Code.
  2. Enable python.terminal.shellIntegration.enabled and select Python 3.14.
  3. Run Python: Start Terminal REPL from the Command Palette.
  4. Enter:
    eval(compile("val", "non-existing-file", "eval"))

Actual result

Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    eval(compile("val", "non-existing-file", "eval"))
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "non-existing-file", line 1, in <module>
    def _initialize():
    ^^^
NameError: name 'val' is not defined. Did you mean: 'eval'?

def _initialize(): comes from pythonrc.py, not the failing expression.

Expected result

The NameError should reference non-existing-file without displaying unrelated startup-script source.

Verification

Reproduced end-to-end in the VS Code integrated terminal with an isolated user-data directory and a copy of the installed extension. The extension set PYTHONSTARTUP automatically to its workspace-storage copy of pythonrc.py; no startup environment variables were set manually.

Adding __spec__ = __loader__ = None at module scope in the isolated extension's startup script, as in #25480, then reloading the window and starting a fresh Terminal REPL removes the incorrect source line:

  File "non-existing-file", line 1, in <module>
NameError: name 'val' is not defined. Did you mean: 'eval'?

Separately, the current repository startup script reproduces outside VS Code on Python 3.13.15 and 3.14.8; both the patch and omitting PYTHONSTARTUP remove the incorrect line.

Related: #25479. Its simple raise 5 example no longer reproduces in the standalone checks on these Python versions; this report covers the remaining dynamic-compile() case.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions