Skip to content

Conversation

@CuriousLearner
Copy link
Member

@CuriousLearner CuriousLearner commented Nov 15, 2025

Fixes #48752

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.

Comment on lines 420 to 421
get_pre_input_hook = getattr(readline, "get_pre_input_hook", None)
if get_pre_input_hook is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to check for hasattr() here, and use readline.get_pre_input_hook() in the code below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vstinner 👋🏼

I have addressed your review. Would you mind taking another pass at this, please?

@CuriousLearner CuriousLearner force-pushed the gh-48752-readline-pre-input-hook branch from e73c48f to 9fe75be Compare November 30, 2025 19:00

# Clear the hook and verify it returns None again
readline.set_pre_input_hook(None)
self.assertIsNone(readline.get_pre_input_hook())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point of checking None twice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, removed the redundant check. Thanks for the review!

function has been set. This function only exists if Python was compiled
for a version of the library that supports it.

.. versionadded:: 3.15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. versionadded:: 3.15
.. versionadded:: next

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, #TIL about the next version.

@CuriousLearner CuriousLearner force-pushed the gh-48752-readline-pre-input-hook branch from 9fe75be to c89e904 Compare December 5, 2025 04:26
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.
@CuriousLearner CuriousLearner force-pushed the gh-48752-readline-pre-input-hook branch from c89e904 to a4de2bd Compare December 5, 2025 04:28
@vstinner vstinner merged commit 4238a97 into python:main Dec 5, 2025
46 checks passed
@vstinner
Copy link
Member

vstinner commented Dec 5, 2025

Merged. Thanks for your contribution!

StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
…1586)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allowing get_pre_input_hook from Readline

2 participants