https://github.com/python/cpython/commit/e5413ec7831608f6cb4f39d805785cb1d7b67702
commit: e5413ec7831608f6cb4f39d805785cb1d7b67702
branch: main
author: Lysandros Nikolaou <[email protected]>
committer: ambv <[email protected]>
date: 2024-05-07T14:31:56Z
summary:

gh-118682: Revert forcing str commands, allow class commands in pyrepl (#118709)

files:
M Lib/_pyrepl/reader.py
M Lib/test/test_pyrepl.py

diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py
index e36f65c176e81f..d84c164a05308d 100644
--- a/Lib/_pyrepl/reader.py
+++ b/Lib/_pyrepl/reader.py
@@ -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)
diff --git a/Lib/test/test_pyrepl.py b/Lib/test/test_pyrepl.py
index b7ae91b919527a..bb9e36bc69ba4d 100644
--- a/Lib/test/test_pyrepl.py
+++ b/Lib/test/test_pyrepl.py
@@ -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()

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to