Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions stdlib/@tests/test_cases/builtins/check_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
7 changes: 2 additions & 5 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Expand Down
Loading