File tree 2 files changed +24
-1
lines changed
test_cases/stdlib/builtins
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -986,8 +986,12 @@ class list(MutableSequence[_T], Generic[_T]):
986
986
@overload
987
987
def __setitem__ (self , __s : slice , __o : Iterable [_T ]) -> None : ...
988
988
def __delitem__ (self , __i : SupportsIndex | slice ) -> None : ...
989
+ # Overloading looks unnecessary, but is needed to work around complex mypy problems
990
+ @overload
989
991
def __add__ (self , __x : list [_T ]) -> list [_T ]: ...
990
- def __iadd__ (self : Self , __x : Iterable [_T ]) -> Self : ...
992
+ @overload
993
+ def __add__ (self , __x : list [_S ]) -> list [_S | _T ]: ...
994
+ def __iadd__ (self : Self , __x : Iterable [_T ]) -> Self : ... # type: ignore[misc]
991
995
def __mul__ (self , __n : SupportsIndex ) -> list [_T ]: ...
992
996
def __rmul__ (self , __n : SupportsIndex ) -> list [_T ]: ...
993
997
def __imul__ (self : Self , __n : SupportsIndex ) -> Self : ...
Original file line number Diff line number Diff line change
1
+ from typing import List , Union
2
+ from typing_extensions import assert_type
3
+
4
+
5
+ # list.__add__ example from #8292
6
+ class Foo :
7
+ def asd (self ) -> int :
8
+ return 1
9
+
10
+
11
+ class Bar :
12
+ def asd (self ) -> int :
13
+ return 2
14
+
15
+
16
+ combined = [Foo ()] + [Bar ()]
17
+ assert_type (combined , List [Union [Foo , Bar ]])
18
+ for item in combined :
19
+ assert_type (item .asd (), int )
You can’t perform that action at this time.
0 commit comments