Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inputhook implementation to be compatible with asyncio.run(). #1810

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

jonathanslenders
Copy link
Member

asyncio.get_event_loop() got deprecated. So we can't install an event loop with inputhook upfront and then use in in prompt_toolkit. Instead, we can take the inputhook as an argument in Application.run() and PromptSession.run(), and install it in the event loop that we create ourselves using asyncio.run().

`asyncio.get_event_loop()` got deprecated. So we can't install an event loop
with inputhook upfront and then use in in prompt_toolkit. Instead, we can take
the inputhook as an argument in `Application.run()` and `PromptSession.run()`,
and install it in the event loop that we create ourselves using
`asyncio.run()`.
@jonathanslenders jonathanslenders merged commit 2e2175a into master Nov 13, 2023
12 checks passed
@jonathanslenders jonathanslenders deleted the fix-eventloop-inputhook branch November 13, 2023 13:36
Carreau added a commit to ipython/ipython that referenced this pull request Nov 20, 2023
…sion.run(). (#14241)

See: prompt-toolkit/python-prompt-toolkit#1809

To summarize:
- In prompt_toolkit, some changes were done to get rid of a deprecation
warning related to the usage of `set_event_loop()` on Python 3.12. It
looks like IPython did had a workaround for the deprecation warning, but
Xonsh for instance did not. Now, the code that was fixed in
prompt_toolkit breaks input hooks in IPython.
- The right thing to do would be to accept the input hook as an argument
in prompt_toolkit, which is what this PR does:
prompt-toolkit/python-prompt-toolkit#1810
- For IPython, we have to do a similar change to pass it as an argument
(this PR).

It's not well tested (I'm not using IPython with inputhooks myself). I'm
also not very familiar myself with IPython's code base.

I think it requires some coordination. I'm not sure if there's a way to
be backward compatible. I guess if I push a new prompt_toolkit version
with the fix on my side, nothing will break, but input hooks will for
sure not work on any Python version until this is merged.

We should probably set the minimum prompt_toolkit version after merging
this.
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.

None yet

1 participant