Skip to content

Commit

Permalink
Fix several methods that should be async def, but aren't (#7107)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Feb 2, 2022
1 parent 1b99812 commit 584336a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ctypes
import mmap
import sys
from os import PathLike
from typing import AbstractSet, Any, Awaitable, Container, Generic, Iterable, Protocol, TypeVar, Union
from typing import AbstractSet, Any, Container, Generic, Iterable, Protocol, TypeVar, Union
from typing_extensions import Final, Literal, final

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

# stable
class SupportsAnext(Protocol[_T_co]):
def __anext__(self) -> Awaitable[_T_co]: ...
async def __anext__(self) -> _T_co: ...

# Comparison protocols

Expand Down
14 changes: 7 additions & 7 deletions stdlib/asyncio/locks.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from collections import deque
from types import TracebackType
from typing import Any, Awaitable, Callable, Generator, TypeVar
from typing import Any, Callable, Generator, TypeVar

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

else:
class _ContextManager:
Expand All @@ -29,10 +29,10 @@ else:
def __exit__(self, *args: Any) -> None: ...
def __iter__(self) -> Generator[Any, None, _ContextManager]: ...
def __await__(self) -> Generator[Any, None, _ContextManager]: ...
def __aenter__(self) -> Awaitable[None]: ...
def __aexit__(
async def __aenter__(self) -> None: ...
async def __aexit__(
self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None
) -> Awaitable[None]: ...
) -> None: ...

class Lock(_ContextManagerMixin):
def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ...
Expand Down
12 changes: 6 additions & 6 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class closing(AbstractContextManager[_SupportsCloseT]):

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

class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):
Expand Down Expand Up @@ -122,19 +122,19 @@ if sys.version_info >= (3, 7):
class AsyncExitStack(AbstractAsyncContextManager[AsyncExitStack]):
def __init__(self) -> None: ...
def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> Awaitable[_T]: ...
async def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> _T: ...
def push(self, exit: _CM_EF) -> _CM_EF: ...
def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
def callback(self, __callback: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ...
def push_async_callback(
self, __callback: Callable[_P, Awaitable[_T]], *args: _P.args, **kwds: _P.kwargs
) -> Callable[_P, Awaitable[_T]]: ...
def pop_all(self: Self) -> Self: ...
def aclose(self) -> Awaitable[None]: ...
def __aenter__(self: Self) -> Awaitable[Self]: ...
def __aexit__(
async def aclose(self) -> None: ...
async def __aenter__(self: Self) -> Self: ...
async def __aexit__(
self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
) -> Awaitable[bool]: ...
) -> bool: ...

if sys.version_info >= (3, 10):
class nullcontext(AbstractContextManager[_T], AbstractAsyncContextManager[_T]):
Expand Down
6 changes: 3 additions & 3 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ class ContextManager(Protocol[_T_co]):

@runtime_checkable
class AsyncContextManager(Protocol[_T_co]):
def __aenter__(self) -> Awaitable[_T_co]: ...
def __aexit__(
async def __aenter__(self) -> _T_co: ...
async def __aexit__(
self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
) -> Awaitable[bool | None]: ...
) -> bool | None: ...

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

0 comments on commit 584336a

Please sign in to comment.