From 82ee1545f5d3c5bea3e114fb6b23974c2da04f82 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Tue, 1 Oct 2019 11:30:56 +0530 Subject: [PATCH 1/2] builtins.pyi: Use two type vars Fixes: #3201 --- stdlib/2/__builtin__.pyi | 3 ++- stdlib/2and3/builtins.pyi | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 62052cfb7186..e826bbb50464 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -18,6 +18,7 @@ if sys.version_info >= (3,): from typing import SupportsBytes, SupportsRound _T = TypeVar('_T') +_U = TypeVar('_U') _T_co = TypeVar('_T_co', covariant=True) _KT = TypeVar('_KT') _VT = TypeVar('_VT') @@ -1189,7 +1190,7 @@ else: @overload def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... @overload -def iter(__function: Callable[[], _T], __sentinel: _T) -> Iterator[_T]: ... +def iter(__function: Callable[[], Union[_T, _U]], __sentinel: _U) -> Iterator[_T]: ... def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def len(__o: Sized) -> int: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 62052cfb7186..e826bbb50464 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -18,6 +18,7 @@ if sys.version_info >= (3,): from typing import SupportsBytes, SupportsRound _T = TypeVar('_T') +_U = TypeVar('_U') _T_co = TypeVar('_T_co', covariant=True) _KT = TypeVar('_KT') _VT = TypeVar('_VT') @@ -1189,7 +1190,7 @@ else: @overload def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... @overload -def iter(__function: Callable[[], _T], __sentinel: _T) -> Iterator[_T]: ... +def iter(__function: Callable[[], Union[_T, _U]], __sentinel: _U) -> Iterator[_T]: ... def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def len(__o: Sized) -> int: ... From a2ffcbf358271fa57525dd4539bff9782ebb79b6 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Fri, 4 Oct 2019 02:24:34 +0530 Subject: [PATCH 2/2] builtins.pyi: Use two type vars Fixes: #3201 --- stdlib/2/__builtin__.pyi | 5 +++-- stdlib/2and3/builtins.pyi | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index e826bbb50464..85b681a522c4 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -18,7 +18,6 @@ if sys.version_info >= (3,): from typing import SupportsBytes, SupportsRound _T = TypeVar('_T') -_U = TypeVar('_U') _T_co = TypeVar('_T_co', covariant=True) _KT = TypeVar('_KT') _VT = TypeVar('_VT') @@ -1190,7 +1189,9 @@ else: @overload def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... @overload -def iter(__function: Callable[[], Union[_T, _U]], __sentinel: _U) -> Iterator[_T]: ... +def iter(__function: Callable[[], Optional[_T]], __sentinel: None) -> Iterator[_T]: ... +@overload +def iter(__function: Callable[[], Any], __sentinel: Any) -> Iterator[Any]: ... def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def len(__o: Sized) -> int: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index e826bbb50464..85b681a522c4 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -18,7 +18,6 @@ if sys.version_info >= (3,): from typing import SupportsBytes, SupportsRound _T = TypeVar('_T') -_U = TypeVar('_U') _T_co = TypeVar('_T_co', covariant=True) _KT = TypeVar('_KT') _VT = TypeVar('_VT') @@ -1190,7 +1189,9 @@ else: @overload def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... @overload -def iter(__function: Callable[[], Union[_T, _U]], __sentinel: _U) -> Iterator[_T]: ... +def iter(__function: Callable[[], Optional[_T]], __sentinel: None) -> Iterator[_T]: ... +@overload +def iter(__function: Callable[[], Any], __sentinel: Any) -> Iterator[Any]: ... def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def len(__o: Sized) -> int: ...