mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-06 21:43:59 +08:00
Make (Async)GeneratorType type parameters consistent with (Async)Generator type parameters (#14789)
Currently `Generator` is generic over three type variables that have defaults, but `GeneratorType` is generic over three type variables that do not have defaults. It seems like it probably makes more sense for them to be consistent? The vast majority of real-world `Generator`s are instances of `GeneratorType`
This commit is contained in:
+9
-5
@@ -392,8 +392,8 @@ class CellType:
|
||||
cell_contents: Any
|
||||
|
||||
_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)
|
||||
|
||||
@final
|
||||
class GeneratorType(Generator[_YieldT_co, _SendT_contra, _ReturnT_co]):
|
||||
@@ -450,8 +450,12 @@ class AsyncGeneratorType(AsyncGenerator[_YieldT_co, _SendT_contra]):
|
||||
def aclose(self) -> Coroutine[Any, Any, None]: ...
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
# Non-default variations to accommodate coroutines
|
||||
_SendT_nd_contra = TypeVar("_SendT_nd_contra", contravariant=True)
|
||||
_ReturnT_nd_co = TypeVar("_ReturnT_nd_co", covariant=True)
|
||||
|
||||
@final
|
||||
class CoroutineType(Coroutine[_YieldT_co, _SendT_contra, _ReturnT_co]):
|
||||
class CoroutineType(Coroutine[_YieldT_co, _SendT_nd_contra, _ReturnT_nd_co]):
|
||||
__name__: str
|
||||
__qualname__: str
|
||||
@property
|
||||
@@ -469,8 +473,8 @@ class CoroutineType(Coroutine[_YieldT_co, _SendT_contra, _ReturnT_co]):
|
||||
def cr_suspended(self) -> bool: ...
|
||||
|
||||
def close(self) -> None: ...
|
||||
def __await__(self) -> Generator[Any, None, _ReturnT_co]: ...
|
||||
def send(self, arg: _SendT_contra, /) -> _YieldT_co: ...
|
||||
def __await__(self) -> Generator[Any, None, _ReturnT_nd_co]: ...
|
||||
def send(self, arg: _SendT_nd_contra, /) -> _YieldT_co: ...
|
||||
@overload
|
||||
def throw(
|
||||
self, typ: type[BaseException], val: BaseException | object = ..., tb: TracebackType | None = ..., /
|
||||
|
||||
+1
-1
@@ -577,7 +577,7 @@ class Awaitable(Protocol[_T_co]):
|
||||
@abstractmethod
|
||||
def __await__(self) -> Generator[Any, Any, _T_co]: ...
|
||||
|
||||
# Non-default variations to accommodate couroutines, and `AwaitableGenerator` having a 4th type parameter.
|
||||
# Non-default variations to accommodate coroutines, and `AwaitableGenerator` having a 4th type parameter.
|
||||
_SendT_nd_contra = TypeVar("_SendT_nd_contra", contravariant=True)
|
||||
_ReturnT_nd_co = TypeVar("_ReturnT_nd_co", covariant=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user