File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
@tests/test_cases/builtins Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -19,3 +19,8 @@ def asd(self) -> int:
19
19
assert_type (combined , List [Union [Foo , Bar ]])
20
20
for item in combined :
21
21
assert_type (item .asd (), int )
22
+
23
+ l1 : list [int ] = [1 ]
24
+ l2 : list [object ] = l1 .copy ()
25
+ # this is an error, because a list of ints can't be a list of strs
26
+ l3 : list [str ] = l1 .copy () # type: ignore
Original file line number Diff line number Diff line change @@ -1104,7 +1104,8 @@ class list(MutableSequence[_T]):
1104
1104
def __init__ (self ) -> None : ...
1105
1105
@overload
1106
1106
def __init__ (self , iterable : Iterable [_T ], / ) -> None : ...
1107
- def copy (self ) -> list [_T ]: ...
1107
+ # `copy` returns a new object, so capture the expected return type here using a type var
1108
+ def copy (self ) -> list [_S | _T ]: ...
1108
1109
def append (self , object : _T , / ) -> None : ...
1109
1110
def extend (self , iterable : Iterable [_T ], / ) -> None : ...
1110
1111
def pop (self , index : SupportsIndex = - 1 , / ) -> _T : ...
You can’t perform that action at this time.
0 commit comments