Skip to content

REPL throws when sys.ps1 is not a string #158827

Description

@edvilme

Bug report

When users assign non-string values to sys.ps1 or sys.ps2, the PyREPL interactive console passes those values directly to the prompt-rendering code, which expects string values, causing repeatedly raised exceptions.

Converting both prompt values to string before use matches the expected behavior and prevents the exception loop.

Tools like the Python extension for VS Code have, for several versions, assigned a custom object with a __str__ method to sys.ps1 to handle the terminal integration logic.

Reproduction

Assign a custom object with a __str__ method to sys.ps1

>>> import sys
>>> class CustomPrompt:
...     def __init__(self, value):
...         self.value = value
...     def __str__(self):
...         return self.value
...
>>> customPS1 = CustomPrompt(":-) ")
>>> str(customPS1)
':-) '
>>> sys.ps1 = customPS1

Expected behavior is to see ':-) ' as the prompt, but the current behavior is showing a loop of exceptions.

CPython versions tested on:

3.15

Operating systems tested on:

macOS

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions