Skip to content

Commit

Permalink
pythongh-118682: Revert forcing str commands, allow class commands in…
Browse files Browse the repository at this point in the history
… pyrepl (python#118709)
  • Loading branch information
lysnikolaou authored May 7, 2024
1 parent 71080b8 commit e5413ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,16 @@ def do_cmd(self, cmd: tuple[str, list[str]]) -> None:
"""`cmd` is a tuple of "event_name" and "event", which in the current
implementation is always just the "buffer" which happens to be a list
of single-character strings."""
assert isinstance(cmd[0], str)

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

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

self.after_command(command)
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,15 @@ def test_setpos_fromxy_in_wrapped_line(self):
reader.setpos_from_xy(0, 1)
self.assertEqual(reader.pos, 9)

def test_up_arrow_after_ctrl_r(self):
events = iter([
Event(evt='key', data='\x12', raw=bytearray(b'\x12')),
Event(evt='key', data='up', raw=bytearray(b'\x1bOA')),
])

reader, _ = handle_all_events(events)
self.assert_screen_equals(reader, "")


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

0 comments on commit e5413ec

Please sign in to comment.