Skip to content

Commit e147bce

Browse files
author
hauntsaninja
committed
builtins: return Union type for list.__add__
1 parent 0e002f4 commit e147bce

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,10 @@ class list(MutableSequence[_T], Generic[_T]):
658658
def __getslice__(self, start: int, stop: int) -> List[_T]: ...
659659
def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ...
660660
def __delslice__(self, start: int, stop: int) -> None: ...
661-
def __add__(self, x: List[_T]) -> List[_T]: ...
662-
def __iadd__(self: _S, x: Iterable[_T]) -> _S: ...
661+
def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ...
662+
def __iadd__(self, x: Iterable[_S]) -> List[Union[_T, _S]]: ...
663+
# Workaround https://github.com/python/mypy/issues/5971
664+
def __radd__(self, x: List[_S]) -> List[Union[_T, _S]]: ...
663665
def __mul__(self, n: int) -> List[_T]: ...
664666
def __rmul__(self, n: int) -> List[_T]: ...
665667
def __contains__(self, o: object) -> bool: ...

stdlib/2/builtins.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,10 @@ class list(MutableSequence[_T], Generic[_T]):
658658
def __getslice__(self, start: int, stop: int) -> List[_T]: ...
659659
def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ...
660660
def __delslice__(self, start: int, stop: int) -> None: ...
661-
def __add__(self, x: List[_T]) -> List[_T]: ...
662-
def __iadd__(self: _S, x: Iterable[_T]) -> _S: ...
661+
def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ...
662+
def __iadd__(self, x: Iterable[_S]) -> List[Union[_T, _S]]: ...
663+
# Workaround https://github.com/python/mypy/issues/5971
664+
def __radd__(self, x: List[_S]) -> List[Union[_T, _S]]: ...
663665
def __mul__(self, n: int) -> List[_T]: ...
664666
def __rmul__(self, n: int) -> List[_T]: ...
665667
def __contains__(self, o: object) -> bool: ...

stdlib/3/builtins.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,10 @@ class list(MutableSequence[_T], Generic[_T]):
726726
@overload
727727
def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ...
728728
def __delitem__(self, i: Union[int, slice]) -> None: ...
729-
def __add__(self, x: List[_T]) -> List[_T]: ...
730-
def __iadd__(self: _S, x: Iterable[_T]) -> _S: ...
729+
def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ...
730+
def __iadd__(self, x: Iterable[_S]) -> List[Union[_T, _S]]: ...
731+
# Workaround https://github.com/python/mypy/issues/5971
732+
def __radd__(self, x: List[_S]) -> List[Union[_T, _S]]: ...
731733
def __mul__(self, n: int) -> List[_T]: ...
732734
def __rmul__(self, n: int) -> List[_T]: ...
733735
def __imul__(self: _S, n: int) -> _S: ...

tests/stubtest_whitelists/py3_common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ builtins.classmethod.__get__
4141
builtins.complex.__complex__
4242
builtins.ellipsis
4343
builtins.function
44+
builtins.list.__radd__
4445
builtins.memoryview.__contains__
4546
builtins.memoryview.__iter__
4647
builtins.memoryview.cast

0 commit comments

Comments
 (0)