From e147bce4ceb7305306fb49ab2062e81d1d39545d Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sun, 1 Nov 2020 13:39:42 -0800 Subject: [PATCH] builtins: return Union type for list.__add__ --- stdlib/2/__builtin__.pyi | 6 ++++-- stdlib/2/builtins.pyi | 6 ++++-- stdlib/3/builtins.pyi | 6 ++++-- tests/stubtest_whitelists/py3_common.txt | 1 + 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index da86f2ee6977..172b2571ea47 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -658,8 +658,10 @@ class list(MutableSequence[_T], Generic[_T]): def __getslice__(self, start: int, stop: int) -> List[_T]: ... def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self, x: List[_T]) -> List[_T]: ... - def __iadd__(self: _S, x: Iterable[_T]) -> _S: ... + def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ... + def __iadd__(self, x: Iterable[_S]) -> List[Union[_T, _S]]: ... + # Workaround https://github.com/python/mypy/issues/5971 + def __radd__(self, x: List[_S]) -> List[Union[_T, _S]]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... def __contains__(self, o: object) -> bool: ... diff --git a/stdlib/2/builtins.pyi b/stdlib/2/builtins.pyi index da86f2ee6977..172b2571ea47 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -658,8 +658,10 @@ class list(MutableSequence[_T], Generic[_T]): def __getslice__(self, start: int, stop: int) -> List[_T]: ... def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self, x: List[_T]) -> List[_T]: ... - def __iadd__(self: _S, x: Iterable[_T]) -> _S: ... + def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ... + def __iadd__(self, x: Iterable[_S]) -> List[Union[_T, _S]]: ... + # Workaround https://github.com/python/mypy/issues/5971 + def __radd__(self, x: List[_S]) -> List[Union[_T, _S]]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... def __contains__(self, o: object) -> bool: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 13ce51131ad0..44a999359d3e 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -726,8 +726,10 @@ class list(MutableSequence[_T], Generic[_T]): @overload def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... - def __add__(self, x: List[_T]) -> List[_T]: ... - def __iadd__(self: _S, x: Iterable[_T]) -> _S: ... + def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ... + def __iadd__(self, x: Iterable[_S]) -> List[Union[_T, _S]]: ... + # Workaround https://github.com/python/mypy/issues/5971 + def __radd__(self, x: List[_S]) -> List[Union[_T, _S]]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... def __imul__(self: _S, n: int) -> _S: ... diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index fb308b37018d..635ec97d4688 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -41,6 +41,7 @@ builtins.classmethod.__get__ builtins.complex.__complex__ builtins.ellipsis builtins.function +builtins.list.__radd__ builtins.memoryview.__contains__ builtins.memoryview.__iter__ builtins.memoryview.cast