From 32f63f51c03481a065507927c39f1ab07c8ec448 Mon Sep 17 00:00:00 2001 From: jikekei <171838407+jikekei@users.noreply.github.com> Date: Sat, 10 Oct 2026 18:14:17 +0800 Subject: [PATCH 1/2] gh-159072: Correct Ctrl+C documentation for msvcrt.getch() --- Doc/library/msvcrt.rst | 1 - PC/clinic/msvcrtmodule.c.h | 5 ++--- PC/msvcrtmodule.c | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Doc/library/msvcrt.rst b/Doc/library/msvcrt.rst index f4a1125554a051..ee0871b6535b18 100644 --- a/Doc/library/msvcrt.rst +++ b/Doc/library/msvcrt.rst @@ -114,7 +114,6 @@ Console I/O is not already available, but will not wait for :kbd:`Enter` to be pressed. If the pressed key was a special function key, this will return ``'\000'`` or ``'\xe0'``; the next call will return the keycode. - The :kbd:`Control-C` keypress cannot be read with this function. .. function:: getwch() diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index 7a43daa987b206..7a51f73afe049b 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -236,8 +236,7 @@ PyDoc_STRVAR(msvcrt_getch__doc__, "Nothing is echoed to the console. This call will block if a keypress is\n" "not already available, but will not wait for Enter to be pressed. If the\n" "pressed key was a special function key, this will return \'\\000\' or\n" -"\'\\xe0\'; the next call will return the keycode. The Control-C keypress\n" -"cannot be read with this function."); +"\'\\xe0\'; the next call will return the keycode."); #define MSVCRT_GETCH_METHODDEF \ {"getch", (PyCFunction)msvcrt_getch, METH_NOARGS, msvcrt_getch__doc__}, @@ -743,4 +742,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg) #ifndef MSVCRT_GETERRORMODE_METHODDEF #define MSVCRT_GETERRORMODE_METHODDEF #endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */ -/*[clinic end generated code: output=58c1771c8b9a209b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3fe5cf89f3e93d10 input=a9049054013a1b77]*/ diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index 868650dd31d9a1..07a3e45d5bdcd2 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -227,13 +227,12 @@ Read a keypress and return the resulting character as a byte string. Nothing is echoed to the console. This call will block if a keypress is not already available, but will not wait for Enter to be pressed. If the pressed key was a special function key, this will return '\000' or -'\xe0'; the next call will return the keycode. The Control-C keypress -cannot be read with this function. +'\xe0'; the next call will return the keycode. [clinic start generated code]*/ static int msvcrt_getch_impl(PyObject *module) -/*[clinic end generated code: output=a4e51f0565064a7d input=37a40cf0ed0d1153]*/ +/*[clinic end generated code: output=a4e51f0565064a7d input=967463215ff3ab9d]*/ { int ch; From ffd7cf0e20223d8ff184767b5585c0e1d2b609c0 Mon Sep 17 00:00:00 2001 From: jikekei <171838407+jikekei@users.noreply.github.com> Date: Sat, 10 Oct 2026 22:32:43 +0800 Subject: [PATCH 2/2] gh-159072: Clarify Ctrl+C and SIGINT handler behavior --- Doc/library/msvcrt.rst | 3 +++ PC/clinic/msvcrtmodule.c.h | 6 ++++-- PC/msvcrtmodule.c | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Doc/library/msvcrt.rst b/Doc/library/msvcrt.rst index ee0871b6535b18..22a63ae8eaae49 100644 --- a/Doc/library/msvcrt.rst +++ b/Doc/library/msvcrt.rst @@ -114,6 +114,9 @@ Console I/O is not already available, but will not wait for :kbd:`Enter` to be pressed. If the pressed key was a special function key, this will return ``'\000'`` or ``'\xe0'``; the next call will return the keycode. + When pressed while this function is waiting for input, :kbd:`Control-C` + can be read as ``b'\x03'`` without invoking the :const:`signal.SIGINT` + handler. .. function:: getwch() diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index 7a51f73afe049b..e4e5157050f088 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -236,7 +236,9 @@ PyDoc_STRVAR(msvcrt_getch__doc__, "Nothing is echoed to the console. This call will block if a keypress is\n" "not already available, but will not wait for Enter to be pressed. If the\n" "pressed key was a special function key, this will return \'\\000\' or\n" -"\'\\xe0\'; the next call will return the keycode."); +"\'\\xe0\'; the next call will return the keycode.\n" +"When pressed while this function is waiting for input, Control-C can be\n" +"read as b\'\\x03\' without invoking the signal.SIGINT handler."); #define MSVCRT_GETCH_METHODDEF \ {"getch", (PyCFunction)msvcrt_getch, METH_NOARGS, msvcrt_getch__doc__}, @@ -742,4 +744,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg) #ifndef MSVCRT_GETERRORMODE_METHODDEF #define MSVCRT_GETERRORMODE_METHODDEF #endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */ -/*[clinic end generated code: output=3fe5cf89f3e93d10 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=db004ea2187c98cc input=a9049054013a1b77]*/ diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index 07a3e45d5bdcd2..e6beb14e8f2259 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -228,11 +228,13 @@ Nothing is echoed to the console. This call will block if a keypress is not already available, but will not wait for Enter to be pressed. If the pressed key was a special function key, this will return '\000' or '\xe0'; the next call will return the keycode. +When pressed while this function is waiting for input, Control-C can be +read as b'\x03' without invoking the signal.SIGINT handler. [clinic start generated code]*/ static int msvcrt_getch_impl(PyObject *module) -/*[clinic end generated code: output=a4e51f0565064a7d input=967463215ff3ab9d]*/ +/*[clinic end generated code: output=a4e51f0565064a7d input=5c91f51ac2355241]*/ { int ch;