From c56cce0fe296baef49832d35e6dd123d768ed5c4 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 18 Aug 2018 20:10:10 -0700 Subject: [PATCH 1/5] fix list concatenation --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2/builtins.pyi | 2 +- stdlib/3/builtins.pyi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 2e9ea8591b80..bc62c02914ad 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -571,7 +571,7 @@ class list(MutableSequence[_T], Generic[_T]): def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self, x: List[_T]) -> List[_T]: ... + def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... diff --git a/stdlib/2/builtins.pyi b/stdlib/2/builtins.pyi index 2e9ea8591b80..bc62c02914ad 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -571,7 +571,7 @@ class list(MutableSequence[_T], Generic[_T]): def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self, x: List[_T]) -> List[_T]: ... + def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 78c598592c77..2bd4b99bb419 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -616,7 +616,7 @@ 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 __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... From 424991ec129d3740fe7777376ca9bd6338347c28 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 18 Aug 2018 20:15:34 -0700 Subject: [PATCH 2/5] also change __iadd__ --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2/builtins.pyi | 2 +- stdlib/3/builtins.pyi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index bc62c02914ad..8e19453f79f8 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -572,7 +572,7 @@ class list(MutableSequence[_T], Generic[_T]): def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __iadd__(self: List[_T_co], x: Iterable[_T_co]) -> List[_T_co]: ... 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 bc62c02914ad..8e19453f79f8 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -572,7 +572,7 @@ class list(MutableSequence[_T], Generic[_T]): def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __iadd__(self: List[_T_co], x: Iterable[_T_co]) -> List[_T_co]: ... 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 2bd4b99bb419..7ead0efd1d36 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -617,7 +617,7 @@ class list(MutableSequence[_T], Generic[_T]): def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __iadd__(self: List[_T_co], x: Iterable[_T_co]) -> List[_T_co]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... def __imul__(self, n: int) -> List[_T]: ... From a0c6dd8ad9b4bb7b6b5a415f11fb45393464c3bb Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 18 Aug 2018 20:19:57 -0700 Subject: [PATCH 3/5] Revert "also change __iadd__" This reverts commit 424991ec129d3740fe7777376ca9bd6338347c28. --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2/builtins.pyi | 2 +- stdlib/3/builtins.pyi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 8e19453f79f8..bc62c02914ad 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -572,7 +572,7 @@ class list(MutableSequence[_T], Generic[_T]): def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self: List[_T_co], x: Iterable[_T_co]) -> List[_T_co]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... 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 8e19453f79f8..bc62c02914ad 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -572,7 +572,7 @@ class list(MutableSequence[_T], Generic[_T]): def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self: List[_T_co], x: Iterable[_T_co]) -> List[_T_co]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... 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 7ead0efd1d36..2bd4b99bb419 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -617,7 +617,7 @@ class list(MutableSequence[_T], Generic[_T]): def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self: List[_T_co], x: Iterable[_T_co]) -> List[_T_co]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... def __imul__(self, n: int) -> List[_T]: ... From 1ca1914c9c0560ef4a0c84948f641b53ef233c3b Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 18 Aug 2018 20:20:56 -0700 Subject: [PATCH 4/5] ignore iadd instead --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2/builtins.pyi | 2 +- stdlib/3/builtins.pyi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index bc62c02914ad..708747c3a0ec 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -572,7 +572,7 @@ class list(MutableSequence[_T], Generic[_T]): def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... # type: ignore 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 bc62c02914ad..708747c3a0ec 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -572,7 +572,7 @@ class list(MutableSequence[_T], Generic[_T]): def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... # type: ignore 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 2bd4b99bb419..82c68b5aa573 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -617,7 +617,7 @@ class list(MutableSequence[_T], Generic[_T]): def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... - def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... # type: ignore def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... def __imul__(self, n: int) -> List[_T]: ... From e782da45dc7aebbbeb2cc7bed5f635672e1341f7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 25 Oct 2018 21:10:43 -0700 Subject: [PATCH 5/5] use a Union instead --- stdlib/2/__builtin__.pyi | 4 ++-- stdlib/2/builtins.pyi | 4 ++-- stdlib/3/builtins.pyi | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 708747c3a0ec..9feda83891ae 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -529,7 +529,7 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... - def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... + def __add__(self, x: Tuple[_S, ...]) -> Tuple[Union[_T_co, _S], ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... @@ -571,7 +571,7 @@ class list(MutableSequence[_T], Generic[_T]): def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... + def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... # type: ignore def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... diff --git a/stdlib/2/builtins.pyi b/stdlib/2/builtins.pyi index 708747c3a0ec..9feda83891ae 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -529,7 +529,7 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... - def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... + def __add__(self, x: Tuple[_S, ...]) -> Tuple[Union[_T_co, _S], ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... @@ -571,7 +571,7 @@ class list(MutableSequence[_T], Generic[_T]): def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... - def __add__(self: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... + def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... # type: ignore def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 82c68b5aa573..efd1b5d287c7 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -569,7 +569,7 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... - def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... + def __add__(self, x: Tuple[_S, ...]) -> Tuple[Union[_T_co, _S], ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... @@ -616,7 +616,7 @@ 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: List[_T_co], x: List[_T_co]) -> List[_T_co]: ... + def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ... def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... # type: ignore def __mul__(self, n: int) -> List[_T]: ... def __rmul__(self, n: int) -> List[_T]: ...