]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118682: Revert forcing str commands, allow class commands in pyrepl (#118709)
authorLysandros Nikolaou <lisandrosnik@gmail.com>
Tue, 7 May 2024 14:31:56 +0000 (16:31 +0200)
committerGitHub <noreply@github.com>
Tue, 7 May 2024 14:31:56 +0000 (14:31 +0000)
Lib/_pyrepl/reader.py
Lib/test/test_pyrepl.py

index e36f65c176e81f2f251fe7edb546df5aa9c426e4..d84c164a05308de73598223f45e96b4dc4a54c9e 100644 (file)
@@ -568,12 +568,16 @@ class Reader:
         """`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)
index b7ae91b919527a5b836c7bd895125e0e3d9f47f7..bb9e36bc69ba4da1fdd9fd4cc32f6c5352b2f74b 100644 (file)
@@ -976,6 +976,15 @@ class TestReader(TestCase):
         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()