-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Return type for iter() and aiter() too strict #6030
Copy link
Copy link
Closed
Description
The definition of builtins.iter() has it returning typing.Iterator:
Line 1040 in 4c6e98e
| def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... |
The problem is typing.Iterator requires both __iter__ and __next__:
Lines 191 to 194 in 4c6e98e
| class Iterator(Iterable[_T_co], Protocol[_T_co]): | |
| @abstractmethod | |
| def __next__(self) -> _T_co: ... | |
| def __iter__(self) -> Iterator[_T_co]: ... |
The docs for iter() does not suggest that the returned iterator must define __iter__. And if you look at the implementation of iter() -- as well as PyObject_GetIter() and PyIter_Check() which iter() uses -- there is no requirement that the returned iterator define __iter__.
All of this also applies to aiter() in regards to __aiter__.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels