Skip to content

iter("") --> Iterator[Never] #13902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion stdlib/@tests/test_cases/builtins/check_iteration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from typing import Iterator
from typing_extensions import assert_type
from typing_extensions import Never, assert_type


class OldStyleIter:
Expand All @@ -14,3 +14,7 @@ def __getitem__(self, index: int) -> str:

assert_type(iter(OldStyleIter()), Iterator[str])
assert_type(next(iter(OldStyleIter())), str)

assert_type(iter(()), Iterator[Never])
assert_type(iter(list[Never]()), Iterator[Never])
assert_type(iter(""), Iterator[Never])
3 changes: 3 additions & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ from typing_extensions import ( # noqa: Y023
Concatenate,
Literal,
LiteralString,
Never,
ParamSpec,
Self,
TypeAlias,
Expand Down Expand Up @@ -1470,6 +1471,8 @@ def input(prompt: object = "", /) -> str: ...
class _GetItemIterable(Protocol[_T_co]):
def __getitem__(self, i: int, /) -> _T_co: ...

@overload
def iter(object: Literal[""], /) -> Iterator[Never]: ...
@overload
def iter(object: SupportsIter[_SupportsNextT_co], /) -> _SupportsNextT_co: ...
@overload
Expand Down