From 8023ba764a034336b378664c41c597d90dd85a5d Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 6 Nov 2023 13:00:25 +0000 Subject: [PATCH] Remove redundant inheritances from `Generic` and various `typing` protocols (#10981) --- stdlib/contextlib.pyi | 4 ++-- stdlib/ipaddress.pyi | 4 ++-- stdlib/typing.pyi | 6 +++--- stubs/redis/redis/asyncio/client.pyi | 4 ++-- stubs/redis/redis/client.pyi | 4 ++-- stubs/redis/redis/cluster.pyi | 4 ++-- stubs/redis/redis/commands/cluster.pyi | 9 ++------- stubs/redis/redis/commands/core.pyi | 4 ---- stubs/tqdm/tqdm/std.pyi | 2 +- 9 files changed, 16 insertions(+), 25 deletions(-) diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index c1bfedd2d..ce46d0d39 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -56,7 +56,7 @@ class AbstractAsyncContextManager(Protocol[_T_co]): class ContextDecorator: def __call__(self, func: _F) -> _F: ... -class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator, Generic[_T_co]): +class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator): # __init__ and all instance attributes are actually inherited from _GeneratorContextManagerBase # _GeneratorContextManagerBase is more trouble than it's worth to include in the stub; see #6676 def __init__(self, func: Callable[..., Iterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ... @@ -81,7 +81,7 @@ if sys.version_info >= (3, 10): class AsyncContextDecorator: def __call__(self, func: _AF) -> _AF: ... - class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], AsyncContextDecorator, Generic[_T_co]): + class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], AsyncContextDecorator): # __init__ and these attributes are actually defined in the base class _GeneratorContextManagerBase, # which is more trouble than it's worth to include in the stub (see #6676) def __init__(self, func: Callable[..., AsyncIterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ... diff --git a/stdlib/ipaddress.pyi b/stdlib/ipaddress.pyi index 945e8bcbb..13a8c4330 100644 --- a/stdlib/ipaddress.pyi +++ b/stdlib/ipaddress.pyi @@ -1,5 +1,5 @@ import sys -from collections.abc import Container, Iterable, Iterator +from collections.abc import Iterable, Iterator from typing import Any, Generic, SupportsInt, TypeVar, overload from typing_extensions import Literal, Self, TypeAlias @@ -70,7 +70,7 @@ class _BaseAddress(_IPAddressBase, SupportsInt): @property def packed(self) -> bytes: ... -class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): +class _BaseNetwork(_IPAddressBase, Generic[_A]): network_address: _A netmask: _A def __init__(self, address: object, strict: bool = ...) -> None: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index ad5719ca9..7694157d7 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -513,7 +513,7 @@ class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): @abstractmethod def __len__(self) -> int: ... -class Sequence(Collection[_T_co], Reversible[_T_co], Generic[_T_co]): +class Sequence(Collection[_T_co], Reversible[_T_co]): @overload @abstractmethod def __getitem__(self, index: int) -> _T_co: ... @@ -607,7 +607,7 @@ class ItemsView(MappingView, AbstractSet[tuple[_KT_co, _VT_co]], Generic[_KT_co, def __xor__(self, other: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ... def __rxor__(self, other: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ... -class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]): +class KeysView(MappingView, AbstractSet[_KT_co]): def __init__(self, mapping: Mapping[_KT_co, Any]) -> None: ... # undocumented def __and__(self, other: Iterable[Any]) -> set[_KT_co]: ... def __rand__(self, other: Iterable[_T]) -> set[_T]: ... @@ -623,7 +623,7 @@ class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]): def __xor__(self, other: Iterable[_T]) -> set[_KT_co | _T]: ... def __rxor__(self, other: Iterable[_T]) -> set[_KT_co | _T]: ... -class ValuesView(MappingView, Collection[_VT_co], Generic[_VT_co]): +class ValuesView(MappingView, Collection[_VT_co]): def __init__(self, mapping: Mapping[Any, _VT_co]) -> None: ... # undocumented def __contains__(self, value: object) -> bool: ... def __iter__(self) -> Iterator[_VT_co]: ... diff --git a/stubs/redis/redis/asyncio/client.pyi b/stubs/redis/redis/asyncio/client.pyi index e58f75d2b..31006fd36 100644 --- a/stubs/redis/redis/asyncio/client.pyi +++ b/stubs/redis/redis/asyncio/client.pyi @@ -2,7 +2,7 @@ from _typeshed import Incomplete, Unused from collections.abc import AsyncIterator, Awaitable, Callable, Generator, Iterable, Mapping, MutableMapping, Sequence from datetime import datetime, timedelta from types import TracebackType -from typing import Any, ClassVar, Generic, NoReturn, Protocol, overload +from typing import Any, ClassVar, NoReturn, Protocol, overload from typing_extensions import Literal, Self, TypeAlias, TypedDict from redis import RedisError @@ -24,7 +24,7 @@ class AsyncResponseCallbackProtocol(Protocol): ResponseCallbackT: TypeAlias = ResponseCallbackProtocol | AsyncResponseCallbackProtocol -class Redis(AbstractRedis, RedisModuleCommands, AsyncCoreCommands[_StrType], AsyncSentinelCommands, Generic[_StrType]): +class Redis(AbstractRedis, RedisModuleCommands, AsyncCoreCommands[_StrType], AsyncSentinelCommands): response_callbacks: MutableMapping[str | bytes, ResponseCallbackT] auto_close_connection_pool: bool connection_pool: Any diff --git a/stubs/redis/redis/client.pyi b/stubs/redis/redis/client.pyi index 124cceafe..871d11587 100644 --- a/stubs/redis/redis/client.pyi +++ b/stubs/redis/redis/client.pyi @@ -4,7 +4,7 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from datetime import datetime, timedelta from re import Pattern from types import TracebackType -from typing import Any, ClassVar, Generic, TypeVar, overload +from typing import Any, ClassVar, TypeVar, overload from typing_extensions import Literal, Self, TypeAlias from redis import RedisError @@ -76,7 +76,7 @@ _LockType = TypeVar("_LockType") class AbstractRedis: RESPONSE_CALLBACKS: dict[str, Any] -class Redis(AbstractRedis, RedisModuleCommands, CoreCommands[_StrType], SentinelCommands, Generic[_StrType]): +class Redis(AbstractRedis, RedisModuleCommands, CoreCommands[_StrType], SentinelCommands): @overload @classmethod def from_url( diff --git a/stubs/redis/redis/cluster.pyi b/stubs/redis/redis/cluster.pyi index 7cca70103..dc1a6f411 100644 --- a/stubs/redis/redis/cluster.pyi +++ b/stubs/redis/redis/cluster.pyi @@ -2,7 +2,7 @@ from _typeshed import Incomplete, Unused from collections.abc import Callable, Iterable, Sequence from threading import Lock from types import TracebackType -from typing import Any, ClassVar, Generic, NoReturn, Protocol +from typing import Any, ClassVar, NoReturn, Protocol from typing_extensions import Literal, Self from redis.client import CaseInsensitiveDict, PubSub, Redis, _ParseResponseOptions @@ -45,7 +45,7 @@ class AbstractRedisCluster: RESULT_CALLBACKS: ClassVar[dict[str, Callable[[Incomplete, Incomplete], Incomplete]]] ERRORS_ALLOW_RETRY: ClassVar[tuple[type[RedisError], ...]] -class RedisCluster(AbstractRedisCluster, RedisClusterCommands[_StrType], Generic[_StrType]): +class RedisCluster(AbstractRedisCluster, RedisClusterCommands[_StrType]): user_on_connect_func: Callable[[Connection], object] | None encoder: Encoder cluster_error_retry_attempts: int diff --git a/stubs/redis/redis/commands/cluster.pyi b/stubs/redis/redis/commands/cluster.pyi index a6b329e9f..ffcd4e1e4 100644 --- a/stubs/redis/redis/commands/cluster.pyi +++ b/stubs/redis/redis/commands/cluster.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from typing import Generic, NoReturn +from typing import NoReturn from .core import ACLCommands, DataAccessCommands, ManagementCommands, PubSubCommands, _StrType @@ -31,12 +31,7 @@ class ClusterDataAccessCommands(DataAccessCommands[_StrType]): ): ... class RedisClusterCommands( - ClusterMultiKeyCommands, - ClusterManagementCommands, - ACLCommands[_StrType], - PubSubCommands, - ClusterDataAccessCommands[_StrType], - Generic[_StrType], + ClusterMultiKeyCommands, ClusterManagementCommands, ACLCommands[_StrType], PubSubCommands, ClusterDataAccessCommands[_StrType] ): def cluster_addslots(self, target_node, *slots): ... def cluster_countkeysinslot(self, slot_id): ... diff --git a/stubs/redis/redis/commands/core.pyi b/stubs/redis/redis/commands/core.pyi index 437e93bee..70a4d1885 100644 --- a/stubs/redis/redis/commands/core.pyi +++ b/stubs/redis/redis/commands/core.pyi @@ -1705,7 +1705,6 @@ class DataAccessCommands( SetCommands[_StrType], StreamCommands, SortedSetCommands[_StrType], - Generic[_StrType], ): ... class AsyncDataAccessCommands( AsyncBasicKeyCommands[_StrType], @@ -1717,7 +1716,6 @@ class AsyncDataAccessCommands( AsyncSetCommands[_StrType], AsyncStreamCommands, AsyncSortedSetCommands[_StrType], - Generic[_StrType], ): ... class CoreCommands( ACLCommands[_StrType], @@ -1727,7 +1725,6 @@ class CoreCommands( ModuleCommands, PubSubCommands, ScriptCommands[_StrType], - Generic[_StrType], ): ... class AsyncCoreCommands( AsyncACLCommands[_StrType], @@ -1738,5 +1735,4 @@ class AsyncCoreCommands( AsyncPubSubCommands, AsyncScriptCommands[_StrType], AsyncFunctionCommands, - Generic[_StrType], ): ... diff --git a/stubs/tqdm/tqdm/std.pyi b/stubs/tqdm/tqdm/std.pyi index 534e4afcd..87301daa5 100644 --- a/stubs/tqdm/tqdm/std.pyi +++ b/stubs/tqdm/tqdm/std.pyi @@ -31,7 +31,7 @@ class TqdmMonitorWarning(TqdmWarning, RuntimeWarning): ... _T = TypeVar("_T") -class tqdm(Iterable[_T], Comparable, Generic[_T]): +class tqdm(Comparable, Generic[_T]): monitor_interval: ClassVar[int] monitor: ClassVar[TMonitor | None]