Skip to content

Commit 94e1c4f

Browse files
committed
fix list.__add__ to use the expected type
1 parent bf484ab commit 94e1c4f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

stdlib/@tests/test_cases/builtins/check_list.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ def asd(self) -> int:
1919
assert_type(combined, List[Union[Foo, Bar]])
2020
for item in combined:
2121
assert_type(item.asd(), int)
22+
23+
l4: list[object] = list[int]() + list[str]()
24+
l5: list[None] = list[int]() + list[str]() # type: ignore

stdlib/builtins.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,11 +1135,8 @@ class list(MutableSequence[_T]):
11351135
@overload
11361136
def __setitem__(self, key: slice, value: Iterable[_T], /) -> None: ...
11371137
def __delitem__(self, key: SupportsIndex | slice, /) -> None: ...
1138-
# Overloading looks unnecessary, but is needed to work around complex mypy problems
1139-
@overload
1140-
def __add__(self, value: list[_T], /) -> list[_T]: ...
1141-
@overload
1142-
def __add__(self, value: list[_S], /) -> list[_S | _T]: ...
1138+
# `_T1` has to come first due to a bug in pyright: https://github.com/DetachHead/basedpyright/issues/1492
1139+
def __add__(self, value: list[_T], /) -> list[_T1 | _S | _T]: ...
11431140
def __iadd__(self, value: Iterable[_T], /) -> Self: ... # type: ignore[misc]
11441141
def __mul__(self, value: SupportsIndex, /) -> list[_T]: ...
11451142
def __rmul__(self, value: SupportsIndex, /) -> list[_T]: ...

0 commit comments

Comments
 (0)