diff --git a/stdlib/@tests/test_cases/builtins/check_list.py b/stdlib/@tests/test_cases/builtins/check_list.py index 4113f5c66182..aec51300536a 100644 --- a/stdlib/@tests/test_cases/builtins/check_list.py +++ b/stdlib/@tests/test_cases/builtins/check_list.py @@ -19,3 +19,12 @@ def asd(self) -> int: assert_type(combined, List[Union[Foo, Bar]]) for item in combined: assert_type(item.asd(), int) + +l_int = [1, 2] +l_str = ["a", "b"] +# TODO: these pass pyright with the current stubs, but mypy erroneously emits errors: +# _1: List[object] = l_int + l_str +# _2: List[None] = l_int + l_str + +# combined = l_int + l_str +# assert_type(combined, List[int | str]) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index bcfc81622179..0c8ee244c35b 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1135,11 +1135,8 @@ class list(MutableSequence[_T]): @overload def __setitem__(self, key: slice, value: Iterable[_T], /) -> None: ... def __delitem__(self, key: SupportsIndex | slice, /) -> None: ... - # Overloading looks unnecessary, but is needed to work around complex mypy problems - @overload - def __add__(self, value: list[_T], /) -> list[_T]: ... - @overload - def __add__(self, value: list[_S], /) -> list[_S | _T]: ... + # `__add__` returns a new object, so we capture the expected result type with a type variable + def __add__(self, value: list[_S], /) -> list[_T1 | _T | _S]: ... def __iadd__(self, value: Iterable[_T], /) -> Self: ... # type: ignore[misc] def __mul__(self, value: SupportsIndex, /) -> list[_T]: ... def __rmul__(self, value: SupportsIndex, /) -> list[_T]: ...