File tree 2 files changed +36
-2
lines changed
test_cases/stdlib/builtins 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: ...
1634
1634
1635
1635
class reversed (Iterator [_T ]):
1636
1636
@overload
1637
- def __init__ ( self , __sequence : Reversible [_T ]) -> None : ...
1637
+ def __new__ ( cls , __sequence : Reversible [_T ]) -> Iterator [ _T ] : ... # type: ignore[misc]
1638
1638
@overload
1639
- def __init__ ( self , __sequence : SupportsLenAndGetItem [_T ]) -> None : ...
1639
+ def __new__ ( cls , __sequence : SupportsLenAndGetItem [_T ]) -> Iterator [ _T ] : ... # type: ignore[misc]
1640
1640
def __iter__ (self ) -> Self : ...
1641
1641
def __next__ (self ) -> _T : ...
1642
1642
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