Skip to content

Commit 584336a

Browse files
authored
Fix several methods that should be async def, but aren't (#7107)
1 parent 1b99812 commit 584336a

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

stdlib/_typeshed/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ctypes
77
import mmap
88
import sys
99
from os import PathLike
10-
from typing import AbstractSet, Any, Awaitable, Container, Generic, Iterable, Protocol, TypeVar, Union
10+
from typing import AbstractSet, Any, Container, Generic, Iterable, Protocol, TypeVar, Union
1111
from typing_extensions import Final, Literal, final
1212

1313
_KT = TypeVar("_KT")
@@ -33,7 +33,7 @@ class SupportsNext(Protocol[_T_co]):
3333

3434
# stable
3535
class SupportsAnext(Protocol[_T_co]):
36-
def __anext__(self) -> Awaitable[_T_co]: ...
36+
async def __anext__(self) -> _T_co: ...
3737

3838
# Comparison protocols
3939

stdlib/asyncio/locks.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from collections import deque
33
from types import TracebackType
4-
from typing import Any, Awaitable, Callable, Generator, TypeVar
4+
from typing import Any, Callable, Generator, TypeVar
55

66
from .events import AbstractEventLoop
77
from .futures import Future
@@ -11,10 +11,10 @@ _T = TypeVar("_T")
1111
if sys.version_info >= (3, 9):
1212
class _ContextManagerMixin:
1313
def __init__(self, lock: Lock | Semaphore) -> None: ...
14-
def __aenter__(self) -> Awaitable[None]: ...
15-
def __aexit__(
14+
async def __aenter__(self) -> None: ...
15+
async def __aexit__(
1616
self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None
17-
) -> Awaitable[None]: ...
17+
) -> None: ...
1818

1919
else:
2020
class _ContextManager:
@@ -29,10 +29,10 @@ else:
2929
def __exit__(self, *args: Any) -> None: ...
3030
def __iter__(self) -> Generator[Any, None, _ContextManager]: ...
3131
def __await__(self) -> Generator[Any, None, _ContextManager]: ...
32-
def __aenter__(self) -> Awaitable[None]: ...
33-
def __aexit__(
32+
async def __aenter__(self) -> None: ...
33+
async def __aexit__(
3434
self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None
35-
) -> Awaitable[None]: ...
35+
) -> None: ...
3636

3737
class Lock(_ContextManagerMixin):
3838
def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ...

stdlib/contextlib.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class closing(AbstractContextManager[_SupportsCloseT]):
8585

8686
if sys.version_info >= (3, 10):
8787
class _SupportsAclose(Protocol):
88-
def aclose(self) -> Awaitable[object]: ...
88+
async def aclose(self) -> object: ...
8989
_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
9090

9191
class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):
@@ -122,19 +122,19 @@ if sys.version_info >= (3, 7):
122122
class AsyncExitStack(AbstractAsyncContextManager[AsyncExitStack]):
123123
def __init__(self) -> None: ...
124124
def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
125-
def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> Awaitable[_T]: ...
125+
async def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> _T: ...
126126
def push(self, exit: _CM_EF) -> _CM_EF: ...
127127
def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
128128
def callback(self, __callback: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ...
129129
def push_async_callback(
130130
self, __callback: Callable[_P, Awaitable[_T]], *args: _P.args, **kwds: _P.kwargs
131131
) -> Callable[_P, Awaitable[_T]]: ...
132132
def pop_all(self: Self) -> Self: ...
133-
def aclose(self) -> Awaitable[None]: ...
134-
def __aenter__(self: Self) -> Awaitable[Self]: ...
135-
def __aexit__(
133+
async def aclose(self) -> None: ...
134+
async def __aenter__(self: Self) -> Self: ...
135+
async def __aexit__(
136136
self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
137-
) -> Awaitable[bool]: ...
137+
) -> bool: ...
138138

139139
if sys.version_info >= (3, 10):
140140
class nullcontext(AbstractContextManager[_T], AbstractAsyncContextManager[_T]):

stdlib/typing.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,10 @@ class ContextManager(Protocol[_T_co]):
448448

449449
@runtime_checkable
450450
class AsyncContextManager(Protocol[_T_co]):
451-
def __aenter__(self) -> Awaitable[_T_co]: ...
452-
def __aexit__(
451+
async def __aenter__(self) -> _T_co: ...
452+
async def __aexit__(
453453
self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
454-
) -> Awaitable[bool | None]: ...
454+
) -> bool | None: ...
455455

456456
class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
457457
# TODO: We wish the key type could also be covariant, but that doesn't work,

0 commit comments

Comments
 (0)