Skip to content

Commit 41ba734

Browse files
Roy Williamsambv
Roy Williams
authored andcommitted
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]' ```
1 parent fd4abe5 commit 41ba734

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ...
725725
@overload
726726
def next(i: Iterator[_T]) -> _T: ...
727727
@overload
728-
def next(i: Iterator[_T], default: _T) -> _T: ...
728+
def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ...
729729
def oct(i: int) -> str: ... # TODO __index__
730730
@overload
731731
def open(file: str, mode: str = 'r', buffering: int = ...) -> BinaryIO: ...

stdlib/3/builtins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ..
743743
@overload
744744
def next(i: Iterator[_T]) -> _T: ...
745745
@overload
746-
def next(i: Iterator[_T], default: _T) -> _T: ...
746+
def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ...
747747
def oct(i: int) -> str: ... # TODO __index__
748748

749749
if sys.version_info >= (3, 6):

0 commit comments

Comments
 (0)