Skip to content

Terminal REPL: >>> prompt disappears after assigning to int (pythonrc.py PS1 breaks when builtins are shadowed) #26039

Description

@mumallaeng

Type: Bug

What happened

I was playing around in the REPL inside VS Code's integrated terminal and noticed that after int = 20, the >>> prompt just stops showing up. del int brings it back.

Python 3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)] on darwin Type "help", "copyright", "credits" or "license" for more information.
Cmd click to launch VS Code Native REPL
>>> int = 20
print(int)      # <- no ">>> " prompt is rendered anymore
20
del int
>>> 

float = 10 doesn't do this, only int. At first I thought it was a CPython bug,
but it turned out to come from the Python extension.

Steps to reproduce

  1. Open the integrated terminal with the Python extension installed (so PYTHONSTARTUP points at the extension's pythonrc.py)
  2. Run python (3.13+ with the new PyREPL — also reproduces outside VS Code with PYTHONSTARTUP=/path/to/pythonrc.py python3.14)
  3. int = 20
  4. Prompt is gone. del int restores it.

Why it happens

pythonrc.py installs a custom sys.ps1 whose __str__ runs on every prompt:

https://github.com/microsoft/vscode-python/blob/main/python_files/pythonrc.py#L49

def __str__(self):
    exit_code = int(bool(self.hooks.failure_flag))

Since PYTHONSTARTUP executes inside the REPL's __main__, the method's __globals__
IS the user's namespace. So after int = 20, every prompt render calls 20(False):

File ".../_pyrepl/reader.py", line 495, in get_prompt
    prompt = f"{t.prompt}{prompt}{t.reset}"
File ".../pythonrc.py", line 49, in __str__
    exit_code = int(bool(self.hooks.failure_flag))
TypeError: 'int' object is not callable

When str(sys.ps1) raises, PyREPL just doesn't render the prompt (CPython side of that is python/cpython#130698).
float is fine simply because pythonrc.py never calls it.

Same thing happens with any other global the hooks touch at prompt time — e.g. sys = 1
also kills the prompt via PS1.__str__sys.platform.

Possible fix

  • capture the builtins/modules at definition time (default args or an alias made at startup), or
  • run the shell-integration code in an actual separate module and only put the ps1
    object into __main__

(#25651 / #25904 look related but cover the opposite direction — pythonrc leaking into
the user namespace. Wrapping pythonrc in a function alone wouldn't fix this one, since a
class defined in a function still resolves its methods' globals through __main__.)

Environment

  • VS Code 1.128.0 (fc3def6774c76082adf699d366f31a557ce5573f)
  • ms-python.python 2026.4.0
  • macOS (Darwin 25.5.0), arm64
  • Python 3.14.6 (Homebrew), new PyREPL
  • python.terminal.shellIntegration.enabled at default

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions