Skip to content

Commit 575007b

Browse files
Use DEFAULT_PS* in other places and add MULTILINE_PS*
1 parent e99d76a commit 575007b

File tree

9 files changed

+37
-27
lines changed

9 files changed

+37
-27
lines changed

Lib/_pyrepl/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
4747

4848
# set sys.{ps1,ps2} just before invoking the interactive interpreter. This
4949
# mimics what CPython does in pythonrun.c
50+
from .utils import DEFAULT_PS1, DEFAULT_PS2
5051
if not hasattr(sys, "ps1"):
51-
sys.ps1 = ">>> "
52+
sys.ps1 = DEFAULT_PS1
5253
if not hasattr(sys, "ps2"):
53-
sys.ps2 = "... "
54+
sys.ps2 = DEFAULT_PS2
5455

5556
from .console import InteractiveColoredConsole
5657
from .simple_interact import run_multiline_interactive_console

Lib/_pyrepl/reader.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
from dataclasses import dataclass, field, fields
2929

3030
from . import commands, console, input
31-
from .utils import DEFAULT_PS1, DEFAULT_PS2, DEFAULT_PS3, DEFAULT_PS4
31+
from .utils import DEFAULT_PS1
32+
from .utils import MULTILINE_PS2, MULTILINE_PS3, MULTILINE_PS4
3233
from .utils import wlen, unbracket, disp_str, gen_colors, THEME
3334
from .trace import trace
3435

@@ -501,11 +502,11 @@ def get_prompt(self, lineno: int, cursor_on_line: bool) -> str:
501502
prompt = "(paste) "
502503
elif "\n" in self.buffer:
503504
if lineno == 0:
504-
prompt = self.__get_prompt_str(self.ps2, DEFAULT_PS2)
505+
prompt = self.__get_prompt_str(self.ps2, MULTILINE_PS2)
505506
elif self.ps4 and lineno == self.buffer.count("\n"):
506-
prompt = self.__get_prompt_str(self.ps4, DEFAULT_PS4)
507+
prompt = self.__get_prompt_str(self.ps4, MULTILINE_PS4)
507508
else:
508-
prompt = self.__get_prompt_str(self.ps3, DEFAULT_PS3)
509+
prompt = self.__get_prompt_str(self.ps3, MULTILINE_PS3)
509510
else:
510511
prompt = self.__get_prompt_str(self.ps1, DEFAULT_PS1)
511512

Lib/_pyrepl/readline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from .completing_reader import CompletingReader
4141
from .console import Console as ConsoleType
4242
from ._module_completer import ModuleCompleter, make_default_module_completer
43+
from .utils import MULTILINE_PS4
4344

4445
Console: type[ConsoleType]
4546
_error: tuple[type[Exception], ...] | type[Exception]
@@ -390,7 +391,7 @@ def multiline_input(self, more_lines: MoreLinesCallable, ps1: str, ps2: str) ->
390391
reader.ps1 = ps1
391392
reader.ps2 = ps1
392393
reader.ps3 = ps2
393-
reader.ps4 = ""
394+
reader.ps4 = MULTILINE_PS4
394395
with warnings.catch_warnings(action="ignore"):
395396
return reader.readline()
396397
finally:

Lib/_pyrepl/simple_interact.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import errno
3535

3636
from .readline import _get_reader, multiline_input, append_history_file
37+
from .utils import DEFAULT_PS1, DEFAULT_PS2
3738

3839

3940
_error: tuple[type[Exception], ...] | type[Exception]
@@ -137,8 +138,8 @@ def maybe_run_command(statement: str) -> bool:
137138
except Exception:
138139
pass
139140

140-
ps1 = getattr(sys, "ps1", ">>> ")
141-
ps2 = getattr(sys, "ps2", "... ")
141+
ps1 = getattr(sys, "ps1", DEFAULT_PS1)
142+
ps2 = getattr(sys, "ps2", DEFAULT_PS2)
142143
try:
143144
statement = multiline_input(more_lines, ps1, ps2)
144145
except EOFError:

Lib/_pyrepl/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ class ColorSpan(NamedTuple):
6060

6161

6262
DEFAULT_PS1 = ">>> "
63-
DEFAULT_PS2 = ">>> "
64-
DEFAULT_PS3 = "... "
65-
DEFAULT_PS4 = "... "
63+
DEFAULT_PS2 = "... "
64+
65+
MULTILINE_PS1 = DEFAULT_PS1
66+
MULTILINE_PS2 = DEFAULT_PS1
67+
MULTILINE_PS3 = DEFAULT_PS2
68+
MULTILINE_PS4 = ""
6669

6770

6871
@functools.cache

Lib/asyncio/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from _colorize import get_theme
1616
from _pyrepl.console import InteractiveColoredConsole
17+
from _pyrepl.utils import DEFAULT_PS1
1718

1819
from . import futures
1920

