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
Bug report
When users assign non-string values to
sys.ps1orsys.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 tosys.ps1to handle the terminal integration logic.Reproduction
Assign a custom object with a
__str__method tosys.ps1Expected 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
sys.ps1andsys.ps2to strings before PyREPL use #158828