From 254477399ae0eb46fac407e53fc7dba15606d264 Mon Sep 17 00:00:00 2001 From: Roy Williams Date: Thu, 12 Jan 2017 10:38:49 -0800 Subject: [PATCH] Fix return type of `next` when default parameter is provided. **test_next.py**: ```python z = (x*2 for x in range(10)) reveal_type(next(z, None)) ``` Before: ```shell test_next.py:2: error: Revealed type is 'builtins.int*' ``` After: ```shell test_next.py:2: error: Revealed type is 'Union[builtins.int*, builtins.None]' ``` --- stdlib/2/__builtin__.pyi | 2 +- stdlib/3/builtins.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index d0e3ef6b0cb5..4378fdf39192 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -725,7 +725,7 @@ def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... @overload def next(i: Iterator[_T]) -> _T: ... @overload -def next(i: Iterator[_T], default: _T) -> _T: ... +def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... def oct(i: int) -> str: ... # TODO __index__ @overload def open(file: str, mode: str = 'r', buffering: int = ...) -> BinaryIO: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 87828bf52bf4..895ec09513e7 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -743,7 +743,7 @@ def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = .. @overload def next(i: Iterator[_T]) -> _T: ... @overload -def next(i: Iterator[_T], default: _T) -> _T: ... +def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... def oct(i: int) -> str: ... # TODO __index__ if sys.version_info >= (3, 6):