From 8826d3a36f5dd25c69f1d2a92a84b4103790e3b8 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 21 Jun 2022 20:51:05 +0100 Subject: [PATCH] Rename some confusingly named type aliases (#8129) --- stdlib/_ast.pyi | 8 +- stdlib/_codecs.pyi | 8 +- stdlib/_tracemalloc.pyi | 6 +- stdlib/asyncio/tasks.pyi | 160 +++++++++++++++++------------------ stdlib/tracemalloc.pyi | 16 ++-- stubs/redis/redis/typing.pyi | 2 +- 6 files changed, 100 insertions(+), 100 deletions(-) diff --git a/stdlib/_ast.pyi b/stdlib/_ast.pyi index 81cb9ffbf..2ae14c017 100644 --- a/stdlib/_ast.pyi +++ b/stdlib/_ast.pyi @@ -366,12 +366,12 @@ class Attribute(expr): ctx: expr_context if sys.version_info >= (3, 9): - _SliceT: TypeAlias = expr + _Slice: TypeAlias = expr else: class slice(AST): ... - _SliceT: TypeAlias = slice + _Slice: TypeAlias = slice -class Slice(_SliceT): +class Slice(_Slice): if sys.version_info >= (3, 10): __match_args__ = ("lower", "upper", "step") lower: expr | None @@ -389,7 +389,7 @@ class Subscript(expr): if sys.version_info >= (3, 10): __match_args__ = ("value", "slice", "ctx") value: expr - slice: _SliceT + slice: _Slice ctx: expr_context class Starred(expr): diff --git a/stdlib/_codecs.pyi b/stdlib/_codecs.pyi index 8fabf94d8..9241ac6a7 100644 --- a/stdlib/_codecs.pyi +++ b/stdlib/_codecs.pyi @@ -8,7 +8,7 @@ from typing_extensions import Literal, TypeAlias class _EncodingMap: def size(self) -> int: ... -_MapT: TypeAlias = dict[int, int] | _EncodingMap +_CharMap: TypeAlias = dict[int, int] | _EncodingMap _Handler: TypeAlias = Callable[[UnicodeError], tuple[str | bytes, int]] _SearchFunction: TypeAlias = Callable[[str], codecs.CodecInfo | None] @@ -66,11 +66,11 @@ def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = ...) - @overload def decode(obj: bytes, encoding: str = ..., errors: str = ...) -> str: ... def lookup(__encoding: str) -> codecs.CodecInfo: ... -def charmap_build(__map: str) -> _MapT: ... +def charmap_build(__map: str) -> _CharMap: ... def ascii_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ... def ascii_encode(__str: str, __errors: str | None = ...) -> tuple[bytes, int]: ... -def charmap_decode(__data: bytes, __errors: str | None = ..., __mapping: _MapT | None = ...) -> tuple[str, int]: ... -def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _MapT | None = ...) -> tuple[bytes, int]: ... +def charmap_decode(__data: bytes, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[str, int]: ... +def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[bytes, int]: ... def escape_decode(__data: str | bytes, __errors: str | None = ...) -> tuple[str, int]: ... def escape_encode(__data: bytes, __errors: str | None = ...) -> tuple[bytes, int]: ... def latin_1_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ... diff --git a/stdlib/_tracemalloc.pyi b/stdlib/_tracemalloc.pyi index 6e3c4e59a..2262d4b16 100644 --- a/stdlib/_tracemalloc.pyi +++ b/stdlib/_tracemalloc.pyi @@ -1,9 +1,9 @@ import sys from collections.abc import Sequence -from tracemalloc import _FrameTupleT, _TraceTupleT +from tracemalloc import _FrameTuple, _TraceTuple -def _get_object_traceback(__obj: object) -> Sequence[_FrameTupleT] | None: ... -def _get_traces() -> Sequence[_TraceTupleT]: ... +def _get_object_traceback(__obj: object) -> Sequence[_FrameTuple] | None: ... +def _get_traces() -> Sequence[_TraceTuple]: ... def clear_traces() -> None: ... def get_traceback_limit() -> int: ... def get_traced_memory() -> tuple[int, int]: ... diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index e20720aef..8442090f1 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -58,7 +58,7 @@ _T3 = TypeVar("_T3") _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") _FT = TypeVar("_FT", bound=Future[Any]) -_FutureT: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T] +_FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T] _TaskYieldType: TypeAlias = Future[object] | None FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED @@ -66,11 +66,11 @@ FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION ALL_COMPLETED = concurrent.futures.ALL_COMPLETED if sys.version_info >= (3, 10): - def as_completed(fs: Iterable[_FutureT[_T]], *, timeout: float | None = ...) -> Iterator[Future[_T]]: ... + def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = ...) -> Iterator[Future[_T]]: ... else: def as_completed( - fs: Iterable[_FutureT[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ... + fs: Iterable[_FutureLike[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ... ) -> Iterator[Future[_T]]: ... @overload @@ -89,68 +89,68 @@ if sys.version_info >= (3, 10): @overload def gather(*, return_exceptions: bool = ...) -> Future[tuple[()]]: ... @overload - def gather(__coro_or_future1: _FutureT[_T1], *, return_exceptions: Literal[False] = ...) -> Future[tuple[_T1]]: ... + def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: Literal[False] = ...) -> Future[tuple[_T1]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], __coro_or_future2: _FutureT[_T2], *, return_exceptions: Literal[False] = ... + __coro_or_future1: _FutureLike[_T1], __coro_or_future2: _FutureLike[_T2], *, return_exceptions: Literal[False] = ... ) -> Future[tuple[_T1, _T2]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], *, return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], *, return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], - __coro_or_future5: _FutureT[_T5], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], + __coro_or_future5: _FutureLike[_T5], *, return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ... @overload - def gather(__coro_or_future1: _FutureT[_T1], *, return_exceptions: bool) -> Future[tuple[_T1 | BaseException]]: ... + def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: bool) -> Future[tuple[_T1 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], __coro_or_future2: _FutureT[_T2], *, return_exceptions: bool + __coro_or_future1: _FutureLike[_T1], __coro_or_future2: _FutureLike[_T2], *, return_exceptions: bool ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], *, return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], *, return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], - __coro_or_future5: _FutureT[_T5], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], + __coro_or_future5: _FutureLike[_T5], *, return_exceptions: bool, ) -> Future[ @@ -158,13 +158,13 @@ if sys.version_info >= (3, 10): ]: ... @overload def gather( - __coro_or_future1: _FutureT[Any], - __coro_or_future2: _FutureT[Any], - __coro_or_future3: _FutureT[Any], - __coro_or_future4: _FutureT[Any], - __coro_or_future5: _FutureT[Any], - __coro_or_future6: _FutureT[Any], - *coros_or_futures: _FutureT[Any], + __coro_or_future1: _FutureLike[Any], + __coro_or_future2: _FutureLike[Any], + __coro_or_future3: _FutureLike[Any], + __coro_or_future4: _FutureLike[Any], + __coro_or_future5: _FutureLike[Any], + __coro_or_future6: _FutureLike[Any], + *coros_or_futures: _FutureLike[Any], return_exceptions: bool = ..., ) -> Future[list[Any]]: ... @@ -173,84 +173,84 @@ else: def gather(*, loop: AbstractEventLoop | None = ..., return_exceptions: bool = ...) -> Future[tuple[()]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ... + __coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ... ) -> Future[tuple[_T1]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], - __coro_or_future5: _FutureT[_T5], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], + __coro_or_future5: _FutureLike[_T5], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool + __coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool ) -> Future[tuple[_T1 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], - __coro_or_future5: _FutureT[_T5], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], + __coro_or_future5: _FutureLike[_T5], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool, @@ -259,21 +259,21 @@ else: ]: ... @overload def gather( - __coro_or_future1: _FutureT[Any], - __coro_or_future2: _FutureT[Any], - __coro_or_future3: _FutureT[Any], - __coro_or_future4: _FutureT[Any], - __coro_or_future5: _FutureT[Any], - __coro_or_future6: _FutureT[Any], - *coros_or_futures: _FutureT[Any], + __coro_or_future1: _FutureLike[Any], + __coro_or_future2: _FutureLike[Any], + __coro_or_future3: _FutureLike[Any], + __coro_or_future4: _FutureLike[Any], + __coro_or_future5: _FutureLike[Any], + __coro_or_future6: _FutureLike[Any], + *coros_or_futures: _FutureLike[Any], loop: AbstractEventLoop | None = ..., return_exceptions: bool = ..., ) -> Future[list[Any]]: ... -def run_coroutine_threadsafe(coro: _FutureT[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ... +def run_coroutine_threadsafe(coro: _FutureLike[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ... if sys.version_info >= (3, 10): - def shield(arg: _FutureT[_T]) -> Future[_T]: ... + def shield(arg: _FutureLike[_T]) -> Future[_T]: ... @overload async def sleep(delay: float) -> None: ... @overload @@ -284,10 +284,10 @@ if sys.version_info >= (3, 10): async def wait( fs: Iterable[Awaitable[_T]], *, timeout: float | None = ..., return_when: str = ... ) -> tuple[set[Task[_T]], set[Task[_T]]]: ... - async def wait_for(fut: _FutureT[_T], timeout: float | None) -> _T: ... + async def wait_for(fut: _FutureLike[_T], timeout: float | None) -> _T: ... else: - def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ... + def shield(arg: _FutureLike[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ... @overload async def sleep(delay: float, *, loop: AbstractEventLoop | None = ...) -> None: ... @overload @@ -300,7 +300,7 @@ else: async def wait( fs: Iterable[Awaitable[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ... ) -> tuple[set[Task[_T]], set[Task[_T]]]: ... - async def wait_for(fut: _FutureT[_T], timeout: float | None, *, loop: AbstractEventLoop | None = ...) -> _T: ... + async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = ...) -> _T: ... class Task(Future[_T], Generic[_T]): if sys.version_info >= (3, 8): diff --git a/stdlib/tracemalloc.pyi b/stdlib/tracemalloc.pyi index 193a4acc7..4b7063e5d 100644 --- a/stdlib/tracemalloc.pyi +++ b/stdlib/tracemalloc.pyi @@ -42,14 +42,14 @@ class StatisticDiff: def __init__(self, traceback: Traceback, size: int, size_diff: int, count: int, count_diff: int) -> None: ... def __eq__(self, other: object) -> bool: ... -_FrameTupleT: TypeAlias = tuple[str, int] +_FrameTuple: TypeAlias = tuple[str, int] class Frame: @property def filename(self) -> str: ... @property def lineno(self) -> int: ... - def __init__(self, frame: _FrameTupleT) -> None: ... + def __init__(self, frame: _FrameTuple) -> None: ... def __eq__(self, other: object) -> bool: ... def __lt__(self, other: Frame) -> bool: ... if sys.version_info >= (3, 11): @@ -62,9 +62,9 @@ class Frame: def __le__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... if sys.version_info >= (3, 9): - _TraceTupleT: TypeAlias = Union[tuple[int, int, Sequence[_FrameTupleT], int | None], tuple[int, int, Sequence[_FrameTupleT]]] + _TraceTuple: TypeAlias = Union[tuple[int, int, Sequence[_FrameTuple], int | None], tuple[int, int, Sequence[_FrameTuple]]] else: - _TraceTupleT: TypeAlias = tuple[int, int, Sequence[_FrameTupleT]] + _TraceTuple: TypeAlias = tuple[int, int, Sequence[_FrameTuple]] class Trace: @property @@ -73,16 +73,16 @@ class Trace: def size(self) -> int: ... @property def traceback(self) -> Traceback: ... - def __init__(self, trace: _TraceTupleT) -> None: ... + def __init__(self, trace: _TraceTuple) -> None: ... def __eq__(self, other: object) -> bool: ... class Traceback(Sequence[Frame]): if sys.version_info >= (3, 9): @property def total_nframe(self) -> int | None: ... - def __init__(self, frames: Sequence[_FrameTupleT], total_nframe: int | None = ...) -> None: ... + def __init__(self, frames: Sequence[_FrameTuple], total_nframe: int | None = ...) -> None: ... else: - def __init__(self, frames: Sequence[_FrameTupleT]) -> None: ... + def __init__(self, frames: Sequence[_FrameTuple]) -> None: ... if sys.version_info >= (3, 7): def format(self, limit: int | None = ..., most_recent_first: bool = ...) -> list[str]: ... else: @@ -106,7 +106,7 @@ class Traceback(Sequence[Frame]): def __le__(self, other: Traceback, NotImplemented: Any = ...) -> bool: ... class Snapshot: - def __init__(self, traces: Sequence[_TraceTupleT], traceback_limit: int) -> None: ... + def __init__(self, traces: Sequence[_TraceTuple], traceback_limit: int) -> None: ... def compare_to(self, old_snapshot: Snapshot, key_type: str, cumulative: bool = ...) -> list[StatisticDiff]: ... def dump(self, filename: str) -> None: ... def filter_traces(self, filters: Sequence[DomainFilter | Filter]) -> Snapshot: ... diff --git a/stubs/redis/redis/typing.pyi b/stubs/redis/redis/typing.pyi index bbce081fc..f351ed45a 100644 --- a/stubs/redis/redis/typing.pyi +++ b/stubs/redis/redis/typing.pyi @@ -14,7 +14,7 @@ AbsExpiryT: TypeAlias = int | datetime ExpiryT: TypeAlias = float | timedelta ZScoreBoundT: TypeAlias = float | str BitfieldOffsetT: TypeAlias = int | str -_StringLikeT: TypeAlias = bytes | str | memoryview +_StringLikeT: TypeAlias = bytes | str | memoryview # noqa: Y043 KeyT: TypeAlias = _StringLikeT PatternT: TypeAlias = _StringLikeT FieldT: TypeAlias = EncodableT