gh-48752: Add readline.get_pre_input_hook() function (#141586)

Add readline.get_pre_input_hook() to retrieve the current pre-input
hook. This allows applications to save and restore the hook without
overwriting user settings.
This commit is contained in:
Sanyam Khurana 2025-12-05 07:18:54 -05:00 committed by GitHub
parent 53ec7c8fc0
commit 4238a975d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 78 additions and 1 deletions

View file

@ -413,6 +413,24 @@ def test_write_read_limited_history(self):
# So, we've only tested that the read did not fail.
# See TestHistoryManipulation for the full test.
@unittest.skipUnless(hasattr(readline, "get_pre_input_hook"),
"get_pre_input_hook not available")
def test_get_pre_input_hook(self):
# Save and restore the original hook to avoid side effects
original_hook = readline.get_pre_input_hook()
self.addCleanup(readline.set_pre_input_hook, original_hook)
# Test that get_pre_input_hook returns None when no hook is set
readline.set_pre_input_hook(None)
self.assertIsNone(readline.get_pre_input_hook())
# Set a hook and verify we can retrieve it
def my_hook():
pass
readline.set_pre_input_hook(my_hook)
self.assertIs(readline.get_pre_input_hook(), my_hook)
@unittest.skipUnless(support.Py_GIL_DISABLED, 'these tests can only possibly fail with GIL disabled')
class FreeThreadingTest(unittest.TestCase):