mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
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:
parent
53ec7c8fc0
commit
4238a975d7
5 changed files with 78 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue