File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
test_cases/stdlib/builtins Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -1634,9 +1634,9 @@ def quit(code: sys._ExitCode = None) -> NoReturn: ...
16341634
16351635class reversed (Iterator [_T ]):
16361636 @overload
1637- def __init__ ( self , __sequence : Reversible [_T ]) -> None : ...
1637+ def __new__ ( cls , __sequence : Reversible [_T ]) -> Iterator [ _T ] : ... # type: ignore[misc]
16381638 @overload
1639- def __init__ ( self , __sequence : SupportsLenAndGetItem [_T ]) -> None : ...
1639+ def __new__ ( cls , __sequence : SupportsLenAndGetItem [_T ]) -> Iterator [ _T ] : ... # type: ignore[misc]
16401640 def __iter__ (self ) -> Self : ...
16411641 def __next__ (self ) -> _T : ...
16421642 def __length_hint__ (self ) -> int : ...
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ from collections .abc import Iterator
4+ from typing import Generic , TypeVar
5+ from typing_extensions import assert_type
6+
7+ x : list [int ] = []
8+ assert_type (list (reversed (x )), "list[int]" )
9+
10+
11+ class MyReversible :
12+ def __iter__ (self ) -> Iterator [str ]:
13+ yield "blah"
14+
15+ def __reversed__ (self ) -> Iterator [str ]:
16+ yield "blah"
17+
18+
19+ assert_type (list (reversed (MyReversible ())), "list[str]" )
20+
21+
22+ _T = TypeVar ("_T" )
23+
24+
25+ class MyLenAndGetItem (Generic [_T ]):
26+ def __len__ (self ) -> int :
27+ return 0
28+
29+ def __getitem__ (self , item : int ) -> _T :
30+ raise KeyError
31+
32+
33+ len_and_get_item : MyLenAndGetItem [int ] = MyLenAndGetItem ()
34+ assert_type (list (reversed (len_and_get_item )), "list[int]" )
You can’t perform that action at this time.
0 commit comments