Skip to content

Commit

Permalink
Fix typing issue for our aclosing implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanslenders committed Jan 17, 2023
1 parent da05f66 commit aa5d0d7
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/prompt_toolkit/eventloop/async_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from threading import Event
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
Awaitable,
Callable,
Expand All @@ -21,22 +22,13 @@
"generator_to_async_generator",
]


if TYPE_CHECKING:
# Thanks: https://github.com/python/typeshed/blob/main/stdlib/contextlib.pyi
from typing_extensions import Protocol

class _SupportsAclose(Protocol):
def aclose(self) -> Awaitable[object]:
...

_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
_T_Generator = TypeVar("_T_Generator", bound=AsyncGenerator[Any, None])


@asynccontextmanager
async def aclosing(
thing: "_SupportsAcloseT",
) -> AsyncGenerator["_SupportsAcloseT", None]:
thing: _T_Generator,
) -> AsyncGenerator[_T_Generator, None]:
"Similar to `contextlib.aclosing`, in Python 3.10."
try:
yield thing
Expand Down

0 comments on commit aa5d0d7

Please sign in to comment.