File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
test_cases/stdlib/builtins Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1202,9 +1202,15 @@ def help(request: object = ...) -> None: ...
1202
1202
def hex (__number : int | SupportsIndex ) -> str : ...
1203
1203
def id (__obj : object ) -> int : ...
1204
1204
def input (__prompt : object = ...) -> str : ...
1205
+
1206
+ class _GetItemIterable (Protocol [_T_co ]):
1207
+ def __getitem__ (self , __i : int ) -> _T_co : ...
1208
+
1205
1209
@overload
1206
1210
def iter (__iterable : SupportsIter [_SupportsNextT ]) -> _SupportsNextT : ...
1207
1211
@overload
1212
+ def iter (__iterable : _GetItemIterable [_T ]) -> Iterator [_T ]: ...
1213
+ @overload
1208
1214
def iter (__function : Callable [[], _T | None ], __sentinel : None ) -> Iterator [_T ]: ...
1209
1215
@overload
1210
1216
def iter (__function : Callable [[], _T ], __sentinel : object ) -> Iterator [_T ]: ...
Original file line number Diff line number Diff line change
1
+ from typing import Iterator
2
+ from typing_extensions import assert_type
3
+
4
+
5
+ class OldStyleIter :
6
+ def __getitem__ (self , index : int ) -> str :
7
+ return str (index )
8
+
9
+
10
+ for x in iter (OldStyleIter ()):
11
+ assert_type (x , str )
12
+
13
+ assert_type (iter (OldStyleIter ()), Iterator [str ])
14
+ assert_type (next (iter (OldStyleIter ())), str )
You can’t perform that action at this time.
0 commit comments