FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

REPL throws when `sys.ps1` is not a string · Issue #158827 · python/cpython · GitHub

Repository navigation

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

Description

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

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 5, 2026
  2. sergey-miryanov commented on Oct 5, 2026

    Contributor
  3. edvilme commented on Oct 5, 2026

    ContributorAuthor

    #130698

    I think this is a different issue (although complementary). The other issue refers to catching the exceptions when trying to convert to string (example uses 1/0) while this one refers to the REPL not attempting to convert to string values first @sergey-miryanov

  4. sergey-miryanov commented on Oct 5, 2026

    Contributor

    It seems like both issues have the same solution. You could link your PR to #130698 instead, though.

  5. edvilme commented on Oct 5, 2026

    ContributorAuthor

    Yeah just noticed that. It also seems like both PRs are mostly similar, but yours is missing adding str(sys.ps1) to simple_interact, let me know if you prefer to add it or I can reopen my PR linked to the existing issue :)

  6. sergey-miryanov commented on Oct 5, 2026

    Contributor

    Feel free to reopen your own PR.

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


      Back | FazBrowse Home | New Git URL