Skip to content

Commit

Permalink
Use TypeVar defaults for Generator and AsyncGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
max-muoto committed May 5, 2024
1 parent e436dfe commit 82aeba8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ class Reversible(Iterable[_T_co], Protocol[_T_co]):
def __reversed__(self) -> Iterator[_T_co]: ...

_YieldT_co = TypeVar("_YieldT_co", covariant=True)
_SendT_contra = TypeVar("_SendT_contra", contravariant=True)
_ReturnT_co = TypeVar("_ReturnT_co", covariant=True)
_SendT_contra = TypeVar("_SendT_contra", contravariant=True, default=None)
_ReturnT_co = TypeVar("_ReturnT_co", covariant=True, default=None)

class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]):
def __next__(self) -> _YieldT_co: ...
Expand Down Expand Up @@ -445,7 +445,11 @@ class Awaitable(Protocol[_T_co]):
@abstractmethod
def __await__(self) -> Generator[Any, Any, _T_co]: ...

class Coroutine(Awaitable[_ReturnT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]):
# Non-default variations to accommodate couroutines, and `AwaitableGenerator` having a 4th type parameter.
_SendT_contra_nd = TypeVar("_SendT_contra_nd", contravariant=True)
_ReturnT_co_nd = TypeVar("_ReturnT_co_nd", covariant=True)

class Coroutine(Awaitable[_ReturnT_co_nd], Generic[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd]):
__name__: str
__qualname__: str
@property
Expand All @@ -457,7 +461,7 @@ class Coroutine(Awaitable[_ReturnT_co], Generic[_YieldT_co, _SendT_contra, _Retu
@property
def cr_running(self) -> bool: ...
@abstractmethod
def send(self, value: _SendT_contra, /) -> _YieldT_co: ...
def send(self, value: _SendT_contra_nd, /) -> _YieldT_co: ...
@overload
@abstractmethod
def throw(
Expand All @@ -473,9 +477,9 @@ class Coroutine(Awaitable[_ReturnT_co], Generic[_YieldT_co, _SendT_contra, _Retu
# The parameters correspond to Generator, but the 4th is the original type.
@type_check_only
class AwaitableGenerator(
Awaitable[_ReturnT_co],
Generator[_YieldT_co, _SendT_contra, _ReturnT_co],
Generic[_YieldT_co, _SendT_contra, _ReturnT_co, _S],
Awaitable[_ReturnT_co_nd],
Generator[_YieldT_co_nd, _SendT_contra_nd, _ReturnT_co_nd],
Generic[_YieldT_co_nd, _SendT_contra_nd, _ReturnT_co_nd, _S],
metaclass=ABCMeta,
): ...

Expand Down
2 changes: 1 addition & 1 deletion stubs/Pygments/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "2.17.*"
version = "2.18.*"
upstream_repository = "https://github.com/pygments/pygments"
requires = ["types-docutils", "types-setuptools"]
partial_stub = true
Expand Down

0 comments on commit 82aeba8

Please sign in to comment.