Backport more Self-related changes to Python 2 (#7166)

This commit is contained in:
Alex Waygood
2022-02-08 17:52:43 +00:00
committed by GitHub
parent 2381066c15
commit 5f830d023f
8 changed files with 29 additions and 32 deletions

View File

@@ -1,7 +1,5 @@
from _typeshed import Self
from typing import Any, Iterable, MutableSequence, Sequence, Text, TypeVar, overload
_MST = TypeVar("_MST", bound=MutableString)
from typing import Any, Iterable, MutableSequence, Sequence, Text, overload
class UserString(Sequence[UserString]):
data: unicode
@@ -70,5 +68,5 @@ class MutableString(UserString, MutableSequence[MutableString]):
def __delitem__(self, index: int | slice) -> None: ...
def immutable(self) -> UserString: ...
def __iadd__(self: Self, other: Any) -> Self: ...
def __imul__(self, n: int) -> _MST: ...
def __imul__(self: Self, n: int) -> Self: ...
def insert(self, index: int, value: Any) -> None: ...

View File

@@ -708,9 +708,9 @@ class set(MutableSet[_T], Generic[_T]):
def __contains__(self, o: object) -> bool: ...
def __iter__(self) -> Iterator[_T]: ...
def __and__(self, s: AbstractSet[object]) -> set[_T]: ...
def __iand__(self, s: AbstractSet[object]) -> set[_T]: ...
def __iand__(self: Self, s: AbstractSet[object]) -> Self: ...
def __or__(self, s: AbstractSet[_S]) -> set[_T | _S]: ...
def __ior__(self, s: AbstractSet[_S]) -> set[_T | _S]: ...
def __ior__(self: Self, s: AbstractSet[_T]) -> Self: ...
@overload
def __sub__(self: set[str], s: AbstractSet[Text | None]) -> set[_T]: ...
@overload
@@ -720,7 +720,7 @@ class set(MutableSet[_T], Generic[_T]):
@overload
def __isub__(self, s: AbstractSet[_T | None]) -> set[_T]: ...
def __xor__(self, s: AbstractSet[_S]) -> set[_T | _S]: ...
def __ixor__(self, s: AbstractSet[_S]) -> set[_T | _S]: ...
def __ixor__(self: Self, s: AbstractSet[_S]) -> Self: ...
def __le__(self, s: AbstractSet[object]) -> bool: ...
def __lt__(self, s: AbstractSet[object]) -> bool: ...
def __ge__(self, s: AbstractSet[object]) -> bool: ...

View File

@@ -4,7 +4,6 @@ from typing import Any, Callable, Generic, Iterator, TypeVar
_K = TypeVar("_K")
_V = TypeVar("_V")
_T = TypeVar("_T")
_T2 = TypeVar("_T2")
class defaultdict(dict[_K, _V]):
default_factory: None
@@ -30,7 +29,7 @@ class deque(Generic[_T]):
def __contains__(self, o: Any) -> bool: ...
def __copy__(self) -> deque[_T]: ...
def __getitem__(self, i: int) -> _T: ...
def __iadd__(self, other: deque[_T2]) -> deque[_T | _T2]: ...
def __iadd__(self: Self, other: deque[_T]) -> Self: ...
def __iter__(self) -> Iterator[_T]: ...
def __len__(self) -> int: ...
def __reversed__(self) -> Iterator[_T]: ...

View File

@@ -16,15 +16,15 @@ class WeakSet(MutableSet[_T], Generic[_T]):
def __contains__(self, item: object) -> bool: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[_T]: ...
def __ior__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def __ior__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
def difference(self: Self, other: Iterable[_T]) -> Self: ...
def __sub__(self: Self, other: Iterable[_T]) -> Self: ...
def difference_update(self, other: Iterable[_T]) -> None: ...
def __isub__(self: Self, other: Iterable[_T]) -> Self: ...
def __sub__(self: Self, other: Iterable[Any]) -> Self: ...
def difference_update(self, other: Iterable[Any]) -> None: ...
def __isub__(self: Self, other: Iterable[Any]) -> Self: ...
def intersection(self: Self, other: Iterable[_T]) -> Self: ...
def __and__(self: Self, other: Iterable[_T]) -> Self: ...
def intersection_update(self, other: Iterable[_T]) -> None: ...
def __iand__(self: Self, other: Iterable[_T]) -> Self: ...
def __and__(self: Self, other: Iterable[Any]) -> Self: ...
def intersection_update(self, other: Iterable[Any]) -> None: ...
def __iand__(self: Self, other: Iterable[Any]) -> Self: ...
def issubset(self, other: Iterable[_T]) -> bool: ...
def __le__(self, other: Iterable[_T]) -> bool: ...
def __lt__(self, other: Iterable[_T]) -> bool: ...
@@ -34,8 +34,8 @@ class WeakSet(MutableSet[_T], Generic[_T]):
def __eq__(self, other: object) -> bool: ...
def symmetric_difference(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def __xor__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def symmetric_difference_update(self, other: Iterable[Any]) -> None: ...
def __ixor__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def symmetric_difference_update(self, other: Iterable[_T]) -> None: ...
def __ixor__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
def union(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def __or__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def isdisjoint(self, other: Iterable[_T]) -> bool: ...

View File

@@ -1,3 +1,4 @@
from _typeshed import Self
from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, Text, TypeVar, Union, overload
from typing_extensions import Literal
@@ -52,7 +53,7 @@ class array(MutableSequence[_T], Generic[_T]):
def __add__(self, x: array[_T]) -> array[_T]: ...
def __ge__(self, other: array[_T]) -> bool: ...
def __gt__(self, other: array[_T]) -> bool: ...
def __iadd__(self, x: array[_T]) -> array[_T]: ... # type: ignore # Overrides MutableSequence
def __iadd__(self: Self, x: array[_T]) -> Self: ... # type: ignore[override]
def __imul__(self, n: int) -> array[_T]: ...
def __le__(self, other: array[_T]) -> bool: ...
def __lt__(self, other: array[_T]) -> bool: ...

View File

@@ -708,9 +708,9 @@ class set(MutableSet[_T], Generic[_T]):
def __contains__(self, o: object) -> bool: ...
def __iter__(self) -> Iterator[_T]: ...
def __and__(self, s: AbstractSet[object]) -> set[_T]: ...
def __iand__(self, s: AbstractSet[object]) -> set[_T]: ...
def __iand__(self: Self, s: AbstractSet[object]) -> Self: ...
def __or__(self, s: AbstractSet[_S]) -> set[_T | _S]: ...
def __ior__(self, s: AbstractSet[_S]) -> set[_T | _S]: ...
def __ior__(self: Self, s: AbstractSet[_T]) -> Self: ...
@overload
def __sub__(self: set[str], s: AbstractSet[Text | None]) -> set[_T]: ...
@overload
@@ -720,7 +720,7 @@ class set(MutableSet[_T], Generic[_T]):
@overload
def __isub__(self, s: AbstractSet[_T | None]) -> set[_T]: ...
def __xor__(self, s: AbstractSet[_S]) -> set[_T | _S]: ...
def __ixor__(self, s: AbstractSet[_S]) -> set[_T | _S]: ...
def __ixor__(self: Self, s: AbstractSet[_T]) -> Self: ...
def __le__(self, s: AbstractSet[object]) -> bool: ...
def __lt__(self, s: AbstractSet[object]) -> bool: ...
def __ge__(self, s: AbstractSet[object]) -> bool: ...

View File

@@ -87,10 +87,10 @@ class Counter(dict[_T, int], Generic[_T]):
def __sub__(self, other: Counter[_T]) -> Counter[_T]: ...
def __and__(self, other: Counter[_T]) -> Counter[_T]: ...
def __or__(self, other: Counter[_T]) -> Counter[_T]: ...
def __iadd__(self, other: Counter[_T]) -> Counter[_T]: ...
def __isub__(self, other: Counter[_T]) -> Counter[_T]: ...
def __iand__(self, other: Counter[_T]) -> Counter[_T]: ...
def __ior__(self, other: Counter[_T]) -> Counter[_T]: ...
def __iadd__(self: Self, other: Counter[_T]) -> Self: ...
def __isub__(self: Self, other: Counter[_T]) -> Self: ...
def __iand__(self: Self, other: Counter[_T]) -> Self: ...
def __ior__(self: Self, other: Counter[_T]) -> Self: ...
class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
def popitem(self, last: bool = ...) -> tuple[_KT, _VT]: ...

View File

@@ -58,7 +58,6 @@ NoReturn = Union[None]
# These type variables are used by the container types.
_T = TypeVar("_T")
_S = TypeVar("_S")
_KT = TypeVar("_KT") # Key type.
_VT = TypeVar("_VT") # Value type.
_T_co = TypeVar("_T_co", covariant=True) # Any type covariant containers.
@@ -211,7 +210,7 @@ class MutableSequence(Sequence[_T], Generic[_T]):
def reverse(self) -> None: ...
def pop(self, index: int = ...) -> _T: ...
def remove(self, object: _T) -> None: ...
def __iadd__(self, x: Iterable[_T]) -> MutableSequence[_T]: ...
def __iadd__(self: Self, x: Iterable[_T]) -> Self: ...
class AbstractSet(Iterable[_T_co], Container[_T_co], Generic[_T_co]):
@abstractmethod
@@ -240,10 +239,10 @@ class MutableSet(AbstractSet[_T], Generic[_T]):
def clear(self) -> None: ...
def pop(self) -> _T: ...
def remove(self, element: _T) -> None: ...
def __ior__(self, s: AbstractSet[_S]) -> MutableSet[_T | _S]: ...
def __iand__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
def __ixor__(self, s: AbstractSet[_S]) -> MutableSet[_T | _S]: ...
def __isub__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
def __ior__(self: Self, s: AbstractSet[_T]) -> Self: ...
def __iand__(self: Self, s: AbstractSet[Any]) -> Self: ...
def __ixor__(self: Self, s: AbstractSet[_T]) -> Self: ...
def __isub__(self: Self, s: AbstractSet[Any]) -> Self: ...
class MappingView(object):
def __len__(self) -> int: ...