Remove many redundant inheritances from Generic[] (#10933)

This commit is contained in:
Alex Waygood
2023-10-26 19:07:20 +01:00
committed by GitHub
parent 5dbdd59c9b
commit a08d4c8d2e
30 changed files with 81 additions and 81 deletions

View File

@@ -81,7 +81,7 @@ class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented
def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ...
@final
class dict_items(ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocumented
class dict_items(ItemsView[_KT_co, _VT_co]): # undocumented
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 10):
@property

View File

@@ -1,6 +1,6 @@
import sys
from collections.abc import Iterable, Iterator, MutableSet
from typing import Any, Generic, TypeVar, overload
from typing import Any, TypeVar, overload
from typing_extensions import Self
if sys.version_info >= (3, 9):
@@ -11,7 +11,7 @@ __all__ = ["WeakSet"]
_S = TypeVar("_S")
_T = TypeVar("_T")
class WeakSet(MutableSet[_T], Generic[_T]):
class WeakSet(MutableSet[_T]):
@overload
def __init__(self, data: None = None) -> None: ...
@overload

View File

@@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite
from collections.abc import Iterable
# pytype crashes if array inherits from collections.abc.MutableSequence instead of typing.MutableSequence
from typing import Any, Generic, MutableSequence, TypeVar, overload # noqa: Y022
from typing import Any, MutableSequence, TypeVar, overload # noqa: Y022
from typing_extensions import Literal, Self, SupportsIndex, TypeAlias
if sys.version_info >= (3, 12):
@@ -18,7 +18,7 @@ _T = TypeVar("_T", int, float, str)
typecodes: str
class array(MutableSequence[_T], Generic[_T]):
class array(MutableSequence[_T]):
@property
def typecode(self) -> _TypeCode: ...
@property

View File

@@ -2,7 +2,7 @@ import concurrent.futures
import sys
from collections.abc import Awaitable, Coroutine, Generator, Iterable, Iterator
from types import FrameType
from typing import Any, Generic, Protocol, TextIO, TypeVar, overload
from typing import Any, Protocol, TextIO, TypeVar, overload
from typing_extensions import Literal, TypeAlias
from . import _CoroutineLike
@@ -379,7 +379,7 @@ else:
# While this is true in general, here it's sort-of okay to have a covariant subclass,
# since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
# and `asyncio.Task.set_result()` always raises.
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright: ignore[reportGeneralTypeIssues]
class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportGeneralTypeIssues]
if sys.version_info >= (3, 12):
def __init__(
self,

View File

@@ -953,7 +953,7 @@ class slice:
__hash__: ClassVar[None] # type: ignore[assignment]
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
class tuple(Sequence[_T_co], Generic[_T_co]):
class tuple(Sequence[_T_co]):
def __new__(cls, __iterable: Iterable[_T_co] = ...) -> Self: ...
def __len__(self) -> int: ...
def __contains__(self, __key: object) -> bool: ...
@@ -1005,7 +1005,7 @@ class function:
# mypy uses `builtins.function.__get__` to represent methods, properties, and getset_descriptors so we type the return as Any.
def __get__(self, __instance: object, __owner: type | None = None) -> Any: ...
class list(MutableSequence[_T], Generic[_T]):
class list(MutableSequence[_T]):
@overload
def __init__(self) -> None: ...
@overload
@@ -1060,7 +1060,7 @@ class list(MutableSequence[_T], Generic[_T]):
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
class dict(MutableMapping[_KT, _VT]):
# __init__ should be kept roughly in line with `collections.UserDict.__init__`, which has similar semantics
# Also multiprocessing.managers.SyncManager.dict()
@overload
@@ -1133,7 +1133,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
@overload
def __ior__(self, __value: Iterable[tuple[_KT, _VT]]) -> Self: ...
class set(MutableSet[_T], Generic[_T]):
class set(MutableSet[_T]):
@overload
def __init__(self) -> None: ...
@overload
@@ -1173,7 +1173,7 @@ class set(MutableSet[_T], Generic[_T]):
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
class frozenset(AbstractSet[_T_co], Generic[_T_co]):
class frozenset(AbstractSet[_T_co]):
@overload
def __new__(cls) -> Self: ...
@overload
@@ -1202,7 +1202,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
class enumerate(Iterator[tuple[int, _T]]):
def __new__(cls, iterable: Iterable[_T], start: int = ...) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[int, _T]: ...
@@ -1411,7 +1411,7 @@ else:
def exit(code: sys._ExitCode = None) -> NoReturn: ...
class filter(Iterator[_T], Generic[_T]):
class filter(Iterator[_T]):
@overload
def __new__(cls, __function: None, __iterable: Iterable[_T | None]) -> Self: ...
@overload
@@ -1470,7 +1470,7 @@ def len(__obj: Sized) -> int: ...
def license() -> None: ...
def locals() -> dict[str, Any]: ...
class map(Iterator[_S], Generic[_S]):
class map(Iterator[_S]):
@overload
def __new__(cls, __func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> Self: ...
@overload
@@ -1742,7 +1742,7 @@ else:
def quit(code: sys._ExitCode = None) -> NoReturn: ...
class reversed(Iterator[_T], Generic[_T]):
class reversed(Iterator[_T]):
@overload
def __init__(self, __sequence: Reversible[_T]) -> None: ...
@overload
@@ -1816,7 +1816,7 @@ def vars(__object: type) -> types.MappingProxyType[str, Any]: ... # type: ignor
@overload
def vars(__object: Any = ...) -> dict[str, Any]: ...
class zip(Iterator[_T_co], Generic[_T_co]):
class zip(Iterator[_T_co]):
if sys.version_info >= (3, 10):
@overload
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...

View File

@@ -45,7 +45,7 @@ def namedtuple(
defaults: Iterable[Any] | None = None,
) -> type[tuple[Any, ...]]: ...
class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
class UserDict(MutableMapping[_KT, _VT]):
data: dict[_KT, _VT]
# __init__ should be kept roughly in line with `dict.__init__`, which has the same semantics
@overload
@@ -228,7 +228,7 @@ class UserString(Sequence[UserString]):
def upper(self) -> Self: ...
def zfill(self, width: int) -> Self: ...
class deque(MutableSequence[_T], Generic[_T]):
class deque(MutableSequence[_T]):
@property
def maxlen(self) -> int | None: ...
@overload
@@ -383,7 +383,7 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
@overload
def __ror__(self, __value: dict[_T1, _T2]) -> OrderedDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc]
class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
class defaultdict(dict[_KT, _VT]):
default_factory: Callable[[], _VT] | None
@overload
def __init__(self) -> None: ...
@@ -424,7 +424,7 @@ class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
@overload
def __ror__(self, __value: dict[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc]
class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
class ChainMap(MutableMapping[_KT, _VT]):
maps: list[MutableMapping[_KT, _VT]]
def __init__(self, *maps: MutableMapping[_KT, _VT]) -> None: ...
def new_child(self, m: MutableMapping[_KT, _VT] | None = None) -> Self: ...

View File

@@ -94,7 +94,7 @@ if sys.version_info >= (3, 10):
) -> bool | None: ...
else:
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], Generic[_T_co]):
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co]):
def __init__(self, func: Callable[..., AsyncIterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ...
gen: AsyncGenerator[_T_co, Any]
func: Callable[..., AsyncGenerator[_T_co, Any]]

View File

@@ -2,7 +2,7 @@ import sys
from _typeshed import AnyStr_co, StrOrBytesPath
from collections.abc import Callable, Iterable, Iterator
from types import TracebackType
from typing import IO, Any, AnyStr, Generic, Protocol, overload
from typing import IO, Any, AnyStr, Protocol, overload
from typing_extensions import Literal, Self, TypeAlias
if sys.version_info >= (3, 9):
@@ -158,7 +158,7 @@ def fileno() -> int: ...
def isfirstline() -> bool: ...
def isstdin() -> bool: ...
class FileInput(Iterator[AnyStr], Generic[AnyStr]):
class FileInput(Iterator[AnyStr]):
if sys.version_info >= (3, 10):
# encoding and errors are added
@overload

View File

@@ -23,7 +23,7 @@ _Predicate: TypeAlias = Callable[[_T], object]
# Technically count can take anything that implements a number protocol and has an add method
# but we can't enforce the add method
class count(Iterator[_N], Generic[_N]):
class count(Iterator[_N]):
@overload
def __new__(cls) -> count[int]: ...
@overload
@@ -33,12 +33,12 @@ class count(Iterator[_N], Generic[_N]):
def __next__(self) -> _N: ...
def __iter__(self) -> Self: ...
class cycle(Iterator[_T], Generic[_T]):
class cycle(Iterator[_T]):
def __init__(self, __iterable: Iterable[_T]) -> None: ...
def __next__(self) -> _T: ...
def __iter__(self) -> Self: ...
class repeat(Iterator[_T], Generic[_T]):
class repeat(Iterator[_T]):
@overload
def __init__(self, object: _T) -> None: ...
@overload
@@ -47,7 +47,7 @@ class repeat(Iterator[_T], Generic[_T]):
def __iter__(self) -> Self: ...
def __length_hint__(self) -> int: ...
class accumulate(Iterator[_T], Generic[_T]):
class accumulate(Iterator[_T]):
if sys.version_info >= (3, 8):
@overload
def __init__(self, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> None: ...
@@ -59,7 +59,7 @@ class accumulate(Iterator[_T], Generic[_T]):
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class chain(Iterator[_T], Generic[_T]):
class chain(Iterator[_T]):
def __init__(self, *iterables: Iterable[_T]) -> None: ...
def __next__(self) -> _T: ...
def __iter__(self) -> Self: ...
@@ -69,17 +69,17 @@ class chain(Iterator[_T], Generic[_T]):
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
class compress(Iterator[_T], Generic[_T]):
class compress(Iterator[_T]):
def __init__(self, data: Iterable[_T], selectors: Iterable[Any]) -> None: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class dropwhile(Iterator[_T], Generic[_T]):
class dropwhile(Iterator[_T]):
def __init__(self, __predicate: _Predicate[_T], __iterable: Iterable[_T]) -> None: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class filterfalse(Iterator[_T], Generic[_T]):
class filterfalse(Iterator[_T]):
def __init__(self, __predicate: _Predicate[_T] | None, __iterable: Iterable[_T]) -> None: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
@@ -92,7 +92,7 @@ class groupby(Iterator[tuple[_T, Iterator[_S]]], Generic[_T, _S]):
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[_T, Iterator[_S]]: ...
class islice(Iterator[_T], Generic[_T]):
class islice(Iterator[_T]):
@overload
def __init__(self, __iterable: Iterable[_T], __stop: int | None) -> None: ...
@overload
@@ -100,19 +100,19 @@ class islice(Iterator[_T], Generic[_T]):
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class starmap(Iterator[_T], Generic[_T]):
class starmap(Iterator[_T]):
def __init__(self, __function: Callable[..., _T], __iterable: Iterable[Iterable[Any]]) -> None: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class takewhile(Iterator[_T], Generic[_T]):
class takewhile(Iterator[_T]):
def __init__(self, __predicate: _Predicate[_T], __iterable: Iterable[_T]) -> None: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
def tee(__iterable: Iterable[_T], __n: int = 2) -> tuple[Iterator[_T], ...]: ...
class zip_longest(Iterator[_T_co], Generic[_T_co]):
class zip_longest(Iterator[_T_co]):
# one iterable (fillvalue doesn't matter)
@overload
def __new__(cls, __iter1: Iterable[_T1], *, fillvalue: object = ...) -> zip_longest[tuple[_T1]]: ...
@@ -192,7 +192,7 @@ class zip_longest(Iterator[_T_co], Generic[_T_co]):
def __iter__(self) -> Self: ...
def __next__(self) -> _T_co: ...
class product(Iterator[_T_co], Generic[_T_co]):
class product(Iterator[_T_co]):
@overload
def __new__(cls, __iter1: Iterable[_T1]) -> product[tuple[_T1]]: ...
@overload
@@ -246,7 +246,7 @@ class permutations(Iterator[tuple[_T, ...]], Generic[_T]):
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[_T, ...]: ...
class combinations(Iterator[_T_co], Generic[_T_co]):
class combinations(Iterator[_T_co]):
@overload
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ...
@overload
@@ -266,7 +266,7 @@ class combinations_with_replacement(Iterator[tuple[_T, ...]], Generic[_T]):
def __next__(self) -> tuple[_T, ...]: ...
if sys.version_info >= (3, 10):
class pairwise(Iterator[_T_co], Generic[_T_co]):
class pairwise(Iterator[_T_co]):
def __new__(cls, __iterable: Iterable[_T]) -> pairwise[tuple[_T, _T]]: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T_co: ...

View File

@@ -321,7 +321,7 @@ else:
dir: GenericPath[AnyStr] | None = None,
) -> IO[Any]: ...
class _TemporaryFileWrapper(IO[AnyStr], Generic[AnyStr]):
class _TemporaryFileWrapper(IO[AnyStr]):
file: IO[AnyStr] # io.TextIOWrapper, io.BufferedReader or io.BufferedWriter
name: str
delete: bool

View File

@@ -16,7 +16,7 @@ from collections.abc import (
from importlib.machinery import ModuleSpec
# pytype crashes if types.MappingProxyType inherits from collections.abc.Mapping instead of typing.Mapping
from typing import Any, ClassVar, Generic, Mapping, Protocol, TypeVar, overload # noqa: Y022
from typing import Any, ClassVar, Mapping, Protocol, TypeVar, overload # noqa: Y022
from typing_extensions import Literal, ParamSpec, Self, TypeVarTuple, final
__all__ = [
@@ -309,7 +309,7 @@ class CodeType:
) -> CodeType: ...
@final
class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]):
class MappingProxyType(Mapping[_KT, _VT_co]):
__hash__: ClassVar[None] # type: ignore[assignment]
def __new__(cls, mapping: SupportsKeysAndGetItem[_KT, _VT_co]) -> Self: ...
def __getitem__(self, __key: _KT) -> _VT_co: ...

View File

@@ -527,7 +527,7 @@ class Sequence(Collection[_T_co], Reversible[_T_co], Generic[_T_co]):
def __iter__(self) -> Iterator[_T_co]: ...
def __reversed__(self) -> Iterator[_T_co]: ...
class MutableSequence(Sequence[_T], Generic[_T]):
class MutableSequence(Sequence[_T]):
@abstractmethod
def insert(self, index: int, value: _T) -> None: ...
@overload
@@ -557,7 +557,7 @@ class MutableSequence(Sequence[_T], Generic[_T]):
def remove(self, value: _T) -> None: ...
def __iadd__(self, values: Iterable[_T]) -> typing_extensions.Self: ...
class AbstractSet(Collection[_T_co], Generic[_T_co]):
class AbstractSet(Collection[_T_co]):
@abstractmethod
def __contains__(self, x: object) -> bool: ...
def _hash(self) -> int: ...
@@ -573,7 +573,7 @@ class AbstractSet(Collection[_T_co], Generic[_T_co]):
def __eq__(self, other: object) -> bool: ...
def isdisjoint(self, other: Iterable[Any]) -> bool: ...
class MutableSet(AbstractSet[_T], Generic[_T]):
class MutableSet(AbstractSet[_T]):
@abstractmethod
def add(self, value: _T) -> None: ...
@abstractmethod
@@ -646,7 +646,7 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
def __contains__(self, __key: object) -> bool: ...
def __eq__(self, __other: object) -> bool: ...
class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
class MutableMapping(Mapping[_KT, _VT]):
@abstractmethod
def __setitem__(self, __key: _KT, __value: _VT) -> None: ...
@abstractmethod
@@ -703,7 +703,7 @@ TYPE_CHECKING: bool
# In stubs, the arguments of the IO class are marked as positional-only.
# This differs from runtime, but better reflects the fact that in reality
# classes deriving from IO use different names for the arguments.
class IO(Iterator[AnyStr], Generic[AnyStr]):
class IO(Iterator[AnyStr]):
# At runtime these are all abstract properties,
# but making them abstract in the stub is hugely disruptive, for not much gain.
# See #8726

View File

@@ -40,7 +40,7 @@ _P = ParamSpec("_P")
ProxyTypes: tuple[type[Any], ...]
class WeakMethod(ref[_CallableT], Generic[_CallableT]):
class WeakMethod(ref[_CallableT]):
def __new__(cls, meth: _CallableT, callback: Callable[[Self], object] | None = None) -> Self: ...
def __call__(self) -> _CallableT | None: ...
def __eq__(self, other: object) -> bool: ...