prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.1k stars 717 forks source link

Fix IPython inputhook (workaround). #1811

Closed jonathanslenders closed 7 months ago

jonathanslenders commented 7 months ago

Workaround to make IPython inputhooks work again, until https://github.com/ipython/ipython/pull/14241 is merged.

tornaria commented 7 months ago

This now causes a deprecation warning when running sagemath on python 3.12 with prompt_toolkit 3.0.41:

$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.1, Release Date: 2023-08-20                    │
│ Using Python 3.12.0. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
/usr/lib/python3.12/site-packages/prompt_toolkit/application/application.py:988: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
sage: 

But we are shipping ipython 8.18 (void linux) so I think this workaround is no longer required.

Is there any suggested way to move forward on this so that asyncio.get_event_loop() is not called when running python 3.12 and ipython 8.18 ? Are we expected to patch out this PR in our prompt_toolkit. Do you intend to do that in the future?

tornaria commented 7 months ago

Maybe, this is being called from ipython, then import IPython and check IPython.version_info < (8, 18, 0, '') to actually do the workaround ?

jonathanslenders commented 7 months ago

@tornaria: Would you mind creating a pull request which adds the IPython version test? Maybe in _called_from_ipython() return False for newer IPython versions. For those we don't need the workaround any longer.