File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
@tests/test_cases/builtins Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -19,3 +19,23 @@ 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
+ # ignoring this so we can test mypy and pyright separately
24
+ # pyright: reportUnnecessaryTypeIgnoreComment=false
25
+
26
+ l_int = [1 , 2 ]
27
+ l_str = ["a" , "b" ]
28
+ combined1 = l_int + l_str
29
+ assert_type (combined1 , List [int | str ])
30
+
31
+ combined2 : list [str | int ]
32
+ # mypy doesn't support this case
33
+ combined2 = l_int + l_str # type: ignore[operator]
34
+ assert_type (combined2 , List [str | int ])
35
+
36
+ combined2 = list [str ]() + list [int | str ]()
37
+ assert_type (combined2 , List [str | int ])
38
+
39
+ # mypy doesn't support this case
40
+ combined3 : list [object ] = l_int + l_str # type: ignore[operator]
41
+ assert_type (combined3 , List [object ])
Original file line number Diff line number Diff line change @@ -1137,9 +1137,10 @@ class list(MutableSequence[_T]):
1137
1137
def __delitem__ (self , key : SupportsIndex | slice , / ) -> None : ...
1138
1138
# Overloading looks unnecessary, but is needed to work around complex mypy problems
1139
1139
@overload
1140
- def __add__ (self , value : list [_T ], / ) -> list [_T ]: ...
1140
+ # # `__add__` returns a new object, so we capture the expected result type with a type variable
1141
+ def __add__ (self , value : list [_T ], / ) -> list [_T1 | _T ]: ...
1141
1142
@overload
1142
- def __add__ (self , value : list [_S ], / ) -> list [_S | _T ]: ...
1143
+ def __add__ (self , value : list [_S ], / ) -> list [_T1 | _T | _S ]: ...
1143
1144
def __iadd__ (self , value : Iterable [_T ], / ) -> Self : ... # type: ignore[misc]
1144
1145
def __mul__ (self , value : SupportsIndex , / ) -> list [_T ]: ...
1145
1146
def __rmul__ (self , value : SupportsIndex , / ) -> list [_T ]: ...
You can’t perform that action at this time.
0 commit comments