8000 Improve various signatures that shouldn't be `async def`, but currently are by AlexWaygood · Pull Request #7491 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Improve various signatures that shouldn't be async def, but currently are #7491

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

Merged
merged 10 commits into from
Mar 19, 2022
Prev Previous commit
Next Next commit
Fix SupportsAnext & contextlib._SupportsAclose.
Co-authored-by: graingert <https//@graingert.co.uk>
  • Loading branch information
AlexWaygood and graingert committed Mar 14, 2022
commit 80acd91059ae7dc8bd83a2c61ef5f62bc30645bb
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, Container, Generic, Iterable, Protocol, TypeVar, Union
from typing import AbstractSet, Any, Awaitable, 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]):
async def __anext__(self) -> _T_co: ...
def __anext__(self) -> Awaitable[_T_co]: ...

# Comparison protocols

Expand Down
14 changes: 12 additions & 2 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ from typing import (
IO,
AbstractSet,
Any,
Awaitable,
BinaryIO,
ByteString,
Generic,
Expand Down Expand Up @@ -72,6 +73,8 @@ _T4 = TypeVar("_T4")
_T5 = TypeVar("_T5")
_SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=True)
_SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True)
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)

class _SupportsIter(Protocol[_T_co]):
def __iter__(self) -> _T_co: ...
Expand Down Expand Up @@ -1068,10 +1071,17 @@ class _PathLike(Protocol[_AnyStr_co]):

if sys.version_info >= (3, 10):
def aiter(__async_iterable: _SupportsAiter[_SupportsAnextT]) -> _SupportsAnextT: ...

class _SupportsSynchronousAnext(Protocol[_AwaitableT_co]):
def __anext__(self) -> _AwaitableT_co: ...

class _SupportsAwaitableAnext(Protocol[_T_co]):
def __anext__(self) -> Awaitable[_T_co]: ...

@overload
async def anext(__i: SupportsAnext[_T]) -> _T: ...
def anext(__i: _SupportsSynchronousAnext[_AwaitableT]) -> _AwaitableT: ...
@overload
async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ...
async def anext(__i: _SupportsAwaitableAnext[_T], default: _VT) -> _T | _VT: ...

# TODO: `compile` has a more precise return type in reality; work on a way of expressing that?
if sys.version_info >= (3, 8):
Expand Down
2 changes: 1 addition & 1 deletion stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class closing(AbstractContextManager[_SupportsCloseT]):

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

class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):
Expand Down
0