Skip to content

Commit 8f151e6

Browse files
committed
Bracket REPL error overlay messages
1 parent 93dd613 commit 8f151e6

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

‎Lib/_pyrepl/reader.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ def debug(self, msg: str) -> None:
882882
pass
883883

884884
def error(self, msg: str = "none") -> None:
885+
msg = f"[ {msg} ]"
885886
if self.can_colorize:
886887
colors = _colorize.ANSIColors
887888
msg = f"{colors.RED}{msg}{colors.RESET}"

‎Lib/test/test_pyrepl/test_reader.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def test_colorized_error_message(self):
469469

470470
self.assertEqual(
471471
reader.msg,
472-
f"{ANSIColors.RED}nothing to yank{ANSIColors.RESET}",
472+
f"{ANSIColors.RED}[ nothing to yank ]{ANSIColors.RESET}",
473473
)
474474
self.assertEqual(reader.screen[-1], reader.msg)
475475

@@ -495,69 +495,69 @@ def _test_error_message(
495495
console.beep.assert_called_once()
496496

497497
def test_invalid_key_message(self):
498-
self._test_error_message("\x1bo", "no command is bound to this key")
498+
self._test_error_message("\x1bo", "[ no command is bound to this key ]")
499499

500500
def test_unimplemented_command_message(self):
501501
self._test_error_message(
502502
"x",
503-
"command 'missing-command' is not implemented",
503+
"[ command 'missing-command' is not implemented ]",
504504
command="missing-command",
505505
)
506506

507507
def test_nothing_to_yank_message(self):
508-
self._test_error_message("\x19", "nothing to yank")
508+
self._test_error_message("\x19", "[ nothing to yank ]")
509509

510510
def test_yank_pop_with_empty_kill_ring_message(self):
511-
self._test_error_message("\x1by", "nothing to yank")
511+
self._test_error_message("\x1by", "[ nothing to yank ]")
512512

513513
def test_yank_pop_after_other_command_message(self):
514514
self._test_error_message(
515515
"x\x01\x0b\x1by",
516-
"previous command was not a yank",
516+
"[ previous command was not a yank ]",
517517
)
518518

519519
def test_start_of_history_message(self):
520-
self._test_error_message("\x10", "start of history list")
520+
self._test_error_message("\x10", "[ start of history list ]")
521521

522522
def test_end_of_history_message(self):
523-
self._test_error_message("\x0e", "end of history list")
523+
self._test_error_message("\x0e", "[ end of history list ]")
524524

525525
def test_yank_arg_at_beginning_of_history_message(self):
526526
self._test_error_message(
527527
"\x1b.\x1b.\x1b.",
528-
"beginning of history list",
528+
"[ beginning of history list ]",
529529
history=["one"],
530530
historyi=1,
531531
)
532532

533533
def test_yank_arg_with_no_argument_message(self):
534534
self._test_error_message(
535535
"\x1b.",
536-
"no such arg",
536+
"[ no such arg ]",
537537
history=[""],
538538
historyi=1,
539539
)
540540

541541
def test_empty_incremental_search_backspace_message(self):
542542
self._test_error_message(
543543
"x",
544-
"nothing to rubout",
544+
"[ nothing to rubout ]",
545545
command="isearch-backspace",
546546
)
547547

548548
def test_history_search_not_found_message(self):
549549
self._test_error_message(
550550
"missingx",
551-
"not found",
551+
"[ not found ]",
552552
command="history-search-backward",
553553
binding="x",
554554
)
555555

556556
def test_incremental_search_not_found_message(self):
557-
self._test_error_message("\x12x", "not found")
557+
self._test_error_message("\x12x", "[ not found ]")
558558

559559
def test_no_completion_matches_message(self):
560-
self._test_error_message("does_not_exist\t", "no matches")
560+
self._test_error_message("does_not_exist\t", "[ no matches ]")
561561

562562

563563
@force_colorized_test_class
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Display error overlays in the new interactive shell without the ``!`` prefix
1+
Display error overlays in the new interactive shell in square brackets
22
and in non-bold red when color is enabled. Patch by Bartosz Sławecki.

0 commit comments

Comments
 (0)