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

gh-130698: Convert `sys.ps1` and `sys.ps2` to strings before PyREPL use by edvilme · Pull Request #158828 · python/cpython · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions Lib/_pyrepl/simple_interact.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def maybe_run_command(statement: str) -> bool:
except Exception:
pass

ps1 = getattr(sys, "ps1", ">>> ")
ps2 = getattr(sys, "ps2", "... ")
ps1 = str(getattr(sys, "ps1", ">>> "))
ps2 = str(getattr(sys, "ps2", "... "))
try:
statement = multiline_input(more_lines, ps1, ps2)
except EOFError:
Expand Down
30 changes: 28 additions & 2 deletions Lib/test/test_pyrepl/test_interact.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
import contextlib
import io
import sys
import warnings
import unittest
from unittest.mock import patch
from unittest.mock import ANY, patch
from textwrap import dedent

from test.support import force_not_colorized

from _pyrepl.console import InteractiveColoredConsole
from _pyrepl.simple_interact import _more_lines
from _pyrepl.simple_interact import (
_more_lines,
run_multiline_interactive_console,
)

class TestSimpleInteract(unittest.TestCase):
def test_prompts_are_converted_to_strings(self):
console = InteractiveColoredConsole()

class Prompt:
def __init__(self, value):
self.value = value

def __str__(self):
return self.value

with (
patch.object(sys, "ps1", Prompt("primary"), create=True),
patch.object(sys, "ps2", Prompt("secondary"), create=True),
patch("_pyrepl.readline._setup"),
patch(
"_pyrepl.simple_interact.multiline_input", side_effect=EOFError
) as multiline_input,
):
run_multiline_interactive_console(console)

multiline_input.assert_called_once_with(ANY, "primary", "secondary")

def test_multiple_statements(self):
namespace = {}
code = dedent("""\
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue where PyREPL would overflow with errors when assigning a string-representable object to ``sys.ps1``.
Loading

Back | FazBrowse Home | New Git URL