@@ -103,7 +104,7 @@ def run(self):
103104
startup_code = compile(f.read(), startup_path, "exec")
104105
exec(startup_code, console.locals)
105106

106-
ps1 = getattr(sys, "ps1", ">>> ")
107+
ps1 = getattr(sys, "ps1", DEFAULT_PS1)
107108
if CAN_USE_PYREPL:
108109
theme = get_theme().syntax
109110
ps1 = f"{theme.prompt}{ps1}{theme.reset}"

Lib/code.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,18 @@ def interact(self, banner=None, exitmsg=None):
217217
a default message is printed.
218218
219219
"""
220+
from ._pyrepl.utils import DEFAULT_PS1, DEFAULT_PS2
220221
try:
221222
sys.ps1
222223
delete_ps1_after = False
223224
except AttributeError:
224-
sys.ps1 = ">>> "
225+
sys.ps1 = DEFAULT_PS1
225226
delete_ps1_after = True
226227
try:
227228
sys.ps2
228229
delete_ps2_after = False
229230
except AttributeError:
230-
sys.ps2 = "... "
231+
sys.ps2 = DEFAULT_PS2
231232
delete_ps2_after = True
232233

233234
cprt = 'Type "help", "copyright", "credits" or "license" for more information.'

Lib/test/test_pyrepl/support.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from _pyrepl.console import Console, Event
77
from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig
88
from _pyrepl.simple_interact import _strip_final_indent
9-
from _pyrepl.utils import unbracket, ANSI_ESCAPE_SEQUENCE
9+
from _pyrepl.utils import unbracket, ANSI_ESCAPE_SEQUENCE, DEFAULT_PS1, DEFAULT_PS2
1010

1111

1212
class ScreenEqualMixin:
@@ -22,8 +22,8 @@ def multiline_input(reader: ReadlineAlikeReader, namespace: dict | None = None):
2222
saved = reader.more_lines
2323
try:
2424
reader.more_lines = partial(more_lines, namespace=namespace)
25-
reader.ps1 = reader.ps2 = ">>> "
26-
reader.ps3 = reader.ps4 = "... "
25+
reader.ps1 = reader.ps2 = DEFAULT_PS1
26+
reader.ps3 = reader.ps4 = DEFAULT_PS2
2727
return reader.readline()
2828
finally:
2929
reader.more_lines = saved

Lib/test/test_pyrepl/test_reader.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
from .support import prepare_reader, prepare_console
1212
from _pyrepl.console import Event
1313
from _pyrepl.reader import Reader
14-
from _pyrepl.utils import DEFAULT_PS1, DEFAULT_PS2, DEFAULT_PS3, DEFAULT_PS4
14+
from _pyrepl.utils import DEFAULT_PS1
15+
from _pyrepl.utils import MULTILINE_PS1, MULTILINE_PS2, MULTILINE_PS3, MULTILINE_PS4
1516
from _colorize import default_theme
1617

1718

1819
def prepare_reader_with_prompt(
19-
console, ps1=DEFAULT_PS1, ps2=DEFAULT_PS2, ps3=DEFAULT_PS3, ps4=DEFAULT_PS4):
20+
console, ps1=MULTILINE_PS1, ps2=MULTILINE_PS2, ps3=MULTILINE_PS3, ps4=MULTILINE_PS4):
2021
reader = prepare_reader(
2122
console,
2223
can_colorize=False,
@@ -57,10 +58,10 @@ def test_calc_screen_prompt_handling(self):
5758
def prepare_reader_keep_prompts(*args, **kwargs):
5859
reader = prepare_reader(*args, **kwargs)
5960
del reader.get_prompt
60-
reader.ps1 = ">>> "
61-
reader.ps2 = ">>> "
62-
reader.ps3 = "... "
63-
reader.ps4 = ""
61+
reader.ps1 = MULTILINE_PS1
62+
reader.ps2 = MULTILINE_PS2
63+
reader.ps3 = MULTILINE_PS3
64+
reader.ps4 = MULTILINE_PS4
6465
reader.can_colorize = False
6566
reader.paste_mode = False
6667
return reader
@@ -355,13 +356,13 @@ def __str__(self): 1/0
355356
)
356357

357358
prompt = reader.get_prompt(0, False)
358-
self.assertEqual(prompt, DEFAULT_PS2)
359+
self.assertEqual(prompt, MULTILINE_PS2)
359360

360361
prompt = reader.get_prompt(1, False)
361-
self.assertEqual(prompt, DEFAULT_PS3)
362+
self.assertEqual(prompt, MULTILINE_PS3)
362363

363364
prompt = reader.get_prompt(2, False)
364-
self.assertEqual(prompt, DEFAULT_PS4)
365+
self.assertEqual(prompt, MULTILINE_PS4)
365366

366367
def test_prompt_arg_raise_exception(self):
367368
# Handles exceptions from arg prompt

0 commit comments

Comments
 (0)