aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-04 20:45:22 +0200
committerGitHub <noreply@github.com>2024-06-04 18:45:22 +0000
commit93b95e91faa17520f2042b4f4ae88379df914666 (patch)
tree7bff77928754014c6e809cad7ca017c44cb58652
parent[3.13] gh-120039: Reduce expected timeout in test_siginterrupt_off (GH-120047... (diff)
downloadcpython-93b95e91faa17520f2042b4f4ae88379df914666.tar.gz
cpython-93b95e91faa17520f2042b4f4ae88379df914666.tar.bz2
cpython-93b95e91faa17520f2042b4f4ae88379df914666.zip
[3.13] gh-119553: Clear reader on Ctrl-C command (GH-119801) (#120062)
(cherry picked from commit 010ea93b2b888149561becefeee90826bf8a2934) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
-rw-r--r--Lib/_pyrepl/commands.py1
-rw-r--r--Lib/test/test_pyrepl/support.py2
-rw-r--r--Lib/test/test_pyrepl/test_reader.py16
3 files changed, 19 insertions, 0 deletions
diff --git a/Lib/_pyrepl/commands.py b/Lib/_pyrepl/commands.py
index 2ef5dada9d9..e94e8c25d37 100644
--- a/Lib/_pyrepl/commands.py
+++ b/Lib/_pyrepl/commands.py
@@ -221,6 +221,7 @@ class interrupt(FinishCommand):
class ctrl_c(Command):
def do(self) -> None:
+ self.reader.finish()
raise KeyboardInterrupt
diff --git a/Lib/test/test_pyrepl/support.py b/Lib/test/test_pyrepl/support.py
index e807b5f3404..70e12286f7d 100644
--- a/Lib/test/test_pyrepl/support.py
+++ b/Lib/test/test_pyrepl/support.py
@@ -75,6 +75,8 @@ def handle_all_events(
reader.handle1()
except StopIteration:
pass
+ except KeyboardInterrupt:
+ pass
return reader, console
diff --git a/Lib/test/test_pyrepl/test_reader.py b/Lib/test/test_pyrepl/test_reader.py
index d02815bfa11..079c963d19a 100644
--- a/Lib/test/test_pyrepl/test_reader.py
+++ b/Lib/test/test_pyrepl/test_reader.py
@@ -179,6 +179,22 @@ class TestReader(TestCase):
self.assert_screen_equals(reader, expected)
self.assertTrue(reader.finished)
+ def test_keyboard_interrupt_clears_screen(self):
+ namespace = {"itertools": itertools}
+ code = "import itertools\nitertools."
+ events = itertools.chain(code_to_events(code), [
+ Event(evt='key', data='\t', raw=bytearray(b'\t')), # Two tabs for completion
+ Event(evt='key', data='\t', raw=bytearray(b'\t')),
+ Event(evt='key', data='\x03', raw=bytearray(b'\x03')), # Ctrl-C
+ ])
+
+ completing_reader = functools.partial(
+ prepare_reader,
+ readline_completer=rlcompleter.Completer(namespace).complete
+ )
+ reader, _ = handle_all_events(events, prepare_reader=completing_reader)
+ self.assertEqual(reader.calc_screen(), code.split("\n"))
+
def test_prompt_length(self):
# Handles simple ASCII prompt
ps1 = ">>> "