Skip to content

Commit e5413ec

Browse files
authored
gh-118682: Revert forcing str commands, allow class commands in pyrepl (#118709)
1 parent 71080b8 commit e5413ec

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Lib/_pyrepl/reader.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,16 @@ def do_cmd(self, cmd: tuple[str, list[str]]) -> None:
568568
"""`cmd` is a tuple of "event_name" and "event", which in the current
569569
implementation is always just the "buffer" which happens to be a list
570570
of single-character strings."""
571-
assert isinstance(cmd[0], str)
572571

573572
trace("received command {cmd}", cmd=cmd)
574-
command_type = self.commands.get(cmd[0], commands.invalid_command)
575-
command = command_type(self, *cmd) # type: ignore[arg-type]
573+
if isinstance(cmd[0], str):
574+
command_type = self.commands.get(cmd[0], commands.invalid_command)
575+
elif isinstance(cmd[0], type):
576+
command_type = cmd[0]
577+
else:
578+
return # nothing to do
576579

580+
command = command_type(self, *cmd) # type: ignore[arg-type]
577581
command.do()
578582

579583
self.after_command(command)

Lib/test/test_pyrepl.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,15 @@ def test_setpos_fromxy_in_wrapped_line(self):
976976
reader.setpos_from_xy(0, 1)
977977
self.assertEqual(reader.pos, 9)
978978

979+
def test_up_arrow_after_ctrl_r(self):
980+
events = iter([
981+
Event(evt='key', data='\x12', raw=bytearray(b'\x12')),
982+
Event(evt='key', data='up', raw=bytearray(b'\x1bOA')),
983+
])
984+
985+
reader, _ = handle_all_events(events)
986+
self.assert_screen_equals(reader, "")
987+
979988

980989
if __name__ == "__main__":
981990
unittest.main()

0 commit comments

Comments
 (0)