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

application: fix DeprecationWarning (#1798) #1799

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/prompt_toolkit/application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,13 @@ def run_in_thread() -> None:
# See whether a loop was installed already. If so, use that. That's
# required for the input hooks to work, they are installed using
# `set_event_loop`.
loop = asyncio.get_event_loop()
if sys.version_info < (3, 10):
loop = asyncio.get_event_loop()
else:
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
except RuntimeError:
# No loop installed. Run like usual.
return asyncio.run(coro)
Expand Down
6 changes: 3 additions & 3 deletions src/prompt_toolkit/input/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ def _get_keys(

# Process if this is a key event. (We also have mouse, menu and
# focus events.)
if type(ev) == KEY_EVENT_RECORD and ev.KeyDown:
if isinstance(ev, KEY_EVENT_RECORD) and ev.KeyDown:
yield from self._event_to_key_presses(ev)

elif type(ev) == MOUSE_EVENT_RECORD:
elif isinstance(ev, MOUSE_EVENT_RECORD):
yield from self._handle_mouse(ev)

@staticmethod
Expand Down Expand Up @@ -379,7 +379,7 @@ def _event_to_key_presses(self, ev: KEY_EVENT_RECORD) -> list[KeyPress]:
"""
For this `KEY_EVENT_RECORD`, return a list of `KeyPress` instances.
"""
assert type(ev) == KEY_EVENT_RECORD and ev.KeyDown
assert isinstance(ev, KEY_EVENT_RECORD) and ev.KeyDown

result: KeyPress | None = None

Expand Down
Loading