Skip to content

Commit 1c6d094

Browse files
Use Coroutine instead of Awaitable in type annotations where possible.
1 parent 87d0107 commit 1c6d094

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/prompt_toolkit/buffer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from collections import deque
1616
from enum import Enum
1717
from functools import wraps
18-
from typing import Any, Awaitable, Callable, Coroutine, Iterable, TypeVar, cast
18+
from typing import Any, Callable, Coroutine, Iterable, TypeVar, cast
1919

2020
from .application.current import get_app
2121
from .application.run_in_terminal import run_in_terminal
@@ -1891,7 +1891,7 @@ def validate_and_handle(self) -> None:
18911891
self.reset()
18921892

18931893

1894-
_T = TypeVar("_T", bound=Callable[..., Awaitable[None]])
1894+
_T = TypeVar("_T", bound=Callable[..., Coroutine[Any, Any, None]])
18951895

18961896

18971897
def _only_one_at_a_time(coroutine: _T) -> _T:

src/prompt_toolkit/contrib/ssh/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import asyncio
77
import traceback
88
from asyncio import get_running_loop
9-
from typing import Any, Awaitable, Callable, TextIO, cast
9+
from typing import Any, Callable, Coroutine, TextIO, cast
1010

1111
import asyncssh
1212

@@ -21,7 +21,7 @@
2121
class PromptToolkitSSHSession(asyncssh.SSHServerSession): # type: ignore
2222
def __init__(
2323
self,
24-
interact: Callable[[PromptToolkitSSHSession], Awaitable[None]],
24+
interact: Callable[[PromptToolkitSSHSession], Coroutine[Any, Any, None]],
2525
*,
2626
enable_cpr: bool,
2727
) -> None:
@@ -162,7 +162,7 @@ async def interact(ssh_session: PromptToolkitSSHSession) -> None:
162162

163163
def __init__(
164164
self,
165-
interact: Callable[[PromptToolkitSSHSession], Awaitable[None]],
165+
interact: Callable[[PromptToolkitSSHSession], Coroutine[Any, Any, None]],
166166
*,
167167
enable_cpr: bool = True,
168168
) -> None:

src/prompt_toolkit/contrib/telnet/server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import contextvars
88
import socket
99
from asyncio import get_running_loop
10-
from typing import Awaitable, Callable, TextIO, cast
10+
from typing import Any, Callable, Coroutine, TextIO, cast
1111

1212
from prompt_toolkit.application.current import create_app_session, get_app
1313
from prompt_toolkit.application.run_in_terminal import run_in_terminal
@@ -124,7 +124,7 @@ def __init__(
124124
self,
125125
conn: socket.socket,
126126
addr: tuple[str, int],
127-
interact: Callable[[TelnetConnection], Awaitable[None]],
127+
interact: Callable[[TelnetConnection], Coroutine[Any, Any, None]],
128128
server: TelnetServer,
129129
encoding: str,
130130
style: BaseStyle | None,
@@ -283,7 +283,9 @@ def __init__(
283283
self,
284284
host: str = "127.0.0.1",
285285
port: int = 23,
286-
interact: Callable[[TelnetConnection], Awaitable[None]] = _dummy_interact,
286+
interact: Callable[
287+
[TelnetConnection], Coroutine[Any, Any, None]
288+
] = _dummy_interact,
287289
encoding: str = "utf-8",
288290
style: BaseStyle | None = None,
289291
enable_cpr: bool = True,

src/prompt_toolkit/key_binding/key_bindings.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ def my_key_binding(event):
4040
from inspect import isawaitable
4141
from typing import (
4242
TYPE_CHECKING,
43-
Awaitable,
43+
Any,
4444
Callable,
45+
Coroutine,
4546
Hashable,
4647
Sequence,
4748
Tuple,
@@ -89,7 +90,8 @@ def my_key_binding(event):
8990
# This is mainly used in case of mouse move events, to prevent excessive
9091
# repainting during mouse move events.
9192
KeyHandlerCallable = Callable[
92-
["KeyPressEvent"], Union["NotImplementedOrNone", Awaitable["NotImplementedOrNone"]]
93+
["KeyPressEvent"],
94+
Union["NotImplementedOrNone", Coroutine[Any, Any, "NotImplementedOrNone"]],
9395
]
9496

9597

@@ -125,7 +127,7 @@ def call(self, event: KeyPressEvent) -> None:
125127

126128
# If the handler is a coroutine, create an asyncio task.
127129
if isawaitable(result):
128-
awaitable = cast(Awaitable["NotImplementedOrNone"], result)
130+
awaitable = cast(Coroutine[Any, Any, "NotImplementedOrNone"], result)
129131

130132
async def bg_task() -> None:
131133
result = await awaitable

0 commit comments

Comments
 (0)