diff --git a/stdlib/_codecs.pyi b/stdlib/_codecs.pyi index 1781a2418..e0fe26cf1 100644 --- a/stdlib/_codecs.pyi +++ b/stdlib/_codecs.pyi @@ -1,13 +1,14 @@ import codecs import sys from typing import Any, Callable +from typing_extensions import TypeAlias # This type is not exposed; it is defined in unicodeobject.c class _EncodingMap: def size(self) -> int: ... -_MapT = dict[int, int] | _EncodingMap -_Handler = Callable[[Exception], tuple[str, int]] +_MapT: TypeAlias = dict[int, int] | _EncodingMap +_Handler: TypeAlias = Callable[[Exception], tuple[str, int]] def register(__search_function: Callable[[str], Any]) -> None: ... def register_error(__errors: str, __handler: _Handler) -> None: ... diff --git a/stdlib/_csv.pyi b/stdlib/_csv.pyi index 161a89778..c89571031 100644 --- a/stdlib/_csv.pyi +++ b/stdlib/_csv.pyi @@ -1,5 +1,5 @@ from typing import Any, Iterable, Iterator, Protocol, Union -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __version__: str @@ -21,7 +21,7 @@ class Dialect: strict: int def __init__(self) -> None: ... -_DialectLike = Union[str, Dialect, type[Dialect]] +_DialectLike: TypeAlias = Union[str, Dialect, type[Dialect]] class _reader(Iterator[list[str]]): dialect: Dialect diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index e193759bd..95a128a32 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,10 +1,10 @@ import sys from _typeshed import SupportsRead from typing import IO, Any, NamedTuple, overload -from typing_extensions import final +from typing_extensions import TypeAlias, final if sys.platform != "win32": - _chtype = str | bytes | int + _chtype: TypeAlias = str | bytes | int # ACS codes are only initialized after initscr is called ACS_BBSS: int diff --git a/stdlib/_dummy_threading.pyi b/stdlib/_dummy_threading.pyi index 1cbb8f1ee..3810f9fe7 100644 --- a/stdlib/_dummy_threading.pyi +++ b/stdlib/_dummy_threading.pyi @@ -1,11 +1,12 @@ import sys from types import FrameType, TracebackType from typing import Any, Callable, Iterable, Mapping, TypeVar +from typing_extensions import TypeAlias # TODO recursive type -_TF = Callable[[FrameType, str, Any], Callable[..., Any] | None] +_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None] -_PF = Callable[[FrameType, str, Any], None] +_PF: TypeAlias = Callable[[FrameType, str, Any], None] _T = TypeVar("_T") if sys.version_info >= (3, 8): diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index 375d8e4dd..57f69b598 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -15,7 +15,7 @@ from typing import ( TypeVar, overload, ) -from typing_extensions import ParamSpec, SupportsIndex, final +from typing_extensions import ParamSpec, SupportsIndex, TypeAlias, final _R = TypeVar("_R") _T = TypeVar("_T") @@ -40,7 +40,7 @@ class _SupportsDunderLE(Protocol): class _SupportsDunderGE(Protocol): def __ge__(self, __other: Any) -> Any: ... -_SupportsComparison = _SupportsDunderLE | _SupportsDunderGE | _SupportsDunderGT | _SupportsDunderLT +_SupportsComparison: TypeAlias = _SupportsDunderLE | _SupportsDunderGE | _SupportsDunderGT | _SupportsDunderLT class _SupportsInversion(Protocol[_T_co]): def __invert__(self) -> _T_co: ... diff --git a/stdlib/_random.pyi b/stdlib/_random.pyi index 9aff4b3cb..c4b235f0c 100644 --- a/stdlib/_random.pyi +++ b/stdlib/_random.pyi @@ -1,5 +1,7 @@ +from typing_extensions import TypeAlias + # Actually Tuple[(int,) * 625] -_State = tuple[int, ...] +_State: TypeAlias = tuple[int, ...] class Random: def __init__(self, seed: object = ...) -> None: ... diff --git a/stdlib/_socket.pyi b/stdlib/_socket.pyi index a8cf16823..78323a60f 100644 --- a/stdlib/_socket.pyi +++ b/stdlib/_socket.pyi @@ -2,20 +2,21 @@ import sys from _typeshed import ReadableBuffer, WriteableBuffer from collections.abc import Iterable from typing import Any, SupportsInt, overload +from typing_extensions import TypeAlias if sys.version_info >= (3, 8): from typing import SupportsIndex - _FD = SupportsIndex + _FD: TypeAlias = SupportsIndex else: - _FD = SupportsInt + _FD: TypeAlias = SupportsInt -_CMSG = tuple[int, int, bytes] -_CMSGArg = tuple[int, int, ReadableBuffer] +_CMSG: TypeAlias = tuple[int, int, bytes] +_CMSGArg: TypeAlias = tuple[int, int, ReadableBuffer] # Addresses can be either tuples of varying lengths (AF_INET, AF_INET6, # AF_NETLINK, AF_TIPC) or strings (AF_UNIX). -_Address = tuple[Any, ...] | str +_Address: TypeAlias = tuple[Any, ...] | str _RetAddress = Any # TODO Most methods allow bytes as address objects diff --git a/stdlib/_threading_local.pyi b/stdlib/_threading_local.pyi index 2ad77a177..04030038e 100644 --- a/stdlib/_threading_local.pyi +++ b/stdlib/_threading_local.pyi @@ -1,8 +1,9 @@ from typing import Any +from typing_extensions import TypeAlias from weakref import ReferenceType __all__ = ["local"] -localdict = dict[Any, Any] +localdict: TypeAlias = dict[Any, Any] class _localimpl: key: str diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index b348a3295..a7f58e29f 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -99,7 +99,7 @@ StrPath: TypeAlias = str | PathLike[str] # stable BytesPath: TypeAlias = bytes | PathLike[bytes] # stable StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes] # stable -OpenTextModeUpdating = Literal[ +OpenTextModeUpdating: TypeAlias = Literal[ "r+", "+r", "rt+", diff --git a/stdlib/aifc.pyi b/stdlib/aifc.pyi index db3d8d991..14e824f3d 100644 --- a/stdlib/aifc.pyi +++ b/stdlib/aifc.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Self from types import TracebackType from typing import IO, Any, NamedTuple, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 9): __all__ = ["Error", "open"] @@ -19,8 +19,8 @@ class _aifc_params(NamedTuple): comptype: bytes compname: bytes -_File = str | IO[bytes] -_Marker = tuple[int, int, bytes] +_File: TypeAlias = str | IO[bytes] +_Marker: TypeAlias = tuple[int, int, bytes] class Aifc_read: def __init__(self, f: _File) -> None: ... diff --git a/stdlib/array.pyi b/stdlib/array.pyi index 69b4d35d9..b3d1a5a85 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -1,12 +1,12 @@ import sys from _typeshed import Self from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, TypeVar, overload -from typing_extensions import Literal, SupportsIndex +from typing_extensions import Literal, SupportsIndex, TypeAlias -_IntTypeCode = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] -_FloatTypeCode = Literal["f", "d"] -_UnicodeTypeCode = Literal["u"] -_TypeCode = _IntTypeCode | _FloatTypeCode | _UnicodeTypeCode +_IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] +_FloatTypeCode: TypeAlias = Literal["f", "d"] +_UnicodeTypeCode: TypeAlias = Literal["u"] +_TypeCode: TypeAlias = _IntTypeCode | _FloatTypeCode | _UnicodeTypeCode _T = TypeVar("_T", int, float, str) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 71e4487ba..9eda1ad19 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -9,7 +9,7 @@ from asyncio.transports import BaseTransport, ReadTransport, SubprocessTransport from collections.abc import Iterable from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Awaitable, Callable, Coroutine, Generator, Sequence, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 7): from contextvars import Context @@ -23,10 +23,10 @@ else: _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) -_Context = dict[str, Any] -_ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] -_ProtocolFactory = Callable[[], BaseProtocol] -_SSLContext = bool | None | ssl.SSLContext +_Context: TypeAlias = dict[str, Any] +_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any] +_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol] +_SSLContext: TypeAlias = bool | None | ssl.SSLContext class Server(AbstractServer): if sys.version_info >= (3, 7): diff --git a/stdlib/asyncio/base_subprocess.pyi b/stdlib/asyncio/base_subprocess.pyi index 21c56bde1..e0eaffcaf 100644 --- a/stdlib/asyncio/base_subprocess.pyi +++ b/stdlib/asyncio/base_subprocess.pyi @@ -1,10 +1,11 @@ import subprocess from collections import deque from typing import IO, Any, Callable, Sequence +from typing_extensions import TypeAlias from . import events, futures, protocols, transports -_File = int | IO[Any] | None +_File: TypeAlias = int | IO[Any] | None class BaseSubprocessTransport(transports.SubprocessTransport): diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index cc0391f92..10dbad98e 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -4,7 +4,7 @@ from _typeshed import FileDescriptorLike, Self from abc import ABCMeta, abstractmethod from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Awaitable, Callable, Coroutine, Generator, Sequence, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .base_events import Server from .futures import Future @@ -75,10 +75,10 @@ else: _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) -_Context = dict[str, Any] -_ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] -_ProtocolFactory = Callable[[], BaseProtocol] -_SSLContext = bool | None | ssl.SSLContext +_Context: TypeAlias = dict[str, Any] +_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any] +_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol] +_SSLContext: TypeAlias = bool | None | ssl.SSLContext class Handle: _cancelled: bool diff --git a/stdlib/asyncio/format_helpers.pyi b/stdlib/asyncio/format_helpers.pyi index 5e483a578..63d8c55f4 100644 --- a/stdlib/asyncio/format_helpers.pyi +++ b/stdlib/asyncio/format_helpers.pyi @@ -2,11 +2,12 @@ import functools import traceback from types import FrameType, FunctionType from typing import Any, Iterable, overload +from typing_extensions import TypeAlias class _HasWrapper: __wrapper__: _HasWrapper | FunctionType -_FuncType = FunctionType | _HasWrapper | functools.partial[Any] | functools.partialmethod[Any] +_FuncType: TypeAlias = FunctionType | _HasWrapper | functools.partial[Any] | functools.partialmethod[Any] @overload def _get_function_source(func: _FuncType) -> tuple[str, int]: ... diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 666862cc7..55bd7dbdb 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -1,6 +1,7 @@ import sys from _typeshed import Self, StrPath from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, Sequence +from typing_extensions import TypeAlias from . import events, protocols, transports from .base_events import Server @@ -64,7 +65,7 @@ else: "start_unix_server", ] -_ClientConnectedCallback = Callable[[StreamReader, StreamWriter], Awaitable[None] | None] +_ClientConnectedCallback: TypeAlias = Callable[[StreamReader, StreamWriter], Awaitable[None] | None] if sys.version_info < (3, 8): class IncompleteReadError(EOFError): diff --git a/stdlib/asyncio/subprocess.pyi b/stdlib/asyncio/subprocess.pyi index 3a617d6fb..7129309de 100644 --- a/stdlib/asyncio/subprocess.pyi +++ b/stdlib/asyncio/subprocess.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import StrOrBytesPath from asyncio import events, protocols, streams, transports from typing import IO, Any, Callable -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 7): __all__ = ("create_subprocess_exec", "create_subprocess_shell") @@ -11,9 +11,9 @@ else: __all__ = ["create_subprocess_exec", "create_subprocess_shell"] if sys.version_info >= (3, 8): - _ExecArg = StrOrBytesPath + _ExecArg: TypeAlias = StrOrBytesPath else: - _ExecArg = str | bytes + _ExecArg: TypeAlias = str | bytes PIPE: int STDOUT: int diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index 885688065..e430f9647 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -3,7 +3,7 @@ import sys from collections.abc import Awaitable, Generator, Iterable, Iterator from types import FrameType from typing import Any, Coroutine, Generic, TextIO, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .events import AbstractEventLoop from .futures import Future @@ -56,8 +56,8 @@ _T3 = TypeVar("_T3") _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") _FT = TypeVar("_FT", bound=Future[Any]) -_FutureT = Future[_T] | Generator[Any, None, _T] | Awaitable[_T] -_TaskYieldType = Future[object] | None +_FutureT: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T] +_TaskYieldType: TypeAlias = Future[object] | None FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION diff --git a/stdlib/asyncio/trsock.pyi b/stdlib/asyncio/trsock.pyi index 3fe1e19d1..d9bf3183b 100644 --- a/stdlib/asyncio/trsock.pyi +++ b/stdlib/asyncio/trsock.pyi @@ -3,12 +3,13 @@ import sys from builtins import type as Type # alias to avoid name clashes with property named "type" from types import TracebackType from typing import Any, BinaryIO, Iterable, NoReturn, overload +from typing_extensions import TypeAlias # These are based in socket, maybe move them out into _typeshed.pyi or such -_Address = tuple[Any, ...] | str -_RetAddress = Any -_WriteBuffer = bytearray | memoryview -_CMSG = tuple[int, int, bytes] +_Address: TypeAlias = tuple[Any, ...] | str +_RetAddress: TypeAlias = Any +_WriteBuffer: TypeAlias = bytearray | memoryview +_CMSG: TypeAlias = tuple[int, int, bytes] class TransportSocket: def __init__(self, sock: socket.socket) -> None: ... diff --git a/stdlib/asyncore.pyi b/stdlib/asyncore.pyi index 8f77e0e45..a4a774282 100644 --- a/stdlib/asyncore.pyi +++ b/stdlib/asyncore.pyi @@ -2,10 +2,11 @@ import sys from _typeshed import FileDescriptorLike from socket import socket from typing import Any, overload +from typing_extensions import TypeAlias # cyclic dependence with asynchat -_maptype = dict[int, Any] -_socket = socket +_maptype: TypeAlias = dict[int, Any] +_socket: TypeAlias = socket socket_map: _maptype # undocumented diff --git a/stdlib/audioop.pyi b/stdlib/audioop.pyi index b08731b85..9df7b22a7 100644 --- a/stdlib/audioop.pyi +++ b/stdlib/audioop.pyi @@ -1,5 +1,7 @@ -AdpcmState = tuple[int, int] -RatecvState = tuple[int, tuple[tuple[int, int], ...]] +from typing_extensions import TypeAlias + +AdpcmState: TypeAlias = tuple[int, int] +RatecvState: TypeAlias = tuple[int, tuple[tuple[int, int], ...]] class error(Exception): ... diff --git a/stdlib/bdb.pyi b/stdlib/bdb.pyi index 8f61433e0..c11988a6f 100644 --- a/stdlib/bdb.pyi +++ b/stdlib/bdb.pyi @@ -1,13 +1,13 @@ from types import CodeType, FrameType, TracebackType from typing import IO, Any, Callable, Iterable, Mapping, SupportsInt, TypeVar -from typing_extensions import Literal, ParamSpec +from typing_extensions import Literal, ParamSpec, TypeAlias __all__ = ["BdbQuit", "Bdb", "Breakpoint"] _T = TypeVar("_T") _P = ParamSpec("_P") -_TraceDispatch = Callable[[FrameType, str, Any], Any] # TODO: Recursive type -_ExcInfo = tuple[type[BaseException], BaseException, FrameType] +_TraceDispatch: TypeAlias = Callable[[FrameType, str, Any], Any] # TODO: Recursive type +_ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, FrameType] GENERATOR_AND_COROUTINE_FLAGS: Literal[672] diff --git a/stdlib/binhex.pyi b/stdlib/binhex.pyi index db002503c..27aa379f1 100644 --- a/stdlib/binhex.pyi +++ b/stdlib/binhex.pyi @@ -1,5 +1,5 @@ from typing import IO, Any -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = ["binhex", "hexbin", "Error"] @@ -15,8 +15,8 @@ class FInfo: Creator: str Flags: int -_FileInfoTuple = tuple[str, FInfo, int, int] -_FileHandleUnion = str | IO[bytes] +_FileInfoTuple: TypeAlias = tuple[str, FInfo, int, int] +_FileHandleUnion: TypeAlias = str | IO[bytes] def getfileinfo(name: str) -> _FileInfoTuple: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 9c5dfcfef..db9bfdfb1 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -54,7 +54,7 @@ from typing import ( TypeVar, overload, ) -from typing_extensions import Literal, SupportsIndex, TypeGuard, final +from typing_extensions import Literal, SupportsIndex, TypeAlias, TypeGuard, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -194,8 +194,8 @@ class super: @overload def __init__(self) -> None: ... -_PositiveInteger = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] -_NegativeInteger = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20] +_PositiveInteger: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] +_NegativeInteger: TypeAlias = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20] class int: @overload @@ -1263,7 +1263,7 @@ def next(__i: SupportsNext[_T], __default: _VT) -> _T | _VT: ... def oct(__number: int | SupportsIndex) -> str: ... _OpenFile = StrOrBytesPath | int -_Opener = Callable[[str, int], int] +_Opener: TypeAlias = Callable[[str, int], int] # Text mode: always returns a TextIOWrapper @overload diff --git a/stdlib/bz2.pyi b/stdlib/bz2.pyi index f1467acad..a17f9c434 100644 --- a/stdlib/bz2.pyi +++ b/stdlib/bz2.pyi @@ -3,7 +3,7 @@ import sys from _compression import BaseStream from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer from typing import IO, Any, Iterable, Protocol, TextIO, overload -from typing_extensions import Literal, SupportsIndex, final +from typing_extensions import Literal, SupportsIndex, TypeAlias, final __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", "open", "compress", "decompress"] @@ -21,10 +21,10 @@ class _WritableFileobj(Protocol): def compress(data: bytes, compresslevel: int = ...) -> bytes: ... def decompress(data: bytes) -> bytes: ... -_ReadBinaryMode = Literal["", "r", "rb"] -_WriteBinaryMode = Literal["w", "wb", "x", "xb", "a", "ab"] -_ReadTextMode = Literal["rt"] -_WriteTextMode = Literal["wt", "xt", "at"] +_ReadBinaryMode: TypeAlias = Literal["", "r", "rb"] +_WriteBinaryMode: TypeAlias = Literal["w", "wb", "x", "xb", "a", "ab"] +_ReadTextMode: TypeAlias = Literal["rt"] +_WriteTextMode: TypeAlias = Literal["wt", "xt", "at"] @overload def open( diff --git a/stdlib/cProfile.pyi b/stdlib/cProfile.pyi index 6f15e461e..7ee7d1bdd 100644 --- a/stdlib/cProfile.pyi +++ b/stdlib/cProfile.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Self, StrOrBytesPath from types import CodeType from typing import Any, Callable, TypeVar -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, TypeAlias __all__ = ["run", "runctx", "Profile"] @@ -13,7 +13,7 @@ def runctx( _T = TypeVar("_T") _P = ParamSpec("_P") -_Label = tuple[str, int, str] +_Label: TypeAlias = tuple[str, int, str] class Profile: stats: dict[_Label, tuple[int, int, int, int, dict[_Label, tuple[int, int, int, int]]]] # undocumented diff --git a/stdlib/calendar.pyi b/stdlib/calendar.pyi index f106eb121..c7e0a6b46 100644 --- a/stdlib/calendar.pyi +++ b/stdlib/calendar.pyi @@ -2,7 +2,7 @@ import datetime import sys from collections.abc import Iterable, Sequence from time import struct_time -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 10): __all__ = [ @@ -66,7 +66,7 @@ else: "weekheader", ] -_LocaleType = tuple[str | None, str | None] +_LocaleType: TypeAlias = tuple[str | None, str | None] class IllegalMonthError(ValueError): def __init__(self, month: int) -> None: ... diff --git a/stdlib/cgitb.pyi b/stdlib/cgitb.pyi index 2db108ce7..974be9fc0 100644 --- a/stdlib/cgitb.pyi +++ b/stdlib/cgitb.pyi @@ -1,8 +1,9 @@ from _typeshed import StrOrBytesPath from types import FrameType, TracebackType from typing import IO, Any, Callable +from typing_extensions import TypeAlias -_ExcInfo = tuple[type[BaseException] | None, BaseException | None, TracebackType | None] +_ExcInfo: TypeAlias = tuple[type[BaseException] | None, BaseException | None, TracebackType | None] __UNDEF__: object # undocumented sentinel diff --git a/stdlib/cmath.pyi b/stdlib/cmath.pyi index ee51861fd..30ada5d5b 100644 --- a/stdlib/cmath.pyi +++ b/stdlib/cmath.pyi @@ -1,5 +1,6 @@ import sys from typing import SupportsComplex, SupportsFloat +from typing_extensions import TypeAlias if sys.version_info >= (3, 8): from typing import SupportsIndex @@ -13,9 +14,9 @@ nanj: complex tau: float if sys.version_info >= (3, 8): - _C = SupportsFloat | SupportsComplex | SupportsIndex | complex + _C: TypeAlias = SupportsFloat | SupportsComplex | SupportsIndex | complex else: - _C = SupportsFloat | SupportsComplex | complex + _C: TypeAlias = SupportsFloat | SupportsComplex | complex def acos(__z: _C) -> complex: ... def acosh(__z: _C) -> complex: ... diff --git a/stdlib/codecs.pyi b/stdlib/codecs.pyi index 8fa93961d..da9c3766b 100644 --- a/stdlib/codecs.pyi +++ b/stdlib/codecs.pyi @@ -3,7 +3,7 @@ import types from _typeshed import Self from abc import abstractmethod from typing import IO, Any, BinaryIO, Callable, Generator, Iterable, Iterator, Protocol, TextIO, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = [ "register", @@ -83,7 +83,7 @@ class _IncrementalDecoder(Protocol): # The type ignore on `encode` and `decode` is to avoid issues with overlapping overloads, for more details, see #300 # https://docs.python.org/3/library/codecs.html#binary-transforms -_BytesToBytesEncoding = Literal[ +_BytesToBytesEncoding: TypeAlias = Literal[ "base64", "base_64", "base64_codec", @@ -102,7 +102,7 @@ _BytesToBytesEncoding = Literal[ "zlib_codec", ] # https://docs.python.org/3/library/codecs.html#text-transforms -_StrToStrEncoding = Literal["rot13", "rot_13"] +_StrToStrEncoding: TypeAlias = Literal["rot13", "rot_13"] @overload def encode(obj: bytes, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ... diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index 55df2ce58..c560b89c5 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import StrOrBytesPath, StrPath, SupportsWrite from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence from typing import Any, ClassVar, Pattern, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = [ "NoSectionError", @@ -29,10 +29,10 @@ __all__ = [ ] # Internal type aliases -_section = Mapping[str, str] -_parser = MutableMapping[str, _section] -_converter = Callable[[str], Any] -_converters = dict[str, _converter] +_section: TypeAlias = Mapping[str, str] +_parser: TypeAlias = MutableMapping[str, _section] +_converter: TypeAlias = Callable[[str], Any] +_converters: TypeAlias = dict[str, _converter] _T = TypeVar("_T") if sys.version_info >= (3, 7): diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index a60f8811e..2b2c6b55d 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -16,7 +16,7 @@ from typing import ( # noqa: Y027 TypeVar, overload, ) -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, TypeAlias if sys.version_info >= (3, 11): __all__ = [ @@ -90,7 +90,7 @@ _T_io = TypeVar("_T_io", bound=IO[str] | None) _F = TypeVar("_F", bound=Callable[..., Any]) _P = ParamSpec("_P") -_ExitFunc = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], bool | None] +_ExitFunc: TypeAlias = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], bool | None] _CM_EF = TypeVar("_CM_EF", AbstractContextManager[Any], _ExitFunc) class ContextDecorator: @@ -189,7 +189,7 @@ class ExitStack(AbstractContextManager[ExitStack]): ) -> bool: ... if sys.version_info >= (3, 7): - _ExitCoroFunc = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], Awaitable[bool]] + _ExitCoroFunc: TypeAlias = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], Awaitable[bool]] _ACM_EF = TypeVar("_ACM_EF", AbstractAsyncContextManager[Any], _ExitCoroFunc) class AsyncExitStack(AbstractAsyncContextManager[AsyncExitStack]): diff --git a/stdlib/copyreg.pyi b/stdlib/copyreg.pyi index 4844a8028..a570b1fe6 100644 --- a/stdlib/copyreg.pyi +++ b/stdlib/copyreg.pyi @@ -1,7 +1,8 @@ from typing import Any, Callable, Hashable, SupportsInt, TypeVar, Union +from typing_extensions import TypeAlias _T = TypeVar("_T") -_Reduce = Union[tuple[Callable[..., _T], tuple[Any, ...]], tuple[Callable[..., _T], tuple[Any, ...], Any | None]] +_Reduce: TypeAlias = Union[tuple[Callable[..., _T], tuple[Any, ...]], tuple[Callable[..., _T], tuple[Any, ...], Any | None]] __all__ = ["pickle", "constructor", "add_extension", "remove_extension", "clear_extension_cache"] @@ -15,5 +16,5 @@ def add_extension(module: Hashable, name: Hashable, code: SupportsInt) -> None: def remove_extension(module: Hashable, name: Hashable, code: int) -> None: ... def clear_extension_cache() -> None: ... -_DispatchTableType = dict[type, Callable[[Any], str | _Reduce[Any]]] # imported by multiprocessing.reduction +_DispatchTableType: TypeAlias = dict[type, Callable[[Any], str | _Reduce[Any]]] # imported by multiprocessing.reduction dispatch_table: _DispatchTableType # undocumented diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 4a03886e8..6df04a024 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -2,6 +2,7 @@ import sys from _typeshed import ReadableBuffer, Self, WriteableBuffer from abc import abstractmethod from typing import Any, Callable, ClassVar, Generic, Iterable, Iterator, Mapping, Sequence, TypeVar, Union as _UnionT, overload +from typing_extensions import TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -84,8 +85,8 @@ class _CData(metaclass=_CDataMeta): class _CanCastTo(_CData): ... class _PointerLike(_CanCastTo): ... -_ECT = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData] -_PF = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]] +_ECT: TypeAlias = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData] +_PF: TypeAlias = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]] class _FuncPointer(_PointerLike, _CData): restype: type[_CData] | Callable[[int], Any] | None @@ -121,12 +122,12 @@ class _CArgObject: ... # Any type that can be implicitly converted to c_void_p when passed as a C function argument. # (bytes is not included here, see below.) -_CVoidPLike = _PointerLike | Array[Any] | _CArgObject | int +_CVoidPLike: TypeAlias = _PointerLike | Array[Any] | _CArgObject | int # Same as above, but including types known to be read-only (i. e. bytes). # This distinction is not strictly necessary (ctypes doesn't differentiate between const # and non-const pointers), but it catches errors like memmove(b'foo', buf, 4) # when memmove(buf, b'foo', 4) was intended. -_CVoidConstPLike = _CVoidPLike | bytes +_CVoidConstPLike: TypeAlias = _CVoidPLike | bytes def addressof(obj: _CData) -> int: ... def alignment(obj_or_type: _CData | type[_CData]) -> int: ... diff --git a/stdlib/ctypes/wintypes.pyi b/stdlib/ctypes/wintypes.pyi index c178a9bdf..9536114b7 100644 --- a/stdlib/ctypes/wintypes.pyi +++ b/stdlib/ctypes/wintypes.pyi @@ -20,6 +20,7 @@ from ctypes import ( c_wchar_p, pointer, ) +from typing_extensions import TypeAlias BYTE = c_byte WORD = c_ushort @@ -182,53 +183,53 @@ class WIN32_FIND_DATAW(Structure): # These pointer type definitions use pointer[...] instead of POINTER(...), to allow them # to be used in type annotations. -PBOOL = pointer[BOOL] -LPBOOL = pointer[BOOL] -PBOOLEAN = pointer[BOOLEAN] -PBYTE = pointer[BYTE] -LPBYTE = pointer[BYTE] -PCHAR = pointer[CHAR] -LPCOLORREF = pointer[COLORREF] -PDWORD = pointer[DWORD] -LPDWORD = pointer[DWORD] -PFILETIME = pointer[FILETIME] -LPFILETIME = pointer[FILETIME] -PFLOAT = pointer[FLOAT] -PHANDLE = pointer[HANDLE] -LPHANDLE = pointer[HANDLE] -PHKEY = pointer[HKEY] -LPHKL = pointer[HKL] -PINT = pointer[INT] -LPINT = pointer[INT] -PLARGE_INTEGER = pointer[LARGE_INTEGER] -PLCID = pointer[LCID] -PLONG = pointer[LONG] -LPLONG = pointer[LONG] -PMSG = pointer[MSG] -LPMSG = pointer[MSG] -PPOINT = pointer[POINT] -LPPOINT = pointer[POINT] -PPOINTL = pointer[POINTL] -PRECT = pointer[RECT] -LPRECT = pointer[RECT] -PRECTL = pointer[RECTL] -LPRECTL = pointer[RECTL] -LPSC_HANDLE = pointer[SC_HANDLE] -PSHORT = pointer[SHORT] -PSIZE = pointer[SIZE] -LPSIZE = pointer[SIZE] -PSIZEL = pointer[SIZEL] -LPSIZEL = pointer[SIZEL] -PSMALL_RECT = pointer[SMALL_RECT] -PUINT = pointer[UINT] -LPUINT = pointer[UINT] -PULARGE_INTEGER = pointer[ULARGE_INTEGER] -PULONG = pointer[ULONG] -PUSHORT = pointer[USHORT] -PWCHAR = pointer[WCHAR] -PWIN32_FIND_DATAA = pointer[WIN32_FIND_DATAA] -LPWIN32_FIND_DATAA = pointer[WIN32_FIND_DATAA] -PWIN32_FIND_DATAW = pointer[WIN32_FIND_DATAW] -LPWIN32_FIND_DATAW = pointer[WIN32_FIND_DATAW] -PWORD = pointer[WORD] -LPWORD = pointer[WORD] +PBOOL: TypeAlias = pointer[BOOL] +LPBOOL: TypeAlias = pointer[BOOL] +PBOOLEAN: TypeAlias = pointer[BOOLEAN] +PBYTE: TypeAlias = pointer[BYTE] +LPBYTE: TypeAlias = pointer[BYTE] +PCHAR: TypeAlias = pointer[CHAR] +LPCOLORREF: TypeAlias = pointer[COLORREF] +PDWORD: TypeAlias = pointer[DWORD] +LPDWORD: TypeAlias = pointer[DWORD] +PFILETIME: TypeAlias = pointer[FILETIME] +LPFILETIME: TypeAlias = pointer[FILETIME] +PFLOAT: TypeAlias = pointer[FLOAT] +PHANDLE: TypeAlias = pointer[HANDLE] +LPHANDLE: TypeAlias = pointer[HANDLE] +PHKEY: TypeAlias = pointer[HKEY] +LPHKL: TypeAlias = pointer[HKL] +PINT: TypeAlias = pointer[INT] +LPINT: TypeAlias = pointer[INT] +PLARGE_INTEGER: TypeAlias = pointer[LARGE_INTEGER] +PLCID: TypeAlias = pointer[LCID] +PLONG: TypeAlias = pointer[LONG] +LPLONG: TypeAlias = pointer[LONG] +PMSG: TypeAlias = pointer[MSG] +LPMSG: TypeAlias = pointer[MSG] +PPOINT: TypeAlias = pointer[POINT] +LPPOINT: TypeAlias = pointer[POINT] +PPOINTL: TypeAlias = pointer[POINTL] +PRECT: TypeAlias = pointer[RECT] +LPRECT: TypeAlias = pointer[RECT] +PRECTL: TypeAlias = pointer[RECTL] +LPRECTL: TypeAlias = pointer[RECTL] +LPSC_HANDLE: TypeAlias = pointer[SC_HANDLE] +PSHORT: TypeAlias = pointer[SHORT] +PSIZE: TypeAlias = pointer[SIZE] +LPSIZE: TypeAlias = pointer[SIZE] +PSIZEL: TypeAlias = pointer[SIZEL] +LPSIZEL: TypeAlias = pointer[SIZEL] +PSMALL_RECT: TypeAlias = pointer[SMALL_RECT] +PUINT: TypeAlias = pointer[UINT] +LPUINT: TypeAlias = pointer[UINT] +PULARGE_INTEGER: TypeAlias = pointer[ULARGE_INTEGER] +PULONG: TypeAlias = pointer[ULONG] +PUSHORT: TypeAlias = pointer[USHORT] +PWCHAR: TypeAlias = pointer[WCHAR] +PWIN32_FIND_DATAA: TypeAlias = pointer[WIN32_FIND_DATAA] +LPWIN32_FIND_DATAA: TypeAlias = pointer[WIN32_FIND_DATAA] +PWIN32_FIND_DATAW: TypeAlias = pointer[WIN32_FIND_DATAW] +LPWIN32_FIND_DATAW: TypeAlias = pointer[WIN32_FIND_DATAW] +PWORD: TypeAlias = pointer[WORD] +LPWORD: TypeAlias = pointer[WORD] diff --git a/stdlib/dbm/__init__.pyi b/stdlib/dbm/__init__.pyi index d43a2415c..b80d0ce75 100644 --- a/stdlib/dbm/__init__.pyi +++ b/stdlib/dbm/__init__.pyi @@ -1,13 +1,13 @@ from _typeshed import Self from types import TracebackType from typing import Iterator, MutableMapping -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = ["open", "whichdb", "error"] -_KeyType = str | bytes -_ValueType = str | bytes -_TFlags = Literal[ +_KeyType: TypeAlias = str | bytes +_ValueType: TypeAlias = str | bytes +_TFlags: TypeAlias = Literal[ "r", "w", "c", diff --git a/stdlib/dbm/dumb.pyi b/stdlib/dbm/dumb.pyi index 5af95ace7..70798f907 100644 --- a/stdlib/dbm/dumb.pyi +++ b/stdlib/dbm/dumb.pyi @@ -1,11 +1,12 @@ from _typeshed import Self from types import TracebackType from typing import Iterator, MutableMapping +from typing_extensions import TypeAlias __all__ = ["error", "open"] -_KeyType = str | bytes -_ValueType = str | bytes +_KeyType: TypeAlias = str | bytes +_ValueType: TypeAlias = str | bytes error = OSError diff --git a/stdlib/dbm/gnu.pyi b/stdlib/dbm/gnu.pyi index 9a603228a..561206c4e 100644 --- a/stdlib/dbm/gnu.pyi +++ b/stdlib/dbm/gnu.pyi @@ -2,11 +2,12 @@ import sys from _typeshed import Self from types import TracebackType from typing import TypeVar, overload +from typing_extensions import TypeAlias if sys.platform != "win32": _T = TypeVar("_T") - _KeyType = str | bytes - _ValueType = str | bytes + _KeyType: TypeAlias = str | bytes + _ValueType: TypeAlias = str | bytes open_flags: str diff --git a/stdlib/dbm/ndbm.pyi b/stdlib/dbm/ndbm.pyi index 8405bec2b..f1032bf3c 100644 --- a/stdlib/dbm/ndbm.pyi +++ b/stdlib/dbm/ndbm.pyi @@ -2,11 +2,12 @@ import sys from _typeshed import Self from types import TracebackType from typing import TypeVar, overload +from typing_extensions import TypeAlias if sys.platform != "win32": _T = TypeVar("_T") - _KeyType = str | bytes - _ValueType = str | bytes + _KeyType: TypeAlias = str | bytes + _ValueType: TypeAlias = str | bytes class error(OSError): ... library: str diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index 819ed1641..c66d9b358 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -3,10 +3,11 @@ import sys from _typeshed import Self from types import TracebackType from typing import Any, Container, NamedTuple, Sequence, Union, overload +from typing_extensions import TypeAlias -_Decimal = Decimal | int -_DecimalNew = Union[Decimal, float, str, tuple[int, Sequence[int], int]] -_ComparableNum = Decimal | float | numbers.Rational +_Decimal: TypeAlias = Decimal | int +_DecimalNew: TypeAlias = Union[Decimal, float, str, tuple[int, Sequence[int], int]] +_ComparableNum: TypeAlias = Decimal | float | numbers.Rational __libmpdec_version__: str @@ -159,7 +160,7 @@ class _ContextManager: def __enter__(self) -> Context: ... def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... -_TrapType = type[DecimalException] +_TrapType: TypeAlias = type[DecimalException] class Context: prec: int diff --git a/stdlib/dis.pyi b/stdlib/dis.pyi index 910458c08..bb5bab919 100644 --- a/stdlib/dis.pyi +++ b/stdlib/dis.pyi @@ -3,6 +3,7 @@ import types from _typeshed import Self from opcode import * # `dis` re-exports it as a part of public API from typing import IO, Any, Callable, Iterator, NamedTuple +from typing_extensions import TypeAlias __all__ = [ "code_info", @@ -34,8 +35,8 @@ __all__ = [ # Strictly this should not have to include Callable, but mypy doesn't use FunctionType # for functions (python/mypy#3171) -_HaveCodeType = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] -_HaveCodeOrStringType = _HaveCodeType | str | bytes +_HaveCodeType: TypeAlias = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] +_HaveCodeOrStringType: TypeAlias = _HaveCodeType | str | bytes class Instruction(NamedTuple): opname: str diff --git a/stdlib/distutils/ccompiler.pyi b/stdlib/distutils/ccompiler.pyi index 4cdc62ce3..89ec0e91d 100644 --- a/stdlib/distutils/ccompiler.pyi +++ b/stdlib/distutils/ccompiler.pyi @@ -1,6 +1,7 @@ from typing import Any, Callable, Union +from typing_extensions import TypeAlias -_Macro = Union[tuple[str], tuple[str, str | None]] +_Macro: TypeAlias = Union[tuple[str], tuple[str, str | None]] def gen_lib_options( compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str] diff --git a/stdlib/distutils/fancy_getopt.pyi b/stdlib/distutils/fancy_getopt.pyi index c2a5bd4c2..d8869d94b 100644 --- a/stdlib/distutils/fancy_getopt.pyi +++ b/stdlib/distutils/fancy_getopt.pyi @@ -1,7 +1,8 @@ from typing import Any, Iterable, Mapping, overload +from typing_extensions import TypeAlias -_Option = tuple[str, str | None, str] -_GR = tuple[list[str], OptionDummy] +_Option: TypeAlias = tuple[str, str | None, str] +_GR: TypeAlias = tuple[list[str], OptionDummy] def fancy_getopt( options: list[_Option], negative_opt: Mapping[_Option, _Option], object: Any, args: list[str] | None diff --git a/stdlib/doctest.pyi b/stdlib/doctest.pyi index 651e1b298..c2679269a 100644 --- a/stdlib/doctest.pyi +++ b/stdlib/doctest.pyi @@ -1,6 +1,7 @@ import types import unittest from typing import Any, Callable, NamedTuple +from typing_extensions import TypeAlias __all__ = [ "register_optionflag", @@ -123,8 +124,8 @@ class DocTestFinder: extraglobs: dict[str, Any] | None = ..., ) -> list[DocTest]: ... -_Out = Callable[[str], Any] -_ExcInfo = tuple[type[BaseException], BaseException, types.TracebackType] +_Out: TypeAlias = Callable[[str], Any] +_ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, types.TracebackType] class DocTestRunner: DIVIDER: str diff --git a/stdlib/email/__init__.pyi b/stdlib/email/__init__.pyi index 49e18ccb8..5eac7bf89 100644 --- a/stdlib/email/__init__.pyi +++ b/stdlib/email/__init__.pyi @@ -1,11 +1,12 @@ from email.message import Message from email.policy import Policy from typing import IO, Callable, TypeVar, Union +from typing_extensions import TypeAlias # Definitions imported by multiple submodules in typeshed _MessageT = TypeVar("_MessageT", bound=Message) # noqa: Y018 -_ParamType = Union[str, tuple[str | None, str | None, str]] -_ParamsType = Union[str, None, tuple[str, str | None, str]] +_ParamType: TypeAlias = Union[str, tuple[str | None, str | None, str]] +_ParamsType: TypeAlias = Union[str, None, tuple[str, str | None, str]] def message_from_string(s: str, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ... def message_from_bytes(s: bytes, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ... diff --git a/stdlib/email/message.pyi b/stdlib/email/message.pyi index 97de1cf5d..d310c21df 100644 --- a/stdlib/email/message.pyi +++ b/stdlib/email/message.pyi @@ -4,13 +4,14 @@ from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy from typing import Any, Generator, Iterator, Sequence, TypeVar +from typing_extensions import TypeAlias __all__ = ["Message", "EmailMessage"] _T = TypeVar("_T") -_PayloadType = list[Message] | str | bytes -_CharsetType = Charset | str | None +_PayloadType: TypeAlias = list[Message] | str | bytes +_CharsetType: TypeAlias = Charset | str | None _HeaderType = Any class Message: diff --git a/stdlib/email/parser.pyi b/stdlib/email/parser.pyi index 1846bdcc3..bd1e48797 100644 --- a/stdlib/email/parser.pyi +++ b/stdlib/email/parser.pyi @@ -3,11 +3,12 @@ from email import _MessageT from email.message import Message from email.policy import Policy from typing import BinaryIO, Callable, TextIO +from typing_extensions import TypeAlias __all__ = ["Parser", "HeaderParser", "BytesParser", "BytesHeaderParser", "FeedParser", "BytesFeedParser"] -FeedParser = email.feedparser.FeedParser[_MessageT] -BytesFeedParser = email.feedparser.BytesFeedParser[_MessageT] +FeedParser: TypeAlias = email.feedparser.FeedParser[_MessageT] +BytesFeedParser: TypeAlias = email.feedparser.BytesFeedParser[_MessageT] class Parser: def __init__(self, _class: Callable[[], Message] | None = ..., *, policy: Policy = ...) -> None: ... diff --git a/stdlib/email/utils.pyi b/stdlib/email/utils.pyi index aeffb0ef1..480c5f795 100644 --- a/stdlib/email/utils.pyi +++ b/stdlib/email/utils.pyi @@ -3,6 +3,7 @@ import sys from email import _ParamType from email.charset import Charset from typing import overload +from typing_extensions import TypeAlias __all__ = [ "collapse_rfc2231_value", @@ -22,7 +23,7 @@ __all__ = [ "unquote", ] -_PDTZ = tuple[int, int, int, int, int, int, int, int, int, int | None] +_PDTZ: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int | None] def quote(str: str) -> str: ... def unquote(str: str) -> str: ... diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index f49bcd7a0..a7c84c5b1 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -5,7 +5,7 @@ from abc import ABCMeta from builtins import property as _builtins_property from collections.abc import Iterable, Iterator, Mapping from typing import Any, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 11): __all__ = [ @@ -52,7 +52,7 @@ _EnumerationT = TypeVar("_EnumerationT", bound=type[Enum]) # # >>> Enum('Foo', names={'RED': 1, 'YELLOW': 2}) # -_EnumNames = str | Iterable[str] | Iterable[Iterable[str | Any]] | Mapping[str, Any] +_EnumNames: TypeAlias = str | Iterable[str] | Iterable[Iterable[str | Any]] | Mapping[str, Any] class _EnumDict(dict[str, Any]): def __init__(self) -> None: ... diff --git a/stdlib/formatter.pyi b/stdlib/formatter.pyi index f5d8348d0..d4f43de31 100644 --- a/stdlib/formatter.pyi +++ b/stdlib/formatter.pyi @@ -1,8 +1,9 @@ from typing import IO, Any, Iterable +from typing_extensions import TypeAlias AS_IS: None -_FontType = tuple[str, bool, bool, bool] -_StylesType = tuple[Any, ...] +_FontType: TypeAlias = tuple[str, bool, bool, bool] +_StylesType: TypeAlias = tuple[Any, ...] class NullFormatter: writer: NullWriter | None diff --git a/stdlib/fractions.pyi b/stdlib/fractions.pyi index 00989fb1f..0d787a011 100644 --- a/stdlib/fractions.pyi +++ b/stdlib/fractions.pyi @@ -3,9 +3,9 @@ from _typeshed import Self from decimal import Decimal from numbers import Integral, Rational, Real from typing import Any, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias -_ComparableNum = int | float | Decimal | Real +_ComparableNum: TypeAlias = int | float | Decimal | Real if sys.version_info >= (3, 9): __all__ = ["Fraction"] diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 741a53ed8..4fd25e634 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -2,7 +2,7 @@ import sys import types from _typeshed import Self, SupportsAllComparisons, SupportsItems from typing import Any, Callable, Generic, Hashable, Iterable, NamedTuple, Sequence, Sized, TypeVar, overload -from typing_extensions import Literal, final +from typing_extensions import Literal, TypeAlias, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -54,7 +54,7 @@ else: "singledispatch", ] -_AnyCallable = Callable[..., Any] +_AnyCallable: TypeAlias = Callable[..., Any] _T = TypeVar("_T") _S = TypeVar("_S") diff --git a/stdlib/gc.pyi b/stdlib/gc.pyi index 7c15e0f5b..9a06e3e4c 100644 --- a/stdlib/gc.pyi +++ b/stdlib/gc.pyi @@ -1,6 +1,6 @@ import sys from typing import Any, Callable -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias DEBUG_COLLECTABLE: Literal[2] DEBUG_LEAK: Literal[38] @@ -8,7 +8,7 @@ DEBUG_SAVEALL: Literal[32] DEBUG_STATS: Literal[1] DEBUG_UNCOLLECTABLE: Literal[4] -_CallbackType = Callable[[Literal["start", "stop"], dict[str, int]], object] +_CallbackType: TypeAlias = Callable[[Literal["start", "stop"], dict[str, int]], object] callbacks: list[_CallbackType] garbage: list[Any] diff --git a/stdlib/gzip.pyi b/stdlib/gzip.pyi index 7347949ae..abf12925a 100644 --- a/stdlib/gzip.pyi +++ b/stdlib/gzip.pyi @@ -4,16 +4,16 @@ import zlib from _typeshed import ReadableBuffer, StrOrBytesPath from io import FileIO from typing import Any, Protocol, TextIO, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 8): __all__ = ["BadGzipFile", "GzipFile", "open", "compress", "decompress"] else: __all__ = ["GzipFile", "open", "compress", "decompress"] -_ReadBinaryMode = Literal["r", "rb"] -_WriteBinaryMode = Literal["a", "ab", "w", "wb", "x", "xb"] -_OpenTextMode = Literal["rt", "at", "wt", "xt"] +_ReadBinaryMode: TypeAlias = Literal["r", "rb"] +_WriteBinaryMode: TypeAlias = Literal["a", "ab", "w", "wb", "x", "xb"] +_OpenTextMode: TypeAlias = Literal["rt", "at", "wt", "xt"] READ: Literal[1] WRITE: Literal[2] diff --git a/stdlib/hmac.pyi b/stdlib/hmac.pyi index 6d355147f..df180f783 100644 --- a/stdlib/hmac.pyi +++ b/stdlib/hmac.pyi @@ -2,10 +2,11 @@ import sys from _typeshed import ReadableBuffer from types import ModuleType from typing import Any, AnyStr, Callable, overload +from typing_extensions import TypeAlias # TODO more precise type for object of hashlib -_Hash = Any -_DigestMod = str | Callable[[], _Hash] | ModuleType +_Hash: TypeAlias = Any +_DigestMod: TypeAlias = str | Callable[[], _Hash] | ModuleType trans_5C: bytes trans_36: bytes diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index 801a195c9..c8090af3e 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -6,6 +6,7 @@ import types from _typeshed import Self, WriteableBuffer from socket import socket from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, Mapping, Protocol, TypeVar, overload +from typing_extensions import TypeAlias __all__ = [ "HTTPResponse", @@ -29,7 +30,7 @@ __all__ = [ "HTTPSConnection", ] -_DataType = bytes | IO[Any] | Iterable[bytes] | str +_DataType: TypeAlias = bytes | IO[Any] | Iterable[bytes] | str _T = TypeVar("_T") HTTP_PORT: int diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index 2cc05961a..774b45e50 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -1,12 +1,13 @@ import sys from typing import Any, Generic, Iterable, Mapping, TypeVar, overload +from typing_extensions import TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias __all__ = ["CookieError", "BaseCookie", "SimpleCookie"] -_DataType = str | Mapping[str, str | Morsel[Any]] +_DataType: TypeAlias = str | Mapping[str, str | Morsel[Any]] _T = TypeVar("_T") @overload diff --git a/stdlib/imaplib.pyi b/stdlib/imaplib.pyi index ab6490cea..32ac465db 100644 --- a/stdlib/imaplib.pyi +++ b/stdlib/imaplib.pyi @@ -5,18 +5,19 @@ from _typeshed import Self from socket import socket as _socket from ssl import SSLContext, SSLSocket from types import TracebackType -from typing import IO, Any, Callable, Pattern -from typing_extensions import Literal +from typing import IO, Any, Callable, Pattern, TypeVar +from typing_extensions import Literal, TypeAlias __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate", "IMAP4_SSL"] # TODO: Commands should use their actual return types, not this type alias. # E.g. Tuple[Literal["OK"], List[bytes]] -_CommandResults = tuple[str, list[Any]] +_CommandResults: TypeAlias = tuple[str, list[Any]] -_AnyResponseData = list[None] | list[bytes | tuple[bytes, bytes]] +_AnyResponseData: TypeAlias = list[None] | list[bytes | tuple[bytes, bytes]] -_list = list # conflicts with a method named "list" +_T = TypeVar("_T") +_list: TypeAlias = list[_T] # conflicts with a method named "list" class IMAP4: error: type[Exception] diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index 877f8ff1a..e020b9e9c 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -13,9 +13,9 @@ from abc import ABCMeta, abstractmethod from importlib.machinery import ModuleSpec from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper from typing import IO, Any, BinaryIO, Iterator, Mapping, NoReturn, Protocol, Sequence, overload, runtime_checkable -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias -_Path = bytes | str +_Path: TypeAlias = bytes | str class Finder(metaclass=ABCMeta): ... diff --git a/stdlib/importlib/resources.pyi b/stdlib/importlib/resources.pyi index e6e3035e5..4ff941733 100644 --- a/stdlib/importlib/resources.pyi +++ b/stdlib/importlib/resources.pyi @@ -4,6 +4,7 @@ from contextlib import AbstractContextManager from pathlib import Path from types import ModuleType from typing import Any, BinaryIO, Iterator, TextIO +from typing_extensions import TypeAlias if sys.version_info >= (3, 10): __all__ = [ @@ -37,8 +38,8 @@ elif sys.version_info >= (3, 9): else: __all__ = ["Package", "Resource", "contents", "is_resource", "open_binary", "open_text", "path", "read_binary", "read_text"] -Package = str | ModuleType -Resource = str | os.PathLike[Any] +Package: TypeAlias = str | ModuleType +Resource: TypeAlias = str | os.PathLike[Any] def open_binary(package: Package, resource: Resource) -> BinaryIO: ... def open_text(package: Package, resource: Resource, encoding: str = ..., errors: str = ...) -> TextIO: ... diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index f87cd0e55..680405ea1 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -19,6 +19,7 @@ from types import ( ModuleType, TracebackType, ) +from typing_extensions import TypeAlias if sys.version_info >= (3, 7): from types import ( @@ -165,8 +166,8 @@ TPFLAGS_IS_ABSTRACT: Literal[1048576] modulesbyfile: dict[str, Any] -_GetMembersPredicate = Callable[[Any], bool] -_GetMembersReturn = list[tuple[str, Any]] +_GetMembersPredicate: TypeAlias = Callable[[Any], bool] +_GetMembersReturn: TypeAlias = list[tuple[str, Any]] def getmembers(object: object, predicate: _GetMembersPredicate | None = ...) -> _GetMembersReturn: ... @@ -242,7 +243,9 @@ def isdatadescriptor(object: object) -> TypeGuard[_SupportsSet[Any, Any] | _Supp # # Retrieving source code # -_SourceObjectType = Union[ModuleType, type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType, Callable[..., Any]] +_SourceObjectType: TypeAlias = Union[ + ModuleType, type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType, Callable[..., Any] +] def findsource(object: _SourceObjectType) -> tuple[list[str], int]: ... def getabsfile(object: _SourceObjectType, _filename: str | None = ...) -> str: ... diff --git a/stdlib/ipaddress.pyi b/stdlib/ipaddress.pyi index d777cef74..c0b3c9674 100644 --- a/stdlib/ipaddress.pyi +++ b/stdlib/ipaddress.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Self from typing import Any, Container, Generic, Iterable, Iterator, SupportsInt, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias # Undocumented length constants IPV4LENGTH: Literal[32] @@ -10,8 +10,8 @@ IPV6LENGTH: Literal[128] _A = TypeVar("_A", IPv4Address, IPv6Address) _N = TypeVar("_N", IPv4Network, IPv6Network) -_RawIPAddress = int | str | bytes | IPv4Address | IPv6Address -_RawNetworkPart = IPv4Network | IPv6Network | IPv4Interface | IPv6Interface +_RawIPAddress: TypeAlias = int | str | bytes | IPv4Address | IPv6Address +_RawNetworkPart: TypeAlias = IPv4Network | IPv6Network | IPv4Interface | IPv6Interface def ip_address(address: _RawIPAddress) -> IPv4Address | IPv6Address: ... def ip_network(address: _RawIPAddress | _RawNetworkPart, strict: bool = ...) -> IPv4Network | IPv6Network: ... diff --git a/stdlib/itertools.pyi b/stdlib/itertools.pyi index bec03b187..520d8ecb2 100644 --- a/stdlib/itertools.pyi +++ b/stdlib/itertools.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Self, _T_co from typing import Any, Callable, Generic, Iterable, Iterator, SupportsComplex, SupportsFloat, SupportsInt, TypeVar, overload -from typing_extensions import Literal, SupportsIndex +from typing_extensions import Literal, SupportsIndex, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -9,9 +9,9 @@ if sys.version_info >= (3, 9): _T = TypeVar("_T") _S = TypeVar("_S") _N = TypeVar("_N", int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex) -_Step = int | float | SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex +_Step: TypeAlias = int | float | SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex -Predicate = Callable[[_T], object] +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 diff --git a/stdlib/lib2to3/pgen2/grammar.pyi b/stdlib/lib2to3/pgen2/grammar.pyi index b5836e1b9..4d298ec69 100644 --- a/stdlib/lib2to3/pgen2/grammar.pyi +++ b/stdlib/lib2to3/pgen2/grammar.pyi @@ -1,8 +1,9 @@ from _typeshed import Self, StrPath +from typing_extensions import TypeAlias -_Label = tuple[int, str | None] -_DFA = list[list[tuple[int, int]]] -_DFAS = tuple[_DFA, dict[int, int]] +_Label: TypeAlias = tuple[int, str | None] +_DFA: TypeAlias = list[list[tuple[int, int]]] +_DFAS: TypeAlias = tuple[_DFA, dict[int, int]] class Grammar: symbol2number: dict[str, int] diff --git a/stdlib/lib2to3/pgen2/parse.pyi b/stdlib/lib2to3/pgen2/parse.pyi index e776ed1e5..a30573c8f 100644 --- a/stdlib/lib2to3/pgen2/parse.pyi +++ b/stdlib/lib2to3/pgen2/parse.pyi @@ -1,8 +1,9 @@ from lib2to3.pgen2.grammar import _DFAS, Grammar from lib2to3.pytree import _NL, _Convert, _RawNode from typing import Any, Sequence +from typing_extensions import TypeAlias -_Context = Sequence[Any] +_Context: TypeAlias = Sequence[Any] class ParseError(Exception): msg: str diff --git a/stdlib/lib2to3/pgen2/tokenize.pyi b/stdlib/lib2to3/pgen2/tokenize.pyi index c1b5a91df..d7e4af446 100644 --- a/stdlib/lib2to3/pgen2/tokenize.pyi +++ b/stdlib/lib2to3/pgen2/tokenize.pyi @@ -1,6 +1,7 @@ import sys from lib2to3.pgen2.token import * from typing import Callable, Iterable, Iterator +from typing_extensions import TypeAlias if sys.version_info >= (3, 8): __all__ = [ @@ -146,9 +147,9 @@ else: "untokenize", ] -_Coord = tuple[int, int] -_TokenEater = Callable[[int, str, _Coord, _Coord, str], None] -_TokenInfo = tuple[int, str, _Coord, _Coord, str] +_Coord: TypeAlias = tuple[int, int] +_TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], None] +_TokenInfo: TypeAlias = tuple[int, str, _Coord, _Coord, str] class TokenError(Exception): ... class StopTokenizing(Exception): ... diff --git a/stdlib/lib2to3/pytree.pyi b/stdlib/lib2to3/pytree.pyi index 68e5d8ba1..62ba2a4b7 100644 --- a/stdlib/lib2to3/pytree.pyi +++ b/stdlib/lib2to3/pytree.pyi @@ -1,12 +1,13 @@ from _typeshed import Self from lib2to3.pgen2.grammar import Grammar from typing import Any, Callable, Iterator +from typing_extensions import TypeAlias -_NL = Node | Leaf -_Context = tuple[str, int, int] -_Results = dict[str, _NL] -_RawNode = tuple[int, str, _Context, list[_NL] | None] -_Convert = Callable[[Grammar, _RawNode], Any] +_NL: TypeAlias = Node | Leaf +_Context: TypeAlias = tuple[str, int, int] +_Results: TypeAlias = dict[str, _NL] +_RawNode: TypeAlias = tuple[int, str, _Context, list[_NL] | None] +_Convert: TypeAlias = Callable[[Grammar, _RawNode], Any] HUGE: int diff --git a/stdlib/linecache.pyi b/stdlib/linecache.pyi index d72d678b5..df54fd80a 100644 --- a/stdlib/linecache.pyi +++ b/stdlib/linecache.pyi @@ -1,13 +1,14 @@ import sys from typing import Any, Protocol +from typing_extensions import TypeAlias if sys.version_info >= (3, 9): __all__ = ["getline", "clearcache", "checkcache", "lazycache"] else: __all__ = ["getline", "clearcache", "checkcache"] -_ModuleGlobals = dict[str, Any] -_ModuleMetadata = tuple[int, float | None, list[str], str] +_ModuleGlobals: TypeAlias = dict[str, Any] +_ModuleMetadata: TypeAlias = tuple[int, float | None, list[str], str] class _SourceLoader(Protocol): def __call__(self) -> str | None: ... diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 8de4d0d88..edb15061a 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -7,7 +7,7 @@ from string import Template from time import struct_time from types import FrameType, TracebackType from typing import Any, ClassVar, Generic, Pattern, TextIO, TypeVar, Union, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = [ "BASIC_FORMAT", @@ -54,12 +54,12 @@ __all__ = [ "raiseExceptions", ] -_SysExcInfoType = Union[tuple[type[BaseException], BaseException, TracebackType | None], tuple[None, None, None]] -_ExcInfoType = None | bool | _SysExcInfoType | BaseException -_ArgsType = tuple[object, ...] | Mapping[str, object] -_FilterType = Filter | Callable[[LogRecord], int] -_Level = int | str -_FormatStyle = Literal["%", "{", "$"] +_SysExcInfoType: TypeAlias = Union[tuple[type[BaseException], BaseException, TracebackType | None], tuple[None, None, None]] +_ExcInfoType: TypeAlias = None | bool | _SysExcInfoType | BaseException +_ArgsType: TypeAlias = tuple[object, ...] | Mapping[str, object] +_FilterType: TypeAlias = Filter | Callable[[LogRecord], int] +_Level: TypeAlias = int | str +_FormatStyle: TypeAlias = Literal["%", "{", "$"] raiseExceptions: bool logThreads: bool diff --git a/stdlib/lzma.pyi b/stdlib/lzma.pyi index 45bf24b3e..3a2df8110 100644 --- a/stdlib/lzma.pyi +++ b/stdlib/lzma.pyi @@ -1,7 +1,7 @@ import io from _typeshed import ReadableBuffer, Self, StrOrBytesPath from typing import IO, Any, Mapping, Sequence, TextIO, overload -from typing_extensions import Literal, final +from typing_extensions import Literal, TypeAlias, final __all__ = [ "CHECK_NONE", @@ -42,12 +42,12 @@ __all__ = [ "is_check_supported", ] -_OpenBinaryWritingMode = Literal["w", "wb", "x", "xb", "a", "ab"] -_OpenTextWritingMode = Literal["wt", "xt", "at"] +_OpenBinaryWritingMode: TypeAlias = Literal["w", "wb", "x", "xb", "a", "ab"] +_OpenTextWritingMode: TypeAlias = Literal["wt", "xt", "at"] -_PathOrFile = StrOrBytesPath | IO[bytes] +_PathOrFile: TypeAlias = StrOrBytesPath | IO[bytes] -_FilterChain = Sequence[Mapping[str, Any]] +_FilterChain: TypeAlias = Sequence[Mapping[str, Any]] FORMAT_AUTO: Literal[0] FORMAT_XZ: Literal[1] diff --git a/stdlib/mailbox.pyi b/stdlib/mailbox.pyi index 143891d32..cf75feefa 100644 --- a/stdlib/mailbox.pyi +++ b/stdlib/mailbox.pyi @@ -4,7 +4,7 @@ from _typeshed import Self, StrOrBytesPath from abc import ABCMeta, abstractmethod from types import TracebackType from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Mapping, Protocol, Sequence, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -31,7 +31,7 @@ __all__ = [ _T = TypeVar("_T") _MessageT = TypeVar("_MessageT", bound=Message) -_MessageData = email.message.Message | bytes | str | IO[str] | IO[bytes] +_MessageData: TypeAlias = email.message.Message | bytes | str | IO[str] | IO[bytes] class _HasIteritems(Protocol): def iteritems(self) -> Iterator[tuple[str, _MessageData]]: ... diff --git a/stdlib/mailcap.pyi b/stdlib/mailcap.pyi index 232ab99c3..4fcb4f077 100644 --- a/stdlib/mailcap.pyi +++ b/stdlib/mailcap.pyi @@ -1,6 +1,7 @@ from typing import Mapping, Sequence +from typing_extensions import TypeAlias -_Cap = dict[str, str | int] +_Cap: TypeAlias = dict[str, str | int] __all__ = ["getcaps", "findmatch"] diff --git a/stdlib/math.pyi b/stdlib/math.pyi index e4ab31199..79dec031d 100644 --- a/stdlib/math.pyi +++ b/stdlib/math.pyi @@ -1,10 +1,10 @@ import sys from _typeshed import SupportsTrunc from typing import Iterable, SupportsFloat, overload -from typing_extensions import SupportsIndex +from typing_extensions import SupportsIndex, TypeAlias if sys.version_info >= (3, 8): - _SupportsFloatOrIndex = SupportsFloat | SupportsIndex + _SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex else: _SupportsFloatOrIndex = SupportsFloat diff --git a/stdlib/msilib/sequence.pyi b/stdlib/msilib/sequence.pyi index 30346aba3..9cc1e0eae 100644 --- a/stdlib/msilib/sequence.pyi +++ b/stdlib/msilib/sequence.pyi @@ -1,8 +1,9 @@ import sys +from typing_extensions import TypeAlias if sys.platform == "win32": - _SequenceType = list[tuple[str, str | None, int]] + _SequenceType: TypeAlias = list[tuple[str, str | None, int]] AdminExecuteSequence: _SequenceType AdminUISequence: _SequenceType diff --git a/stdlib/multiprocessing/__init__.pyi b/stdlib/multiprocessing/__init__.pyi index 3a8a382b8..87ceda105 100644 --- a/stdlib/multiprocessing/__init__.pyi +++ b/stdlib/multiprocessing/__init__.pyi @@ -20,8 +20,8 @@ from multiprocessing.process import active_children as active_children, current_ # multiprocessing.queues or the aliases defined below. See #4266 for discussion. from multiprocessing.queues import JoinableQueue as JoinableQueue, Queue as Queue, SimpleQueue as SimpleQueue from multiprocessing.spawn import freeze_support as freeze_support -from typing import Any, overload -from typing_extensions import Literal +from typing import Any, TypeVar, overload +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 8): from multiprocessing.process import parent_process as parent_process @@ -118,23 +118,24 @@ else: # from multiprocessing import _LockType # lock: _LockType = Lock() -_QueueType = Queue -_SimpleQueueType = SimpleQueue -_JoinableQueueType = JoinableQueue -_BarrierType = synchronize.Barrier -_BoundedSemaphoreType = synchronize.BoundedSemaphore -_ConditionType = synchronize.Condition -_EventType = synchronize.Event -_LockType = synchronize.Lock -_RLockType = synchronize.RLock -_SemaphoreType = synchronize.Semaphore +_T = TypeVar("_T") +_QueueType: TypeAlias = Queue[_T] +_SimpleQueueType: TypeAlias = SimpleQueue[_T] +_JoinableQueueType: TypeAlias = JoinableQueue[_T] +_BarrierType: TypeAlias = synchronize.Barrier +_BoundedSemaphoreType: TypeAlias = synchronize.BoundedSemaphore +_ConditionType: TypeAlias = synchronize.Condition +_EventType: TypeAlias = synchronize.Event +_LockType: TypeAlias = synchronize.Lock +_RLockType: TypeAlias = synchronize.RLock +_SemaphoreType: TypeAlias = synchronize.Semaphore # N.B. The functions below are generated at runtime by partially applying # multiprocessing.context.BaseContext's methods, so the two signatures should # be identical (modulo self). # Synchronization primitives -_LockLike = synchronize.Lock | synchronize.RLock +_LockLike: TypeAlias = synchronize.Lock | synchronize.RLock RawValue = context._default_context.RawValue RawArray = context._default_context.RawArray Value = context._default_context.Value diff --git a/stdlib/multiprocessing/connection.pyi b/stdlib/multiprocessing/connection.pyi index 5db6fa4cd..9b5af6323 100644 --- a/stdlib/multiprocessing/connection.pyi +++ b/stdlib/multiprocessing/connection.pyi @@ -3,12 +3,12 @@ import sys import types from _typeshed import Self from typing import Any, Iterable, Union -from typing_extensions import SupportsIndex +from typing_extensions import SupportsIndex, TypeAlias __all__ = ["Client", "Listener", "Pipe", "wait"] # https://docs.python.org/3/library/multiprocessing.html#address-formats -_Address = Union[str, tuple[str, int]] +_Address: TypeAlias = Union[str, tuple[str, int]] class _ConnectionBase: def __init__(self, handle: SupportsIndex, readable: bool = ..., writable: bool = ...) -> None: ... diff --git a/stdlib/multiprocessing/context.pyi b/stdlib/multiprocessing/context.pyi index 315918a04..d618d1028 100644 --- a/stdlib/multiprocessing/context.pyi +++ b/stdlib/multiprocessing/context.pyi @@ -9,14 +9,14 @@ from multiprocessing.pool import Pool as _Pool from multiprocessing.process import BaseProcess from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase from typing import Any, ClassVar, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 8): __all__ = () else: __all__: list[str] = [] -_LockLike = synchronize.Lock | synchronize.RLock +_LockLike: TypeAlias = synchronize.Lock | synchronize.RLock _CT = TypeVar("_CT", bound=_CData) class ProcessError(Exception): ... diff --git a/stdlib/multiprocessing/dummy/connection.pyi b/stdlib/multiprocessing/dummy/connection.pyi index c61617cd9..fd909d0d3 100644 --- a/stdlib/multiprocessing/dummy/connection.pyi +++ b/stdlib/multiprocessing/dummy/connection.pyi @@ -2,12 +2,13 @@ from _typeshed import Self from queue import Queue from types import TracebackType from typing import Any, Union +from typing_extensions import TypeAlias __all__ = ["Client", "Listener", "Pipe"] families: list[None] -_Address = Union[str, tuple[str, int]] +_Address: TypeAlias = Union[str, tuple[str, int]] class Connection: _in: Any diff --git a/stdlib/multiprocessing/synchronize.pyi b/stdlib/multiprocessing/synchronize.pyi index 0cfc815b2..b96f9429d 100644 --- a/stdlib/multiprocessing/synchronize.pyi +++ b/stdlib/multiprocessing/synchronize.pyi @@ -4,10 +4,11 @@ from contextlib import AbstractContextManager from multiprocessing.context import BaseContext from types import TracebackType from typing import Any, Callable +from typing_extensions import TypeAlias __all__ = ["Lock", "RLock", "Semaphore", "BoundedSemaphore", "Condition", "Event"] -_LockLike = Lock | RLock +_LockLike: TypeAlias = Lock | RLock class Barrier(threading.Barrier): def __init__( diff --git a/stdlib/netrc.pyi b/stdlib/netrc.pyi index 45f6cfbed..803c78073 100644 --- a/stdlib/netrc.pyi +++ b/stdlib/netrc.pyi @@ -1,4 +1,5 @@ from _typeshed import StrOrBytesPath +from typing_extensions import TypeAlias __all__ = ["netrc", "NetrcParseError"] @@ -9,7 +10,7 @@ class NetrcParseError(Exception): def __init__(self, msg: str, filename: StrOrBytesPath | None = ..., lineno: int | None = ...) -> None: ... # (login, account, password) tuple -_NetrcTuple = tuple[str, str | None, str | None] +_NetrcTuple: TypeAlias = tuple[str, str | None, str | None] class netrc: hosts: dict[str, _NetrcTuple] diff --git a/stdlib/nntplib.pyi b/stdlib/nntplib.pyi index cc48cb83a..019475294 100644 --- a/stdlib/nntplib.pyi +++ b/stdlib/nntplib.pyi @@ -4,7 +4,7 @@ import ssl import sys from _typeshed import Self from typing import IO, Any, Iterable, NamedTuple -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = [ "NNTP", @@ -18,7 +18,7 @@ __all__ = [ "NNTP_SSL", ] -_File = IO[bytes] | bytes | str | None +_File: TypeAlias = IO[bytes] | bytes | str | None class NNTPError(Exception): response: str diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 2ef781bbe..2048a80ef 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -35,7 +35,7 @@ from typing import ( overload, runtime_checkable, ) -from typing_extensions import Final, Literal, final +from typing_extensions import Final, Literal, TypeAlias, final from . import path as _path @@ -211,7 +211,7 @@ R_OK: int W_OK: int X_OK: int -_EnvironCodeFunc = Callable[[AnyStr], AnyStr] +_EnvironCodeFunc: TypeAlias = Callable[[AnyStr], AnyStr] class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): encodekey: _EnvironCodeFunc[AnyStr] @@ -383,7 +383,7 @@ def listdir(path: BytesPath) -> list[bytes]: ... @overload def listdir(path: int) -> list[str]: ... -_FdOrAnyPath = int | StrOrBytesPath +_FdOrAnyPath: TypeAlias = int | StrOrBytesPath @final class DirEntry(Generic[AnyStr]): @@ -404,9 +404,9 @@ class DirEntry(Generic[AnyStr]): def __class_getitem__(cls, item: Any) -> GenericAlias: ... if sys.version_info >= (3, 7): - _StatVfsTuple = tuple[int, int, int, int, int, int, int, int, int, int, int] + _StatVfsTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int] else: - _StatVfsTuple = tuple[int, int, int, int, int, int, int, int, int, int] + _StatVfsTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int] @final class statvfs_result(structseq[int], _StatVfsTuple): @@ -527,7 +527,7 @@ def putenv(__name: bytes | str, __value: bytes | str) -> None: ... if sys.platform != "win32" or sys.version_info >= (3, 9): def unsetenv(__name: bytes | str) -> None: ... -_Opener = Callable[[str, int], int] +_Opener: TypeAlias = Callable[[str, int], int] @overload def fdopen( @@ -787,7 +787,7 @@ def utime( follow_symlinks: bool = ..., ) -> None: ... -_OnError = Callable[[OSError], Any] +_OnError: TypeAlias = Callable[[OSError], Any] def walk( top: AnyStr | PathLike[AnyStr], topdown: bool = ..., onerror: _OnError | None = ..., followlinks: bool = ... @@ -845,7 +845,7 @@ def execlpe(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: Any) -> NoRetur # Not separating out PathLike[str] and PathLike[bytes] here because it doesn't make much difference # in practice, and doing so would explode the number of combinations in this already long union. # All these combinations are necessary due to list being invariant. -_ExecVArgs = ( +_ExecVArgs: TypeAlias = ( tuple[StrOrBytesPath, ...] | list[bytes] | list[str] @@ -855,7 +855,7 @@ _ExecVArgs = ( | list[str | PathLike[Any]] | list[bytes | str | PathLike[Any]] ) -_ExecEnv = Mapping[bytes, bytes | str] | Mapping[str, bytes | str] +_ExecEnv: TypeAlias = Mapping[bytes, bytes | str] | Mapping[str, bytes | str] def execv(__path: StrOrBytesPath, __argv: _ExecVArgs) -> NoReturn: ... def execve(path: _FdOrAnyPath, argv: _ExecVArgs, env: _ExecEnv) -> NoReturn: ... diff --git a/stdlib/pickle.pyi b/stdlib/pickle.pyi index 26ee94ca2..8ebbb6222 100644 --- a/stdlib/pickle.pyi +++ b/stdlib/pickle.pyi @@ -1,6 +1,6 @@ import sys from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Protocol, Union -from typing_extensions import final +from typing_extensions import TypeAlias, final if sys.version_info >= (3, 8): __all__ = [ @@ -189,7 +189,7 @@ if sys.version_info >= (3, 8): def __init__(self, buffer: Any) -> None: ... def raw(self) -> memoryview: ... def release(self) -> None: ... - _BufferCallback = Callable[[PickleBuffer], Any] | None + _BufferCallback: TypeAlias = Callable[[PickleBuffer], Any] | None def dump( obj: Any, file: _WritableFileobj, @@ -223,7 +223,7 @@ class PickleError(Exception): ... class PicklingError(PickleError): ... class UnpicklingError(PickleError): ... -_reducedtype = Union[ +_reducedtype: TypeAlias = Union[ str, tuple[Callable[..., Any], tuple[Any, ...]], tuple[Callable[..., Any], tuple[Any, ...], Any], diff --git a/stdlib/pickletools.pyi b/stdlib/pickletools.pyi index 7b79ddcff..9d7dc6f97 100644 --- a/stdlib/pickletools.pyi +++ b/stdlib/pickletools.pyi @@ -1,8 +1,9 @@ from typing import IO, Any, Callable, Iterator, MutableMapping +from typing_extensions import TypeAlias __all__ = ["dis", "genops", "optimize"] -_Reader = Callable[[IO[bytes]], Any] +_Reader: TypeAlias = Callable[[IO[bytes]], Any] bytes_types: tuple[type[Any], ...] UP_TO_NEWLINE: int diff --git a/stdlib/poplib.pyi b/stdlib/poplib.pyi index 6b651e98e..af4c8b3e7 100644 --- a/stdlib/poplib.pyi +++ b/stdlib/poplib.pyi @@ -1,11 +1,11 @@ import socket import ssl from typing import Any, BinaryIO, NoReturn, Pattern, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = ["POP3", "error_proto", "POP3_SSL"] -_LongResp = tuple[bytes, list[bytes], int] +_LongResp: TypeAlias = tuple[bytes, list[bytes], int] class error_proto(Exception): ... diff --git a/stdlib/profile.pyi b/stdlib/profile.pyi index 982bcabad..6b23dff05 100644 --- a/stdlib/profile.pyi +++ b/stdlib/profile.pyi @@ -1,6 +1,6 @@ from _typeshed import Self, StrOrBytesPath from typing import Any, Callable, TypeVar -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, TypeAlias __all__ = ["run", "runctx", "Profile"] @@ -11,7 +11,7 @@ def runctx( _T = TypeVar("_T") _P = ParamSpec("_P") -_Label = tuple[str, int, str] +_Label: TypeAlias = tuple[str, int, str] class Profile: bias: int diff --git a/stdlib/pstats.pyi b/stdlib/pstats.pyi index a7b8bebe4..e8d13cf51 100644 --- a/stdlib/pstats.pyi +++ b/stdlib/pstats.pyi @@ -3,7 +3,7 @@ from _typeshed import Self, StrOrBytesPath from cProfile import Profile as _cProfile from profile import Profile from typing import IO, Any, Iterable, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 9): __all__ = ["Stats", "SortKey", "FunctionProfile", "StatsProfile"] @@ -12,7 +12,7 @@ elif sys.version_info >= (3, 7): else: __all__ = ["Stats"] -_Selector = str | float | int +_Selector: TypeAlias = str | float | int if sys.version_info >= (3, 7): from enum import Enum @@ -45,7 +45,7 @@ if sys.version_info >= (3, 9): total_tt: float func_profiles: dict[str, FunctionProfile] -_SortArgDict = dict[str, tuple[tuple[tuple[int, int], ...], str]] +_SortArgDict: TypeAlias = dict[str, tuple[tuple[tuple[int, int], ...], str]] class Stats: sort_arg_dict_default: _SortArgDict diff --git a/stdlib/pty.pyi b/stdlib/pty.pyi index 73c6ddfbd..02f0bc7e9 100644 --- a/stdlib/pty.pyi +++ b/stdlib/pty.pyi @@ -1,10 +1,10 @@ import sys from typing import Callable, Iterable -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.platform != "win32": __all__ = ["openpty", "fork", "spawn"] - _Reader = Callable[[int], bytes] + _Reader: TypeAlias = Callable[[int], bytes] STDIN_FILENO: Literal[0] STDOUT_FILENO: Literal[1] diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index b4fa66c60..d68cea97f 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -3,11 +3,12 @@ from abc import abstractmethod from reprlib import Repr from types import MethodType, ModuleType, TracebackType from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, TypeVar +from typing_extensions import TypeAlias __all__ = ["help"] # the return type of sys.exc_info(), used by ErrorDuringImport.__init__ -_Exc_Info = tuple[type[BaseException] | None, BaseException | None, TracebackType | None] +_Exc_Info: TypeAlias = tuple[type[BaseException] | None, BaseException | None, TracebackType | None] _T = TypeVar("_T") diff --git a/stdlib/pyexpat/__init__.pyi b/stdlib/pyexpat/__init__.pyi index 24c93965b..f6a5c55cd 100644 --- a/stdlib/pyexpat/__init__.pyi +++ b/stdlib/pyexpat/__init__.pyi @@ -2,7 +2,7 @@ import pyexpat.errors as errors import pyexpat.model as model from _typeshed import SupportsRead from typing import Any, Callable -from typing_extensions import final +from typing_extensions import TypeAlias, final EXPAT_VERSION: str # undocumented version_info: tuple[int, int, int] # undocumented @@ -20,7 +20,7 @@ XML_PARAM_ENTITY_PARSING_NEVER: int XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE: int XML_PARAM_ENTITY_PARSING_ALWAYS: int -_Model = tuple[int, int, str | None, tuple[Any, ...]] +_Model: TypeAlias = tuple[int, int, str | None, tuple[Any, ...]] @final class XMLParserType: diff --git a/stdlib/re.pyi b/stdlib/re.pyi index 57dab8eb8..42c6fbd10 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -3,6 +3,7 @@ import sre_compile import sys from sre_constants import error as error from typing import Any, AnyStr, Callable, Iterator, overload +from typing_extensions import TypeAlias # ----- re variables and constants ----- if sys.version_info >= (3, 7): @@ -147,7 +148,7 @@ T = RegexFlag.T TEMPLATE = RegexFlag.TEMPLATE if sys.version_info >= (3, 11): NOFLAG = RegexFlag.NOFLAG -_FlagsType = int | RegexFlag +_FlagsType: TypeAlias = int | RegexFlag if sys.version_info < (3, 7): # undocumented diff --git a/stdlib/readline.pyi b/stdlib/readline.pyi index df08a3cc2..365caa00a 100644 --- a/stdlib/readline.pyi +++ b/stdlib/readline.pyi @@ -1,10 +1,11 @@ import sys from _typeshed import StrOrBytesPath from typing import Callable, Sequence +from typing_extensions import TypeAlias if sys.platform != "win32": - _Completer = Callable[[str, int], str | None] - _CompDisp = Callable[[str, Sequence[str], int], None] + _Completer: TypeAlias = Callable[[str, int], str | None] + _CompDisp: TypeAlias = Callable[[str, Sequence[str], int], None] def parse_and_bind(__string: str) -> None: ... def read_init_file(__filename: StrOrBytesPath | None = ...) -> None: ... diff --git a/stdlib/reprlib.pyi b/stdlib/reprlib.pyi index 2d114a7c4..bef0ddb53 100644 --- a/stdlib/reprlib.pyi +++ b/stdlib/reprlib.pyi @@ -1,10 +1,11 @@ from array import array from collections import deque from typing import Any, Callable +from typing_extensions import TypeAlias __all__ = ["Repr", "repr", "recursive_repr"] -_ReprFunc = Callable[[Any], str] +_ReprFunc: TypeAlias = Callable[[Any], str] def recursive_repr(fillvalue: str = ...) -> Callable[[_ReprFunc], _ReprFunc]: ... diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index 5fa5f6669..16684ca82 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -2,6 +2,7 @@ import os import sys from _typeshed import BytesPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite from typing import Any, AnyStr, Callable, Iterable, NamedTuple, Sequence, TypeVar, overload +from typing_extensions import TypeAlias __all__ = [ "copyfileobj", @@ -82,7 +83,7 @@ else: def rmtree(path: StrOrBytesPath, ignore_errors: bool = ..., onerror: Callable[[Any, Any, Any], Any] | None = ...) -> None: ... -_CopyFn = Callable[[str, str], None] | Callable[[StrPath, StrPath], None] +_CopyFn: TypeAlias = Callable[[str, str], None] | Callable[[StrPath, StrPath], None] # N.B. shutil.move appears to take bytes arguments, however, # this does not work when dst is (or is within) an existing directory. diff --git a/stdlib/signal.pyi b/stdlib/signal.pyi index 2defe7995..8e45c6a83 100644 --- a/stdlib/signal.pyi +++ b/stdlib/signal.pyi @@ -3,7 +3,7 @@ from _typeshed import structseq from enum import IntEnum from types import FrameType from typing import Any, Callable, Iterable, Union -from typing_extensions import Final, final +from typing_extensions import Final, TypeAlias, final NSIG: int @@ -60,8 +60,8 @@ class Handlers(IntEnum): SIG_DFL: Handlers SIG_IGN: Handlers -_SIGNUM = int | Signals -_HANDLER = Union[Callable[[int, FrameType | None], Any], int, Handlers, None] +_SIGNUM: TypeAlias = int | Signals +_HANDLER: TypeAlias = Union[Callable[[int, FrameType | None], Any], int, Handlers, None] def default_int_handler(__signalnum: int, __frame: FrameType | None) -> None: ... diff --git a/stdlib/smtpd.pyi b/stdlib/smtpd.pyi index 037f62a8d..fc5a1cb62 100644 --- a/stdlib/smtpd.pyi +++ b/stdlib/smtpd.pyi @@ -4,13 +4,14 @@ import socket import sys from collections import defaultdict from typing import Any +from typing_extensions import TypeAlias if sys.version_info >= (3, 11): __all__ = ["SMTPChannel", "SMTPServer", "DebuggingServer", "PureProxy"] else: __all__ = ["SMTPChannel", "SMTPServer", "DebuggingServer", "PureProxy", "MailmanProxy"] -_Address = tuple[str, int] # (host, port) +_Address: TypeAlias = tuple[str, int] # (host, port) class SMTPChannel(asynchat.async_chat): COMMAND: int diff --git a/stdlib/smtplib.pyi b/stdlib/smtplib.pyi index 3136667dc..7967327b1 100644 --- a/stdlib/smtplib.pyi +++ b/stdlib/smtplib.pyi @@ -5,6 +5,7 @@ from socket import socket from ssl import SSLContext from types import TracebackType from typing import Any, Pattern, Protocol, Sequence, overload +from typing_extensions import TypeAlias if sys.version_info >= (3, 7): __all__ = [ @@ -40,10 +41,10 @@ else: "SMTP_SSL", ] -_Reply = tuple[int, bytes] -_SendErrs = dict[str, _Reply] +_Reply: TypeAlias = tuple[int, bytes] +_SendErrs: TypeAlias = dict[str, _Reply] # Should match source_address for socket.create_connection -_SourceAddress = tuple[bytearray | bytes | str, int] +_SourceAddress: TypeAlias = tuple[bytearray | bytes | str, int] SMTP_PORT: int SMTP_SSL_PORT: int diff --git a/stdlib/socketserver.pyi b/stdlib/socketserver.pyi index 9bdd8ccfe..d86e0e4e3 100644 --- a/stdlib/socketserver.pyi +++ b/stdlib/socketserver.pyi @@ -3,6 +3,7 @@ import types from _typeshed import Self from socket import socket as _socket from typing import Any, BinaryIO, Callable, ClassVar, Union +from typing_extensions import TypeAlias if sys.platform == "win32": __all__ = [ @@ -36,8 +37,8 @@ else: "ThreadingUnixDatagramServer", ] -_RequestType = Union[_socket, tuple[bytes, _socket]] -_AddressType = Union[tuple[str, int], str] +_RequestType: TypeAlias = Union[_socket, tuple[bytes, _socket]] +_AddressType: TypeAlias = Union[tuple[str, int], str] # This can possibly be generic at some point: class BaseServer: diff --git a/stdlib/sre_parse.pyi b/stdlib/sre_parse.pyi index 05e71c255..05ac306fa 100644 --- a/stdlib/sre_parse.pyi +++ b/stdlib/sre_parse.pyi @@ -2,6 +2,7 @@ import sys from sre_constants import * from sre_constants import _NamedIntConstant as _NIC, error as _Error from typing import Any, Iterable, Match, Pattern as _Pattern, overload +from typing_extensions import TypeAlias SPECIAL_CHARS: str REPEAT_CHARS: str @@ -33,16 +34,16 @@ class _State: def checklookbehindgroup(self, gid: int, source: Tokenizer) -> None: ... if sys.version_info >= (3, 8): - State = _State + State: TypeAlias = _State else: - Pattern = _State + Pattern: TypeAlias = _State -_OpSubpatternType = tuple[int | None, int, int, SubPattern] -_OpGroupRefExistsType = tuple[int, SubPattern, SubPattern] -_OpInType = list[tuple[_NIC, int]] -_OpBranchType = tuple[None, list[SubPattern]] -_AvType = _OpInType | _OpBranchType | Iterable[SubPattern] | _OpGroupRefExistsType | _OpSubpatternType -_CodeType = tuple[_NIC, _AvType] +_OpSubpatternType: TypeAlias = tuple[int | None, int, int, SubPattern] +_OpGroupRefExistsType: TypeAlias = tuple[int, SubPattern, SubPattern] +_OpInType: TypeAlias = list[tuple[_NIC, int]] +_OpBranchType: TypeAlias = tuple[None, list[SubPattern]] +_AvType: TypeAlias = _OpInType | _OpBranchType | Iterable[SubPattern] | _OpGroupRefExistsType | _OpSubpatternType +_CodeType: TypeAlias = tuple[_NIC, _AvType] class SubPattern: data: list[_CodeType] @@ -87,8 +88,8 @@ class Tokenizer: def fix_flags(src: str | bytes, flags: int) -> int: ... -_TemplateType = tuple[list[tuple[int, int]], list[str | None]] -_TemplateByteType = tuple[list[tuple[int, int]], list[bytes | None]] +_TemplateType: TypeAlias = tuple[list[tuple[int, int]], list[str | None]] +_TemplateByteType: TypeAlias = tuple[list[tuple[int, int]], list[bytes | None]] if sys.version_info >= (3, 8): def parse(str: str, flags: int = ..., state: State | None = ...) -> SubPattern: ... @overload diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index b7fe6914d..3ec3abc0b 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -3,16 +3,16 @@ import socket import sys from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer from typing import Any, Callable, Iterable, NamedTuple, Union, overload -from typing_extensions import Literal, TypedDict, final +from typing_extensions import Literal, TypeAlias, TypedDict, final -_PCTRTT = tuple[tuple[str, str], ...] -_PCTRTTT = tuple[_PCTRTT, ...] -_PeerCertRetDictType = dict[str, str | _PCTRTTT | _PCTRTT] -_PeerCertRetType = _PeerCertRetDictType | bytes | None -_EnumRetType = list[tuple[bytes, str, set[str] | bool]] -_PasswordType = Union[Callable[[], str | bytes], str, bytes] +_PCTRTT: TypeAlias = tuple[tuple[str, str], ...] +_PCTRTTT: TypeAlias = tuple[_PCTRTT, ...] +_PeerCertRetDictType: TypeAlias = dict[str, str | _PCTRTTT | _PCTRTT] +_PeerCertRetType: TypeAlias = _PeerCertRetDictType | bytes | None +_EnumRetType: TypeAlias = list[tuple[bytes, str, set[str] | bool]] +_PasswordType: TypeAlias = Union[Callable[[], str | bytes], str, bytes] -_SrvnmeCbType = Callable[[SSLSocket | SSLObject, str | None, SSLSocket], int | None] +_SrvnmeCbType: TypeAlias = Callable[[SSLSocket | SSLObject, str | None, SSLSocket], int | None] class _Cipher(TypedDict): aead: bool diff --git a/stdlib/statistics.pyi b/stdlib/statistics.pyi index 446a77879..9f31c8f8f 100644 --- a/stdlib/statistics.pyi +++ b/stdlib/statistics.pyi @@ -3,7 +3,7 @@ from _typeshed import Self, SupportsRichComparisonT from decimal import Decimal from fractions import Fraction from typing import Any, Hashable, Iterable, NamedTuple, Sequence, SupportsFloat, TypeVar -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 10): __all__ = [ @@ -65,7 +65,7 @@ else: ] # Most functions in this module accept homogeneous collections of one of these types -_Number = float | Decimal | Fraction +_Number: TypeAlias = float | Decimal | Fraction _NumberT = TypeVar("_NumberT", float, Decimal, Fraction) # Used in mode, multimode diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index ced2e708f..66a3d2d01 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Self, StrOrBytesPath from types import TracebackType from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -102,18 +102,18 @@ else: # reveal_type(x) # bytes, based on the overloads # except TimeoutError as e: # reveal_type(e.cmd) # Any, but morally is _CMD -_FILE = None | int | IO[Any] -_TXT = bytes | str +_FILE: TypeAlias = None | int | IO[Any] +_TXT: TypeAlias = bytes | str if sys.version_info >= (3, 8): - _CMD = StrOrBytesPath | Sequence[StrOrBytesPath] + _CMD: TypeAlias = StrOrBytesPath | Sequence[StrOrBytesPath] else: # Python 3.6 doesn't support _CMD being a single PathLike. # See: https://bugs.python.org/issue31961 - _CMD = _TXT | Sequence[StrOrBytesPath] + _CMD: TypeAlias = _TXT | Sequence[StrOrBytesPath] if sys.platform == "win32": - _ENV = Mapping[str, str] + _ENV: TypeAlias = Mapping[str, str] else: - _ENV = Mapping[bytes, StrOrBytesPath] | Mapping[str, StrOrBytesPath] + _ENV: TypeAlias = Mapping[bytes, StrOrBytesPath] | Mapping[str, StrOrBytesPath] _T = TypeVar("_T") diff --git a/stdlib/sunau.pyi b/stdlib/sunau.pyi index 73aa8999c..5b21cb03d 100644 --- a/stdlib/sunau.pyi +++ b/stdlib/sunau.pyi @@ -1,9 +1,9 @@ import sys from _typeshed import Self from typing import IO, Any, NamedTuple, NoReturn, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias -_File = str | IO[bytes] +_File: TypeAlias = str | IO[bytes] class Error(Exception): ... diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index 4fca35a2c..7facb2fb8 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -6,13 +6,13 @@ from importlib.machinery import ModuleSpec from io import TextIOWrapper from types import FrameType, ModuleType, TracebackType from typing import Any, AsyncGenerator, Callable, Coroutine, NoReturn, Protocol, Sequence, TextIO, TypeVar, Union, overload -from typing_extensions import Literal, final +from typing_extensions import Literal, TypeAlias, final _T = TypeVar("_T") # The following type alias are stub-only and do not exist during runtime -_ExcInfo = tuple[type[BaseException], BaseException, TracebackType] -_OptExcInfo = Union[_ExcInfo, tuple[None, None, None]] +_ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType] +_OptExcInfo: TypeAlias = Union[_ExcInfo, tuple[None, None, None]] # Intentionally omits one deprecated and one optional method of `importlib.abc.MetaPathFinder` class _MetaPathFinder(Protocol): @@ -76,16 +76,16 @@ _xoptions: dict[Any, Any] # Type alias used as a mixin for structseq classes that cannot be instantiated at runtime # This can't be represented in the type system, so we just use `structseq[Any]` -_uninstantiable_structseq = structseq[Any] +_uninstantiable_structseq: TypeAlias = structseq[Any] flags: _flags if sys.version_info >= (3, 10): - _FlagTuple = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, bool, int, int] + _FlagTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, bool, int, int] elif sys.version_info >= (3, 7): - _FlagTuple = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, bool, int] + _FlagTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, bool, int] else: - _FlagTuple = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int] + _FlagTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int] @final class _flags(_uninstantiable_structseq, _FlagTuple): @@ -237,12 +237,12 @@ def getsizeof(obj: object) -> int: ... def getsizeof(obj: object, default: int) -> int: ... def getswitchinterval() -> float: ... -_ProfileFunc = Callable[[FrameType, str, Any], Any] +_ProfileFunc: TypeAlias = Callable[[FrameType, str, Any], Any] def getprofile() -> _ProfileFunc | None: ... def setprofile(profilefunc: _ProfileFunc | None) -> None: ... -_TraceFunc = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None] +_TraceFunc: TypeAlias = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None] def gettrace() -> _TraceFunc | None: ... def settrace(tracefunc: _TraceFunc | None) -> None: ... @@ -309,7 +309,7 @@ if sys.version_info >= (3, 8): def addaudithook(hook: Callable[[str, tuple[Any, ...]], Any]) -> None: ... def audit(__event: str, *args: Any) -> None: ... -_AsyncgenHook = Callable[[AsyncGenerator[Any, Any]], None] | None +_AsyncgenHook: TypeAlias = Callable[[AsyncGenerator[Any, Any]], None] | None @final class _asyncgen_hooks(structseq[_AsyncgenHook], tuple[_AsyncgenHook, _AsyncgenHook]): @@ -330,6 +330,6 @@ if sys.version_info >= (3, 7): def set_coroutine_origin_tracking_depth(depth: int) -> None: ... if sys.version_info < (3, 8): - _CoroWrapper = Callable[[Coroutine[Any, Any, Any]], Any] + _CoroWrapper: TypeAlias = Callable[[Coroutine[Any, Any, Any]], Any] def set_coroutine_wrapper(__wrapper: _CoroWrapper) -> None: ... def get_coroutine_wrapper() -> _CoroWrapper: ... diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index 19a4dbee2..696294f1a 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import Self from types import TracebackType from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -29,7 +29,7 @@ TMP_MAX: int tempdir: str | None template: str -_DirT = AnyStr | os.PathLike[AnyStr] +_DirT: TypeAlias = AnyStr | os.PathLike[AnyStr] if sys.version_info >= (3, 8): @overload diff --git a/stdlib/termios.pyi b/stdlib/termios.pyi index c6a90df31..b2423304b 100644 --- a/stdlib/termios.pyi +++ b/stdlib/termios.pyi @@ -1,9 +1,10 @@ import sys from _typeshed import FileDescriptorLike from typing import Any +from typing_extensions import TypeAlias if sys.platform != "win32": - _Attr = list[int | list[bytes | int]] + _Attr: TypeAlias = list[int | list[bytes | int]] # TODO constants not really documented B0: int diff --git a/stdlib/threading.pyi b/stdlib/threading.pyi index c3fa57faf..ebdfe5a24 100644 --- a/stdlib/threading.pyi +++ b/stdlib/threading.pyi @@ -1,11 +1,12 @@ import sys from types import FrameType, TracebackType from typing import Any, Callable, Iterable, Mapping, TypeVar +from typing_extensions import TypeAlias # TODO recursive type -_TF = Callable[[FrameType, str, Any], Callable[..., Any] | None] +_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None] -_PF = Callable[[FrameType, str, Any], None] +_PF: TypeAlias = Callable[[FrameType, str, Any], None] _T = TypeVar("_T") if sys.version_info >= (3, 10): diff --git a/stdlib/time.pyi b/stdlib/time.pyi index 25f8d7056..cceb7c8ca 100644 --- a/stdlib/time.pyi +++ b/stdlib/time.pyi @@ -1,9 +1,9 @@ import sys from _typeshed import structseq from typing import Any, Protocol -from typing_extensions import Final, Literal, final +from typing_extensions import Final, Literal, TypeAlias, final -_TimeTuple = tuple[int, int, int, int, int, int, int, int, int] +_TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int] altzone: int daylight: int diff --git a/stdlib/timeit.pyi b/stdlib/timeit.pyi index bfaea728f..9c9d13fb3 100644 --- a/stdlib/timeit.pyi +++ b/stdlib/timeit.pyi @@ -1,9 +1,10 @@ from typing import IO, Any, Callable, Sequence +from typing_extensions import TypeAlias __all__ = ["Timer", "timeit", "repeat", "default_timer"] -_Timer = Callable[[], float] -_Stmt = str | Callable[[], Any] +_Timer: TypeAlias = Callable[[], float] +_Stmt: TypeAlias = str | Callable[[], Any] default_timer: _Timer diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 2a6172ba4..6a8737af0 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -6,7 +6,7 @@ from tkinter.constants import * from tkinter.font import _FontDescription from types import TracebackType from typing import Any, Callable, Generic, Mapping, Protocol, Sequence, TypeVar, Union, overload -from typing_extensions import Literal, TypedDict +from typing_extensions import Literal, TypeAlias, TypedDict if sys.version_info >= (3, 9): __all__ = [ @@ -171,29 +171,31 @@ EXCEPTION = _tkinter.EXCEPTION # Some widgets have an option named -compound that accepts different values # than the _Compound defined here. Many other options have similar things. -_Anchor = Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] # manual page: Tk_GetAnchor -_Bitmap = str # manual page: Tk_GetBitmap -_ButtonCommand = str | Callable[[], Any] # accepts string of tcl code, return value is returned from Button.invoke() -_CanvasItemId = int -_Color = str # typically '#rrggbb', '#rgb' or color names. -_Compound = Literal["top", "left", "center", "right", "bottom", "none"] # -compound in manual page named 'options' -_Cursor = Union[str, tuple[str], tuple[str, str], tuple[str, str, str], tuple[str, str, str, str]] # manual page: Tk_GetCursor -_EntryValidateCommand = ( +_Anchor: TypeAlias = Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] # manual page: Tk_GetAnchor +_Bitmap: TypeAlias = str # manual page: Tk_GetBitmap +_ButtonCommand: TypeAlias = str | Callable[[], Any] # accepts string of tcl code, return value is returned from Button.invoke() +_CanvasItemId: TypeAlias = int +_Color: TypeAlias = str # typically '#rrggbb', '#rgb' or color names. +_Compound: TypeAlias = Literal["top", "left", "center", "right", "bottom", "none"] # -compound in manual page named 'options' +_Cursor: TypeAlias = Union[ + str, tuple[str], tuple[str, str], tuple[str, str, str], tuple[str, str, str, str] +] # manual page: Tk_GetCursor +_EntryValidateCommand: TypeAlias = ( str | list[str] | tuple[str, ...] | Callable[[], bool] ) # example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P'] -_GridIndex = int | str | Literal["all"] -_ImageSpec = _Image | str # str can be from e.g. tkinter.image_names() -_Padding = Union[ +_GridIndex: TypeAlias = int | str | Literal["all"] +_ImageSpec: TypeAlias = _Image | str # str can be from e.g. tkinter.image_names() +_Padding: TypeAlias = Union[ _ScreenUnits, tuple[_ScreenUnits], tuple[_ScreenUnits, _ScreenUnits], tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits], tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits], ] -_Relief = Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] # manual page: Tk_GetRelief -_ScreenUnits = str | float # Often the right type instead of int. Manual page: Tk_GetPixels -_XYScrollCommand = str | Callable[[float, float], Any] # -xscrollcommand and -yscrollcommand in 'options' manual page -_TakeFocusValue = Union[int, Literal[""], Callable[[str], bool | None]] # -takefocus in manual page named 'options' +_Relief: TypeAlias = Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] # manual page: Tk_GetRelief +_ScreenUnits: TypeAlias = str | float # Often the right type instead of int. Manual page: Tk_GetPixels +_XYScrollCommand: TypeAlias = str | Callable[[float, float], Any] # -xscrollcommand and -yscrollcommand in 'options' manual page +_TakeFocusValue: TypeAlias = Union[int, Literal[""], Callable[[str], bool | None]] # -takefocus in manual page named 'options' class EventType(str, Enum): Activate: str @@ -263,7 +265,7 @@ class Event(Generic[_W_co]): def NoDefaultRoot() -> None: ... -_TraceMode = Literal["array", "read", "write", "unset"] +_TraceMode: TypeAlias = Literal["array", "read", "write", "unset"] class Variable: def __init__(self, master: Misc | None = ..., value: Any | None = ..., name: str | None = ...) -> None: ... @@ -1696,7 +1698,7 @@ class Checkbutton(Widget): def select(self) -> None: ... def toggle(self) -> None: ... -_EntryIndex = str | int # "INDICES" in manual page +_EntryIndex: TypeAlias = str | int # "INDICES" in manual page class Entry(Widget, XView): def __init__( @@ -2054,7 +2056,7 @@ class Listbox(Widget, XView, YView): def itemconfigure(self, index, cnf: Any | None = ..., **kw): ... itemconfig: Any -_MenuIndex = str | int +_MenuIndex: TypeAlias = str | int class Menu(Widget): def __init__( @@ -2740,7 +2742,7 @@ class Scrollbar(Widget): def get(self) -> tuple[float, float, float, float] | tuple[float, float]: ... def set(self, first: float, last: float) -> None: ... -_TextIndex = _tkinter.Tcl_Obj | str | float | Misc +_TextIndex: TypeAlias = _tkinter.Tcl_Obj | str | float | Misc class Text(Widget, XView, YView): def __init__( diff --git a/stdlib/tkinter/font.pyi b/stdlib/tkinter/font.pyi index 4b0101b32..dff84e9fa 100644 --- a/stdlib/tkinter/font.pyi +++ b/stdlib/tkinter/font.pyi @@ -2,7 +2,7 @@ import _tkinter import sys import tkinter from typing import Any, overload -from typing_extensions import Literal, TypedDict +from typing_extensions import Literal, TypeAlias, TypedDict if sys.version_info >= (3, 9): __all__ = ["NORMAL", "ROMAN", "BOLD", "ITALIC", "nametofont", "Font", "families", "names"] @@ -12,7 +12,7 @@ ROMAN: Literal["roman"] BOLD: Literal["bold"] ITALIC: Literal["italic"] -_FontDescription = ( +_FontDescription: TypeAlias = ( str # "Helvetica 12" | Font # A font object constructed in Python | list[Any] # ("Helvetica", 12, BOLD) diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index c48b5cd7a..cffbb1eb4 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -3,7 +3,7 @@ import sys import tkinter from tkinter.font import _FontDescription from typing import Any, Callable, overload -from typing_extensions import Literal, TypedDict +from typing_extensions import Literal, TypeAlias, TypedDict if sys.version_info >= (3, 7): __all__ = [ @@ -65,7 +65,7 @@ def tclobjs_to_py(adict: dict[Any, Any]) -> dict[Any, Any]: ... def setup_master(master: Any | None = ...): ... # from ttk_widget (aka ttk::widget) manual page, differs from tkinter._Compound -_TtkCompound = Literal["text", "image", tkinter._Compound] +_TtkCompound: TypeAlias = Literal["text", "image", tkinter._Compound] class Style: master: Any @@ -972,7 +972,7 @@ class _TreeviewColumnDict(TypedDict): anchor: tkinter._Anchor id: str -_TreeviewColumnId = int | str # manual page: "COLUMN IDENTIFIERS" +_TreeviewColumnId: TypeAlias = int | str # manual page: "COLUMN IDENTIFIERS" class Treeview(Widget, tkinter.XView, tkinter.YView): def __init__( diff --git a/stdlib/tokenize.pyi b/stdlib/tokenize.pyi index 7b17e8de6..0b4de6186 100644 --- a/stdlib/tokenize.pyi +++ b/stdlib/tokenize.pyi @@ -3,6 +3,7 @@ from _typeshed import StrOrBytesPath from builtins import open as _builtin_open from token import * from typing import Any, Callable, Generator, Iterable, NamedTuple, Pattern, Sequence, TextIO +from typing_extensions import TypeAlias if sys.version_info >= (3, 10): __all__ = [ @@ -317,7 +318,7 @@ if sys.version_info < (3, 7): cookie_re: Pattern[str] blank_re: Pattern[bytes] -_Position = tuple[int, int] +_Position: TypeAlias = tuple[int, int] class _TokenInfo(NamedTuple): type: int @@ -331,7 +332,7 @@ class TokenInfo(_TokenInfo): def exact_type(self) -> int: ... # Backwards compatible tokens can be sequences of a shorter length too -_Token = TokenInfo | Sequence[int | str | _Position] +_Token: TypeAlias = TokenInfo | Sequence[int | str | _Position] class TokenError(Exception): ... class StopTokenizing(Exception): ... # undocumented diff --git a/stdlib/trace.pyi b/stdlib/trace.pyi index 612806447..1415bf7bc 100644 --- a/stdlib/trace.pyi +++ b/stdlib/trace.pyi @@ -2,14 +2,14 @@ import sys import types from _typeshed import StrPath from typing import Any, Callable, Mapping, Sequence, TypeVar -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, TypeAlias __all__ = ["Trace", "CoverageResults"] _T = TypeVar("_T") _P = ParamSpec("_P") -_localtrace = Callable[[types.FrameType, str, Any], Callable[..., Any]] -_fileModuleFunction = tuple[str, str | None, str] +_localtrace: TypeAlias = Callable[[types.FrameType, str, Any], Callable[..., Any]] +_fileModuleFunction: TypeAlias = tuple[str, str | None, str] class CoverageResults: def __init__( diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index 859bfef64..b86182447 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Self, SupportsWrite from types import FrameType, TracebackType from typing import IO, Any, Generator, Iterable, Iterator, Mapping, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = [ "extract_stack", @@ -26,7 +26,7 @@ __all__ = [ "walk_tb", ] -_PT = tuple[str, int, str, str | None] +_PT: TypeAlias = tuple[str, int, str, str | None] def print_tb(tb: TracebackType | None, limit: int | None = ..., file: IO[str] | None = ...) -> None: ... diff --git a/stdlib/tracemalloc.pyi b/stdlib/tracemalloc.pyi index e2e6800cb..9dd03c254 100644 --- a/stdlib/tracemalloc.pyi +++ b/stdlib/tracemalloc.pyi @@ -1,7 +1,7 @@ import sys from _tracemalloc import * from typing import Any, Sequence, Union, overload -from typing_extensions import SupportsIndex +from typing_extensions import SupportsIndex, TypeAlias def get_object_traceback(obj: object) -> Traceback | None: ... def take_snapshot() -> Snapshot: ... @@ -41,7 +41,7 @@ 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 = tuple[str, int] +_FrameTupleT: TypeAlias = tuple[str, int] class Frame: @property @@ -61,9 +61,9 @@ class Frame: def __le__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... if sys.version_info >= (3, 9): - _TraceTupleT = Union[tuple[int, int, Sequence[_FrameTupleT], int | None], tuple[int, int, Sequence[_FrameTupleT]]] + _TraceTupleT: TypeAlias = Union[tuple[int, int, Sequence[_FrameTupleT], int | None], tuple[int, int, Sequence[_FrameTupleT]]] else: - _TraceTupleT = tuple[int, int, Sequence[_FrameTupleT]] + _TraceTupleT: TypeAlias = tuple[int, int, Sequence[_FrameTupleT]] class Trace: @property diff --git a/stdlib/tty.pyi b/stdlib/tty.pyi index 08c93f6f2..8edae9ec2 100644 --- a/stdlib/tty.pyi +++ b/stdlib/tty.pyi @@ -1,10 +1,11 @@ import sys from typing import IO +from typing_extensions import TypeAlias if sys.platform != "win32": __all__ = ["setraw", "setcbreak"] - _FD = int | IO[str] + _FD: TypeAlias = int | IO[str] # XXX: Undocumented integer constants IFLAG: int diff --git a/stdlib/turtle.pyi b/stdlib/turtle.pyi index 2ff965465..3022f67fb 100644 --- a/stdlib/turtle.pyi +++ b/stdlib/turtle.pyi @@ -1,6 +1,7 @@ from _typeshed import Self from tkinter import Canvas, Frame, Misc, PhotoImage, Scrollbar from typing import Any, Callable, ClassVar, Sequence, Union, overload +from typing_extensions import TypeAlias __all__ = [ "ScrolledCanvas", @@ -131,18 +132,18 @@ __all__ = [ # alias we use for return types. Really, these two aliases should be the # same, but as per the "no union returns" typeshed policy, we'll return # Any instead. -_Color = Union[str, tuple[float, float, float]] +_Color: TypeAlias = Union[str, tuple[float, float, float]] _AnyColor = Any # TODO: Replace this with a TypedDict once it becomes standardized. -_PenState = dict[str, Any] +_PenState: TypeAlias = dict[str, Any] -_Speed = str | float -_PolygonCoords = Sequence[tuple[float, float]] +_Speed: TypeAlias = str | float +_PolygonCoords: TypeAlias = Sequence[tuple[float, float]] # TODO: Type this more accurately # Vec2D is actually a custom subclass of 'tuple'. -Vec2D = tuple[float, float] +Vec2D: TypeAlias = tuple[float, float] # Does not actually inherit from Canvas, but dynamically gets all methods of Canvas class ScrolledCanvas(Canvas, Frame): # type: ignore[misc] diff --git a/stdlib/unittest/loader.pyi b/stdlib/unittest/loader.pyi index 8b3c82233..b4ce17064 100644 --- a/stdlib/unittest/loader.pyi +++ b/stdlib/unittest/loader.pyi @@ -4,9 +4,10 @@ import unittest.result import unittest.suite from types import ModuleType from typing import Any, Callable, Pattern, Sequence +from typing_extensions import TypeAlias -_SortComparisonMethod = Callable[[str, str], int] -_SuiteClass = Callable[[list[unittest.case.TestCase]], unittest.suite.TestSuite] +_SortComparisonMethod: TypeAlias = Callable[[str, str], int] +_SuiteClass: TypeAlias = Callable[[list[unittest.case.TestCase]], unittest.suite.TestSuite] VALID_MODULE_NAME: Pattern[str] diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index f5cd4218c..eef114ba6 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -3,7 +3,7 @@ from _typeshed import Self from contextlib import _GeneratorContextManager from types import TracebackType from typing import Any, Awaitable, Callable, Generic, Iterable, Mapping, Sequence, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias _T = TypeVar("_T") _TT = TypeVar("_TT", bound=type[Any]) @@ -77,9 +77,9 @@ class _Sentinel: sentinel: Any DEFAULT: Any -_ArgsKwargs = tuple[tuple[Any, ...], Mapping[str, Any]] -_NameArgsKwargs = tuple[str, tuple[Any, ...], Mapping[str, Any]] -_CallValue = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs | _NameArgsKwargs +_ArgsKwargs: TypeAlias = tuple[tuple[Any, ...], Mapping[str, Any]] +_NameArgsKwargs: TypeAlias = tuple[str, tuple[Any, ...], Mapping[str, Any]] +_CallValue: TypeAlias = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs | _NameArgsKwargs class _Call(tuple[Any, ...]): def __new__( @@ -283,7 +283,7 @@ class _patch_dict: stop: Any if sys.version_info >= (3, 8): - _Mock = MagicMock | AsyncMock + _Mock: TypeAlias = MagicMock | AsyncMock else: _Mock = MagicMock diff --git a/stdlib/unittest/result.pyi b/stdlib/unittest/result.pyi index 1c79f8ab6..54d8704ba 100644 --- a/stdlib/unittest/result.pyi +++ b/stdlib/unittest/result.pyi @@ -1,8 +1,9 @@ import unittest.case from types import TracebackType from typing import Any, Callable, TextIO, TypeVar, Union +from typing_extensions import TypeAlias -_SysExcInfoType = Union[tuple[type[BaseException], BaseException, TracebackType], tuple[None, None, None]] +_SysExcInfoType: TypeAlias = Union[tuple[type[BaseException], BaseException, TracebackType], tuple[None, None, None]] _F = TypeVar("_F", bound=Callable[..., Any]) diff --git a/stdlib/unittest/runner.pyi b/stdlib/unittest/runner.pyi index 479a9f2c3..6d3c7f045 100644 --- a/stdlib/unittest/runner.pyi +++ b/stdlib/unittest/runner.pyi @@ -2,8 +2,9 @@ import unittest.case import unittest.result import unittest.suite from typing import Callable, Iterable, TextIO +from typing_extensions import TypeAlias -_ResultClassType = Callable[[TextIO, bool, int], unittest.result.TestResult] +_ResultClassType: TypeAlias = Callable[[TextIO, bool, int], unittest.result.TestResult] class TextTestResult(unittest.result.TestResult): descriptions: bool # undocumented diff --git a/stdlib/unittest/suite.pyi b/stdlib/unittest/suite.pyi index ca483b06a..f295a4f27 100644 --- a/stdlib/unittest/suite.pyi +++ b/stdlib/unittest/suite.pyi @@ -1,8 +1,9 @@ import unittest.case import unittest.result from typing import Iterable, Iterator +from typing_extensions import TypeAlias -_TestType = unittest.case.TestCase | TestSuite +_TestType: TypeAlias = unittest.case.TestCase | TestSuite class BaseTestSuite(Iterable[_TestType]): _tests: list[unittest.case.TestCase] diff --git a/stdlib/unittest/util.pyi b/stdlib/unittest/util.pyi index 30ab6061b..4a4fdd387 100644 --- a/stdlib/unittest/util.pyi +++ b/stdlib/unittest/util.pyi @@ -1,7 +1,8 @@ from typing import Any, Sequence, TypeVar +from typing_extensions import TypeAlias _T = TypeVar("_T") -_Mismatch = tuple[_T, _T, int] +_Mismatch: TypeAlias = tuple[_T, _T, int] _MAX_LENGTH: int _PLACEHOLDER_LEN: int diff --git a/stdlib/urllib/parse.pyi b/stdlib/urllib/parse.pyi index a45e23dd9..c3348880b 100644 --- a/stdlib/urllib/parse.pyi +++ b/stdlib/urllib/parse.pyi @@ -1,5 +1,6 @@ import sys from typing import Any, AnyStr, Callable, Generic, Mapping, NamedTuple, Sequence, overload +from typing_extensions import TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -28,7 +29,7 @@ __all__ = [ "SplitResultBytes", ] -_Str = bytes | str +_Str: TypeAlias = bytes | str uses_relative: list[str] uses_netloc: list[str] diff --git a/stdlib/urllib/request.pyi b/stdlib/urllib/request.pyi index 265ef2196..ae0dfb1f6 100644 --- a/stdlib/urllib/request.pyi +++ b/stdlib/urllib/request.pyi @@ -5,6 +5,7 @@ from email.message import Message from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar from typing import IO, Any, Callable, ClassVar, Iterable, Mapping, MutableMapping, NoReturn, Pattern, Sequence, TypeVar, overload +from typing_extensions import TypeAlias from urllib.error import HTTPError from urllib.response import addclosehook, addinfourl @@ -46,8 +47,8 @@ __all__ = [ ] _T = TypeVar("_T") -_UrlopenRet = Any -_DataType = bytes | SupportsRead[bytes] | Iterable[bytes] | None +_UrlopenRet: TypeAlias = Any +_DataType: TypeAlias = bytes | SupportsRead[bytes] | Iterable[bytes] | None def urlopen( url: str | Request, diff --git a/stdlib/uu.pyi b/stdlib/uu.pyi index d75df67a1..4ebb12be8 100644 --- a/stdlib/uu.pyi +++ b/stdlib/uu.pyi @@ -1,9 +1,10 @@ import sys from typing import BinaryIO +from typing_extensions import TypeAlias __all__ = ["Error", "encode", "decode"] -_File = str | BinaryIO +_File: TypeAlias = str | BinaryIO class Error(Exception): ... diff --git a/stdlib/uuid.pyi b/stdlib/uuid.pyi index 4d46e89be..fd7f1334e 100644 --- a/stdlib/uuid.pyi +++ b/stdlib/uuid.pyi @@ -1,9 +1,10 @@ import sys +from typing_extensions import TypeAlias # Because UUID has properties called int and bytes we need to rename these temporarily. -_Int = int -_Bytes = bytes -_FieldsType = tuple[int, int, int, int, int, int] +_Int: TypeAlias = int +_Bytes: TypeAlias = bytes +_FieldsType: TypeAlias = tuple[int, int, int, int, int, int] if sys.version_info >= (3, 7): from enum import Enum diff --git a/stdlib/warnings.pyi b/stdlib/warnings.pyi index 1799d69f5..5bb8341b2 100644 --- a/stdlib/warnings.pyi +++ b/stdlib/warnings.pyi @@ -1,7 +1,7 @@ from _warnings import warn as warn, warn_explicit as warn_explicit from types import ModuleType, TracebackType from typing import Any, Sequence, TextIO, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias __all__ = [ "warn", @@ -14,7 +14,7 @@ __all__ = [ "catch_warnings", ] -_ActionKind = Literal["default", "error", "ignore", "always", "module", "once"] +_ActionKind: TypeAlias = Literal["default", "error", "ignore", "always", "module", "once"] filters: Sequence[tuple[str, str | None, type[Warning], str | None, int]] # undocumented, do not mutate diff --git a/stdlib/wave.pyi b/stdlib/wave.pyi index de20c6c4f..689282f69 100644 --- a/stdlib/wave.pyi +++ b/stdlib/wave.pyi @@ -1,14 +1,14 @@ import sys from _typeshed import ReadableBuffer, Self from typing import IO, Any, BinaryIO, NamedTuple, NoReturn, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 9): __all__ = ["open", "Error", "Wave_read", "Wave_write"] else: __all__ = ["open", "openfp", "Error", "Wave_read", "Wave_write"] -_File = str | IO[bytes] +_File: TypeAlias = str | IO[bytes] class Error(Exception): ... diff --git a/stdlib/winreg.pyi b/stdlib/winreg.pyi index 5dc7e4363..2cc42318f 100644 --- a/stdlib/winreg.pyi +++ b/stdlib/winreg.pyi @@ -2,10 +2,10 @@ import sys from _typeshed import Self from types import TracebackType from typing import Any -from typing_extensions import Literal, final +from typing_extensions import Literal, TypeAlias, final if sys.platform == "win32": - _KeyType = HKEYType | int + _KeyType: TypeAlias = HKEYType | int def CloseKey(__hkey: _KeyType) -> None: ... def ConnectRegistry(__computer_name: str | None, __key: _KeyType) -> HKEYType: ... def CreateKey(__key: _KeyType, __sub_key: str | None) -> HKEYType: ... diff --git a/stdlib/wsgiref/handlers.pyi b/stdlib/wsgiref/handlers.pyi index 9e2153788..28a759b58 100644 --- a/stdlib/wsgiref/handlers.pyi +++ b/stdlib/wsgiref/handlers.pyi @@ -1,6 +1,7 @@ from abc import abstractmethod from types import TracebackType from typing import IO, Callable, MutableMapping +from typing_extensions import TypeAlias from .headers import Headers from .types import ErrorStream, InputStream, StartResponse, WSGIApplication, WSGIEnvironment @@ -8,7 +9,7 @@ from .util import FileWrapper __all__ = ["BaseHandler", "SimpleHandler", "BaseCGIHandler", "CGIHandler", "IISCGIHandler", "read_environ"] -_exc_info = tuple[type[BaseException] | None, BaseException | None, TracebackType | None] +_exc_info: TypeAlias = tuple[type[BaseException] | None, BaseException | None, TracebackType | None] def format_date_time(timestamp: float | None) -> str: ... # undocumented def read_environ() -> dict[str, str]: ... diff --git a/stdlib/wsgiref/headers.pyi b/stdlib/wsgiref/headers.pyi index b62124a2a..cde0227a7 100644 --- a/stdlib/wsgiref/headers.pyi +++ b/stdlib/wsgiref/headers.pyi @@ -1,6 +1,7 @@ from typing import Pattern, overload +from typing_extensions import TypeAlias -_HeaderList = list[tuple[str, str]] +_HeaderList: TypeAlias = list[tuple[str, str]] tspecials: Pattern[str] # undocumented diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index b2bec64fd..d228e2de2 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import SupportsRead from typing import Any, Sequence -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from xml.dom.minidom import Document, DOMImplementation, Element, Text from xml.sax.handler import ContentHandler from xml.sax.xmlreader import XMLReader @@ -15,10 +15,10 @@ PROCESSING_INSTRUCTION: Literal["PROCESSING_INSTRUCTION"] IGNORABLE_WHITESPACE: Literal["IGNORABLE_WHITESPACE"] CHARACTERS: Literal["CHARACTERS"] -_DocumentFactory = DOMImplementation | None -_Node = Document | Element | Text +_DocumentFactory: TypeAlias = DOMImplementation | None +_Node: TypeAlias = Document | Element | Text -_Event = tuple[ +_Event: TypeAlias = tuple[ Literal[ Literal["START_ELEMENT"], Literal["END_ELEMENT"], diff --git a/stdlib/xml/dom/xmlbuilder.pyi b/stdlib/xml/dom/xmlbuilder.pyi index ec47ec134..f6afd8aa2 100644 --- a/stdlib/xml/dom/xmlbuilder.pyi +++ b/stdlib/xml/dom/xmlbuilder.pyi @@ -1,5 +1,5 @@ from typing import Any, NoReturn -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from urllib.request import OpenerDirector from xml.dom.expatbuilder import ExpatBuilder, ExpatBuilderNS from xml.dom.minidom import Node @@ -18,13 +18,13 @@ __all__ = ["DOMBuilder", "DOMEntityResolver", "DOMInputSource"] # probably the same as `Options.errorHandler`? # Maybe `xml.sax.handler.ErrorHandler`? -_DOMBuilderErrorHandlerType = Any | None +_DOMBuilderErrorHandlerType: TypeAlias = Any | None # probably some kind of IO... -_DOMInputSourceCharacterStreamType = Any | None +_DOMInputSourceCharacterStreamType: TypeAlias = Any | None # probably a string?? -_DOMInputSourceStringDataType = Any | None +_DOMInputSourceStringDataType: TypeAlias = Any | None # probably a string?? -_DOMInputSourceEncodingType = Any | None +_DOMInputSourceEncodingType: TypeAlias = Any | None class Options: namespaces: int diff --git a/stdlib/xml/etree/ElementPath.pyi b/stdlib/xml/etree/ElementPath.pyi index 5a2dd69c1..796c704b7 100644 --- a/stdlib/xml/etree/ElementPath.pyi +++ b/stdlib/xml/etree/ElementPath.pyi @@ -1,11 +1,12 @@ from typing import Callable, Generator, Pattern, TypeVar +from typing_extensions import TypeAlias from xml.etree.ElementTree import Element xpath_tokenizer_re: Pattern[str] -_token = tuple[str, str] -_next = Callable[[], _token] -_callback = Callable[[_SelectorContext, list[Element]], Generator[Element, None, None]] +_token: TypeAlias = tuple[str, str] +_next: TypeAlias = Callable[[], _token] +_callback: TypeAlias = Callable[[_SelectorContext, list[Element]], Generator[Element, None, None]] def xpath_tokenizer(pattern: str, namespaces: dict[str, str] | None = ...) -> Generator[_token, None, None]: ... def get_parent_map(context: _SelectorContext) -> dict[Element, Element]: ... diff --git a/stdlib/xml/etree/ElementTree.pyi b/stdlib/xml/etree/ElementTree.pyi index 7b50b4279..f9beb4aff 100644 --- a/stdlib/xml/etree/ElementTree.pyi +++ b/stdlib/xml/etree/ElementTree.pyi @@ -14,7 +14,7 @@ from typing import ( TypeVar, overload, ) -from typing_extensions import Literal, SupportsIndex, TypeGuard +from typing_extensions import Literal, SupportsIndex, TypeAlias, TypeGuard if sys.version_info >= (3, 9): __all__ = [ @@ -101,9 +101,9 @@ else: ] _T = TypeVar("_T") -_FileRead = StrOrBytesPath | FileDescriptor | SupportsRead[bytes] | SupportsRead[str] -_FileWriteC14N = StrOrBytesPath | FileDescriptor | SupportsWrite[bytes] -_FileWrite = _FileWriteC14N | SupportsWrite[str] +_FileRead: TypeAlias = StrOrBytesPath | FileDescriptor | SupportsRead[bytes] | SupportsRead[str] +_FileWriteC14N: TypeAlias = StrOrBytesPath | FileDescriptor | SupportsWrite[bytes] +_FileWrite: TypeAlias = _FileWriteC14N | SupportsWrite[str] VERSION: str @@ -352,7 +352,7 @@ def fromstringlist(sequence: Sequence[str | bytes], parser: XMLParser | None = . # TreeBuilder is called by client code (they could pass strs, bytes or whatever); # but we don't want to use a too-broad type, or it would be too hard to write # elementfactories. -_ElementFactory = Callable[[Any, dict[Any, Any]], Element] +_ElementFactory: TypeAlias = Callable[[Any, dict[Any, Any]], Element] class TreeBuilder: if sys.version_info >= (3, 8): diff --git a/stdlib/xmlrpc/client.pyi b/stdlib/xmlrpc/client.pyi index a59be37f9..6929eded7 100644 --- a/stdlib/xmlrpc/client.pyi +++ b/stdlib/xmlrpc/client.pyi @@ -7,17 +7,17 @@ from datetime import datetime from io import BytesIO from types import TracebackType from typing import Any, Callable, Iterable, Mapping, Protocol, Union, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... -_DateTimeComparable = DateTime | datetime | str | _SupportsTimeTuple -_Marshallable = ( +_DateTimeComparable: TypeAlias = DateTime | datetime | str | _SupportsTimeTuple +_Marshallable: TypeAlias = ( bool | int | float | str | bytes | None | tuple[Any, ...] | list[Any] | dict[Any, Any] | datetime | DateTime | Binary ) -_XMLDate = int | datetime | tuple[int, ...] | time.struct_time -_HostType = Union[tuple[str, dict[str, str]], str] +_XMLDate: TypeAlias = int | datetime | tuple[int, ...] | time.struct_time +_HostType: TypeAlias = Union[tuple[str, dict[str, str]], str] def escape(s: str) -> str: ... # undocumented diff --git a/stdlib/xmlrpc/server.pyi b/stdlib/xmlrpc/server.pyi index 2ed0b03c7..fd7010aa5 100644 --- a/stdlib/xmlrpc/server.pyi +++ b/stdlib/xmlrpc/server.pyi @@ -4,10 +4,11 @@ import socketserver import sys from datetime import datetime from typing import Any, Callable, Iterable, Mapping, Pattern, Protocol +from typing_extensions import TypeAlias from xmlrpc.client import Fault # TODO: Recursive type on tuple, list, dict -_Marshallable = None | bool | int | float | str | bytes | tuple[Any, ...] | list[Any] | dict[Any, Any] | datetime +_Marshallable: TypeAlias = None | bool | int | float | str | bytes | tuple[Any, ...] | list[Any] | dict[Any, Any] | datetime # The dispatch accepts anywhere from 0 to N arguments, no easy way to allow this in mypy class _DispatchArity0(Protocol): @@ -30,7 +31,9 @@ class _DispatchArity4(Protocol): class _DispatchArityN(Protocol): def __call__(self, *args: _Marshallable) -> _Marshallable: ... -_DispatchProtocol = _DispatchArity0 | _DispatchArity1 | _DispatchArity2 | _DispatchArity3 | _DispatchArity4 | _DispatchArityN +_DispatchProtocol: TypeAlias = ( + _DispatchArity0 | _DispatchArity1 | _DispatchArity2 | _DispatchArity3 | _DispatchArity4 | _DispatchArityN +) def resolve_dotted_attribute(obj: Any, attr: str, allow_dotted_names: bool = ...) -> Any: ... # undocumented def list_public_methods(obj: Any) -> list[str]: ... # undocumented diff --git a/stdlib/zipapp.pyi b/stdlib/zipapp.pyi index c3cf8321d..f7a1db351 100644 --- a/stdlib/zipapp.pyi +++ b/stdlib/zipapp.pyi @@ -1,10 +1,11 @@ import sys from pathlib import Path from typing import BinaryIO, Callable +from typing_extensions import TypeAlias __all__ = ["ZipAppError", "create_archive", "get_interpreter"] -_Path = str | Path | BinaryIO +_Path: TypeAlias = str | Path | BinaryIO class ZipAppError(ValueError): ... diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index b837528d7..6260b1b50 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -4,7 +4,7 @@ from _typeshed import Self, StrOrBytesPath, StrPath from os import PathLike from types import TracebackType from typing import IO, Any, Callable, Iterable, Iterator, Protocol, Sequence, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 8): __all__ = [ @@ -38,10 +38,10 @@ else: "LargeZipFile", ] -_DateTuple = tuple[int, int, int, int, int, int] -_ReadWriteMode = Literal["r", "w"] -_ReadWriteBinaryMode = Literal["r", "w", "rb", "wb"] -_ZipFileMode = Literal["r", "w", "x", "a"] +_DateTuple: TypeAlias = tuple[int, int, int, int, int, int] +_ReadWriteMode: TypeAlias = Literal["r", "w"] +_ReadWriteBinaryMode: TypeAlias = Literal["r", "w", "rb", "wb"] +_ZipFileMode: TypeAlias = Literal["r", "w", "x", "a"] class BadZipFile(Exception): ... diff --git a/stubs/Deprecated/deprecated/classic.pyi b/stubs/Deprecated/deprecated/classic.pyi index 160968742..a93337a89 100644 --- a/stubs/Deprecated/deprecated/classic.pyi +++ b/stubs/Deprecated/deprecated/classic.pyi @@ -1,8 +1,8 @@ from typing import Any, Callable, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias _F = TypeVar("_F", bound=Callable[..., Any]) -_Actions = Literal["default", "error", "ignore", "always", "module", "once"] +_Actions: TypeAlias = Literal["default", "error", "ignore", "always", "module", "once"] class ClassicAdapter: reason: str diff --git a/stubs/Flask-Cors/flask_cors/core.pyi b/stubs/Flask-Cors/flask_cors/core.pyi index 083a653b1..d649b884c 100644 --- a/stubs/Flask-Cors/flask_cors/core.pyi +++ b/stubs/Flask-Cors/flask_cors/core.pyi @@ -1,13 +1,13 @@ from datetime import timedelta from logging import Logger from typing import Any, Iterable, Pattern, TypeVar, overload -from typing_extensions import TypedDict +from typing_extensions import TypeAlias, TypedDict _IterableT = TypeVar("_IterableT", bound=Iterable[Any]) _T = TypeVar("_T") -_App = Any # flask is not part of typeshed -_Response = Any # flask is not part of typeshed -_MultiDict = Any # werkzeug is not part of typeshed +_App: TypeAlias = Any # flask is not part of typeshed +_Response: TypeAlias = Any # flask is not part of typeshed +_MultiDict: TypeAlias = Any # werkzeug is not part of typeshed class _Options(TypedDict, total=False): resources: dict[str, dict[str, Any]] | list[str] | str | None @@ -35,7 +35,7 @@ ACL_REQUEST_HEADERS: str ALL_METHODS: list[str] CONFIG_OPTIONS: list[str] FLASK_CORS_EVALUATED: str -RegexObject = Pattern[str] +RegexObject: TypeAlias = Pattern[str] DEFAULT_OPTIONS: _Options def parse_resources(resources: dict[str, _Options] | Iterable[str] | str | Pattern[str]) -> list[tuple[str, _Options]]: ... diff --git a/stubs/Pillow/PIL/Image.pyi b/stubs/Pillow/PIL/Image.pyi index 67586efaf..bf6746cd4 100644 --- a/stubs/Pillow/PIL/Image.pyi +++ b/stubs/Pillow/PIL/Image.pyi @@ -2,7 +2,7 @@ from _typeshed import Self, SupportsRead, SupportsWrite from collections.abc import Iterable, Iterator, MutableMapping from pathlib import Path from typing import Any, Callable, ClassVar, Protocol, Sequence, SupportsBytes, Union -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from ._imaging import ( DEFAULT_STRATEGY as DEFAULT_STRATEGY, @@ -14,15 +14,15 @@ from ._imaging import ( from .ImageFilter import Filter from .ImagePalette import ImagePalette -_Mode = Literal["1", "CMYK", "F", "HSV", "I", "L", "LAB", "P", "RGB", "RGBA", "RGBX", "YCbCr"] -_Resample = Literal[0, 1, 2, 3, 4, 5] -_Size = tuple[int, int] -_Box = tuple[int, int, int, int] +_Mode: TypeAlias = Literal["1", "CMYK", "F", "HSV", "I", "L", "LAB", "P", "RGB", "RGBA", "RGBX", "YCbCr"] +_Resample: TypeAlias = Literal[0, 1, 2, 3, 4, 5] +_Size: TypeAlias = tuple[int, int] +_Box: TypeAlias = tuple[int, int, int, int] -_ConversionMatrix = Union[ +_ConversionMatrix: TypeAlias = Union[ tuple[float, float, float, float], tuple[float, float, float, float, float, float, float, float, float, float, float, float], ] -_Color = float | tuple[float, ...] +_Color: TypeAlias = float | tuple[float, ...] class _Writeable(SupportsWrite[bytes], Protocol): def seek(self, __offset: int) -> Any: ... @@ -99,7 +99,7 @@ class _E: def __add__(self, other) -> _E: ... def __mul__(self, other) -> _E: ... -_ImageState = tuple[dict[str, Any], str, tuple[int, int], Any, bytes] +_ImageState: TypeAlias = tuple[dict[str, Any], str, tuple[int, int], Any, bytes] class Image: format: ClassVar[str | None] diff --git a/stubs/Pillow/PIL/ImageColor.pyi b/stubs/Pillow/PIL/ImageColor.pyi index d3debdd94..1815d7004 100644 --- a/stubs/Pillow/PIL/ImageColor.pyi +++ b/stubs/Pillow/PIL/ImageColor.pyi @@ -1,8 +1,9 @@ from typing import Union +from typing_extensions import TypeAlias -_RGB = Union[tuple[int, int, int], tuple[int, int, int, int]] -_Ink = str | int | _RGB -_GreyScale = tuple[int, int] +_RGB: TypeAlias = Union[tuple[int, int, int], tuple[int, int, int, int]] +_Ink: TypeAlias = str | int | _RGB +_GreyScale: TypeAlias = tuple[int, int] def getrgb(color: _Ink) -> _RGB: ... def getcolor(color: _Ink, mode: str) -> _RGB | _GreyScale: ... diff --git a/stubs/Pillow/PIL/ImageDraw.pyi b/stubs/Pillow/PIL/ImageDraw.pyi index dab68e666..6f139926e 100644 --- a/stubs/Pillow/PIL/ImageDraw.pyi +++ b/stubs/Pillow/PIL/ImageDraw.pyi @@ -1,13 +1,13 @@ from collections.abc import Container from typing import Any, Sequence, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .Image import Image from .ImageColor import _Ink from .ImageFont import _Font -_XY = Sequence[float | tuple[float, float]] -_Outline = Any +_XY: TypeAlias = Sequence[float | tuple[float, float]] +_Outline: TypeAlias = Any class ImageDraw: def __init__(self, im: Image, mode: str | None = ...) -> None: ... diff --git a/stubs/Pillow/PIL/ImageFilter.pyi b/stubs/Pillow/PIL/ImageFilter.pyi index 6ec69d53b..a46c06c39 100644 --- a/stubs/Pillow/PIL/ImageFilter.pyi +++ b/stubs/Pillow/PIL/ImageFilter.pyi @@ -1,10 +1,10 @@ from _typeshed import Self from typing import Any, Callable, Iterable, Sequence -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .Image import Image -_FilterArgs = tuple[Sequence[int], int, int, Sequence[int]] +_FilterArgs: TypeAlias = tuple[Sequence[int], int, int, Sequence[int]] # filter image parameters below are the C images, i.e. Image().im. diff --git a/stubs/Pillow/PIL/ImageOps.pyi b/stubs/Pillow/PIL/ImageOps.pyi index 2c84e4dc6..fd178f12c 100644 --- a/stubs/Pillow/PIL/ImageOps.pyi +++ b/stubs/Pillow/PIL/ImageOps.pyi @@ -1,9 +1,10 @@ from typing import Any, Iterable, Protocol, Union +from typing_extensions import TypeAlias from .Image import Image, _Resample, _Size from .ImageColor import _Ink -_Border = Union[int, tuple[int, int], tuple[int, int, int, int]] +_Border: TypeAlias = Union[int, tuple[int, int], tuple[int, int, int, int]] class _Deformer(Protocol): def getmesh(self, image: Image): ... diff --git a/stubs/Pillow/PIL/TiffTags.pyi b/stubs/Pillow/PIL/TiffTags.pyi index 64ede121b..e4582c889 100644 --- a/stubs/Pillow/PIL/TiffTags.pyi +++ b/stubs/Pillow/PIL/TiffTags.pyi @@ -1,5 +1,5 @@ from typing import Any, NamedTuple, Union -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias class _TagInfo(NamedTuple): value: Any @@ -35,8 +35,8 @@ FLOAT: Literal[11] DOUBLE: Literal[12] IFD: Literal[13] -_TagType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] -_TagTuple = Union[tuple[str, _TagType, int], tuple[str, _TagInfo, int, dict[str, int]]] +_TagType: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] +_TagTuple: TypeAlias = Union[tuple[str, _TagType, int], tuple[str, _TagInfo, int, dict[str, int]]] TAGS_V2: dict[int, _TagTuple] TAGS_V2_GROUPS: dict[int, dict[int, _TagTuple]] diff --git a/stubs/PyMySQL/pymysql/converters.pyi b/stubs/PyMySQL/pymysql/converters.pyi index 175a5f7cd..850ca799d 100644 --- a/stubs/PyMySQL/pymysql/converters.pyi +++ b/stubs/PyMySQL/pymysql/converters.pyi @@ -3,8 +3,9 @@ import time from collections.abc import Callable, Mapping, Sequence from decimal import Decimal from typing import Any, TypeVar +from typing_extensions import TypeAlias -_EscaperMapping = Mapping[type[object], Callable[..., str]] | None +_EscaperMapping: TypeAlias = Mapping[type[object], Callable[..., str]] | None _T = TypeVar("_T") def escape_item(val: object, charset: object, mapping: _EscaperMapping = ...) -> str: ... diff --git a/stubs/PyYAML/yaml/constructor.pyi b/stubs/PyYAML/yaml/constructor.pyi index c030cd23a..1dc437453 100644 --- a/stubs/PyYAML/yaml/constructor.pyi +++ b/stubs/PyYAML/yaml/constructor.pyi @@ -1,9 +1,10 @@ from typing import Any, Pattern +from typing_extensions import TypeAlias from yaml.error import MarkedYAMLError from yaml.nodes import ScalarNode -_Scalar = str | int | float | bool | None +_Scalar: TypeAlias = str | int | float | bool | None class ConstructorError(MarkedYAMLError): ... diff --git a/stubs/PyYAML/yaml/cyaml.pyi b/stubs/PyYAML/yaml/cyaml.pyi index 74946311e..3fced1def 100644 --- a/stubs/PyYAML/yaml/cyaml.pyi +++ b/stubs/PyYAML/yaml/cyaml.pyi @@ -1,6 +1,7 @@ from _typeshed import SupportsRead from collections.abc import Mapping, Sequence from typing import IO, Any +from typing_extensions import TypeAlias from ._yaml import CEmitter, CParser from .constructor import BaseConstructor, FullConstructor, SafeConstructor, UnsafeConstructor @@ -9,7 +10,7 @@ from .resolver import BaseResolver, Resolver __all__ = ["CBaseLoader", "CSafeLoader", "CFullLoader", "CUnsafeLoader", "CLoader", "CBaseDumper", "CSafeDumper", "CDumper"] -_Readable = SupportsRead[str | bytes] +_Readable: TypeAlias = SupportsRead[str | bytes] class CBaseLoader(CParser, BaseConstructor, BaseResolver): def __init__(self, stream: str | bytes | _Readable) -> None: ... diff --git a/stubs/PyYAML/yaml/reader.pyi b/stubs/PyYAML/yaml/reader.pyi index 06e9a0f42..01d74cc9b 100644 --- a/stubs/PyYAML/yaml/reader.pyi +++ b/stubs/PyYAML/yaml/reader.pyi @@ -1,9 +1,10 @@ from _typeshed import SupportsRead from typing import Any +from typing_extensions import TypeAlias from yaml.error import YAMLError -_ReadStream = str | bytes | SupportsRead[str] | SupportsRead[bytes] +_ReadStream: TypeAlias = str | bytes | SupportsRead[str] | SupportsRead[bytes] class ReaderError(YAMLError): name: Any diff --git a/stubs/Pygments/pygments/lexers/__init__.pyi b/stubs/Pygments/pygments/lexers/__init__.pyi index 8eacccb26..fd64271c8 100644 --- a/stubs/Pygments/pygments/lexers/__init__.pyi +++ b/stubs/Pygments/pygments/lexers/__init__.pyi @@ -1,10 +1,11 @@ from _typeshed import StrOrBytesPath, StrPath from collections.abc import Iterator from typing import Any +from typing_extensions import TypeAlias from pygments.lexer import Lexer, LexerMeta -_OpenFile = StrOrBytesPath | int # copy/pasted from builtins.pyi +_OpenFile: TypeAlias = StrOrBytesPath | int # copy/pasted from builtins.pyi def get_all_lexers() -> Iterator[tuple[str, tuple[str, ...], tuple[str, ...], tuple[str, ...]]]: ... def find_lexer_class(name: str) -> LexerMeta | None: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/dbapi.pyi b/stubs/SQLAlchemy/sqlalchemy/dbapi.pyi index 432e5936a..e01062d35 100644 --- a/stubs/SQLAlchemy/sqlalchemy/dbapi.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/dbapi.pyi @@ -3,11 +3,12 @@ from collections.abc import Mapping, Sequence from typing import Any, Protocol +from typing_extensions import TypeAlias -DBAPITypeCode = Any | None +DBAPITypeCode: TypeAlias = Any | None # Strictly speaking, this should be a Sequence, but the type system does # not support fixed-length sequences. -DBAPIColumnDescription = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None] +DBAPIColumnDescription: TypeAlias = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None] class DBAPIConnection(Protocol): def close(self) -> object: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/engine/base.pyi b/stubs/SQLAlchemy/sqlalchemy/engine/base.pyi index 80dfff42e..c165a6448 100644 --- a/stubs/SQLAlchemy/sqlalchemy/engine/base.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/engine/base.pyi @@ -3,6 +3,7 @@ from abc import abstractmethod from collections.abc import Mapping from types import TracebackType from typing import Any, Callable, TypeVar, overload +from typing_extensions import TypeAlias from ..dbapi import DBAPIConnection from ..log import Identified, _EchoFlag, echo_property @@ -19,7 +20,7 @@ from .util import TransactionalContext _T = TypeVar("_T") -_Executable = ClauseElement | FunctionElement | DDLElement | DefaultGenerator | Compiled +_Executable: TypeAlias = ClauseElement | FunctionElement | DDLElement | DefaultGenerator | Compiled class Connection(Connectable): engine: Engine diff --git a/stubs/SQLAlchemy/sqlalchemy/engine/url.pyi b/stubs/SQLAlchemy/sqlalchemy/engine/url.pyi index 0e0f535fd..30625dfce 100644 --- a/stubs/SQLAlchemy/sqlalchemy/engine/url.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/engine/url.pyi @@ -1,6 +1,7 @@ from _typeshed import Self, SupportsItems from collections.abc import Iterable, Mapping, Sequence from typing import Any, NamedTuple +from typing_extensions import TypeAlias from ..util import immutabledict from .interfaces import Dialect @@ -15,7 +16,7 @@ class _URLTuple(NamedTuple): database: str | None query: immutabledict[str, str | tuple[str, ...]] -_Query = Mapping[str, str | Sequence[str]] | Sequence[tuple[str, str | Sequence[str]]] +_Query: TypeAlias = Mapping[str, str | Sequence[str]] | Sequence[tuple[str, str | Sequence[str]]] class URL(_URLTuple): @classmethod diff --git a/stubs/SQLAlchemy/sqlalchemy/log.pyi b/stubs/SQLAlchemy/sqlalchemy/log.pyi index 2f1115228..54b045cbc 100644 --- a/stubs/SQLAlchemy/sqlalchemy/log.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/log.pyi @@ -1,10 +1,10 @@ from _typeshed import Self from logging import Logger from typing import Any, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias _ClsT = TypeVar("_ClsT", bound=type) -_EchoFlag = bool | Literal["debug"] | None +_EchoFlag: TypeAlias = bool | Literal["debug"] | None rootlogger: Any diff --git a/stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi b/stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi index 482f4d3fc..dc322256b 100644 --- a/stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi @@ -1,5 +1,6 @@ from collections.abc import Callable from typing import Any, ClassVar, TypeVar, overload +from typing_extensions import TypeAlias from ..engine.interfaces import Connectable from ..sql.schema import MetaData @@ -21,7 +22,7 @@ class _DeclarativeBase(Any): # super classes are dynamic __class_getitem__: ClassVar[Any] # Meta class (or function) that creates a _DeclarativeBase class. -_DeclarativeBaseMeta = Callable[[str, tuple[type[Any], ...], dict[str, Any]], _DeclT] +_DeclarativeBaseMeta: TypeAlias = Callable[[str, tuple[type[Any], ...], dict[str, Any]], _DeclT] def has_inherited_table(cls: type[Any]) -> bool: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi b/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi index e764687d1..06cd4378b 100644 --- a/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi @@ -3,6 +3,7 @@ import sys from _typeshed import Self, SupportsKeysAndGetItem from collections.abc import Callable, Iterable, Iterator, Mapping from typing import Any, Generic, NoReturn, TypeVar, overload +from typing_extensions import TypeAlias from ..cimmutabledict import immutabledict as immutabledict from ..sql.elements import ColumnElement @@ -178,7 +179,7 @@ class WeakPopulateDict(dict[Any, Any]): column_set = set column_dict = dict -ordered_column_set = OrderedSet[ColumnElement[Any]] +ordered_column_set: TypeAlias = OrderedSet[ColumnElement[Any]] def unique_list(seq: Iterable[_T], hashfunc: Callable[[_T], Any] | None = ...) -> list[_T]: ... diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index 0ad3ab6c9..87a1cc4ab 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -3,10 +3,11 @@ from _typeshed import StrOrBytesPath from asyncio.events import AbstractEventLoop from os import stat_result from typing import Any, Sequence, overload +from typing_extensions import TypeAlias from . import ospath as path -_FdOrAnyPath = int | StrOrBytesPath +_FdOrAnyPath: TypeAlias = int | StrOrBytesPath async def stat( path: _FdOrAnyPath, # noqa: F811 diff --git a/stubs/aiofiles/aiofiles/threadpool/__init__.pyi b/stubs/aiofiles/aiofiles/threadpool/__init__.pyi index f1759567e..49262ebad 100644 --- a/stubs/aiofiles/aiofiles/threadpool/__init__.pyi +++ b/stubs/aiofiles/aiofiles/threadpool/__init__.pyi @@ -8,14 +8,14 @@ from _typeshed import ( ) from asyncio import AbstractEventLoop from typing import Any, Callable, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from ..base import AiofilesContextManager from .binary import AsyncBufferedIOBase, AsyncBufferedReader, AsyncFileIO, _UnknownAsyncBinaryIO from .text import AsyncTextIOWrapper -_OpenFile = StrOrBytesPath | int -_Opener = Callable[[str, int], int] +_OpenFile: TypeAlias = StrOrBytesPath | int +_Opener: TypeAlias = Callable[[str, int], int] # Text mode: always returns AsyncTextIOWrapper @overload diff --git a/stubs/annoy/annoy/__init__.pyi b/stubs/annoy/annoy/__init__.pyi index 87ecc5c57..2a0bb263a 100644 --- a/stubs/annoy/annoy/__init__.pyi +++ b/stubs/annoy/annoy/__init__.pyi @@ -1,8 +1,8 @@ from _typeshed import SupportsLenAndGetItem from typing import overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias -_Vector = SupportsLenAndGetItem[float] +_Vector: TypeAlias = SupportsLenAndGetItem[float] class AnnoyIndex: f: int diff --git a/stubs/babel/babel/core.pyi b/stubs/babel/babel/core.pyi index 7bb4e9d08..ddd0df911 100644 --- a/stubs/babel/babel/core.pyi +++ b/stubs/babel/babel/core.pyi @@ -1,5 +1,5 @@ from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias class UnknownLocaleError(Exception): identifier: Any @@ -115,7 +115,7 @@ def parse_locale(identifier, sep: str = ...): ... def get_locale_identifier(tup, sep: str = ...): ... def get_global(key: _GLOBAL_KEY): ... -_GLOBAL_KEY = Literal[ +_GLOBAL_KEY: TypeAlias = Literal[ "all_currencies", "currency_fractions", "language_aliases", diff --git a/stubs/babel/babel/dates.pyi b/stubs/babel/babel/dates.pyi index 4e86c985b..68723fc88 100644 --- a/stubs/babel/babel/dates.pyi +++ b/stubs/babel/babel/dates.pyi @@ -1,6 +1,6 @@ from datetime import date, datetime, time, timedelta, tzinfo from typing import Any, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from babel.core import Locale from babel.util import LOCALTZ as LOCALTZ, UTC as UTC @@ -10,8 +10,8 @@ from pytz import BaseTzInfo # http://babel.pocoo.org/en/latest/api/dates.html # Date and Time Formatting -_Instant = date | time | datetime | float | None -_PredefinedTimeFormat = Literal["full", "long", "medium", "short"] +_Instant: TypeAlias = date | time | datetime | float | None +_PredefinedTimeFormat: TypeAlias = Literal["full", "long", "medium", "short"] def format_datetime( datetime: _Instant = ..., format: _PredefinedTimeFormat | str = ..., tzinfo: tzinfo | None = ..., locale: str | Locale = ... @@ -57,7 +57,7 @@ def get_timezone_gmt( return_z: bool = ..., ) -> str: ... -_DtOrTzinfo = datetime | tzinfo | str | int | time | None +_DtOrTzinfo: TypeAlias = datetime | tzinfo | str | int | time | None def get_timezone_location(dt_or_tzinfo: _DtOrTzinfo = ..., locale: str | Locale = ..., return_city: bool = ...) -> str: ... def get_timezone_name( diff --git a/stubs/beautifulsoup4/bs4/element.pyi b/stubs/beautifulsoup4/bs4/element.pyi index 4468480a3..974f39ac8 100644 --- a/stubs/beautifulsoup4/bs4/element.pyi +++ b/stubs/beautifulsoup4/bs4/element.pyi @@ -1,6 +1,7 @@ from _typeshed import Self from collections.abc import Iterator from typing import Any, Callable, Generic, Iterable, Pattern, TypeVar, overload +from typing_extensions import TypeAlias from . import BeautifulSoup from .builder import TreeBuilder @@ -27,10 +28,10 @@ class ContentMetaAttributeValue(AttributeValueWithCharsetSubstitution): def encode(self, encoding: str) -> str: ... # type: ignore[override] # incompatible with str _PageElementT = TypeVar("_PageElementT", bound=PageElement) -_SimpleStrainable = str | bool | None | bytes | Pattern[str] | Callable[[str], bool] | Callable[[Tag], bool] -_Strainable = _SimpleStrainable | Iterable[_SimpleStrainable] -_SimpleNormalizedStrainable = str | bool | None | Pattern[str] | Callable[[str], bool] | Callable[[Tag], bool] -_NormalizedStrainable = _SimpleNormalizedStrainable | Iterable[_SimpleNormalizedStrainable] +_SimpleStrainable: TypeAlias = str | bool | None | bytes | Pattern[str] | Callable[[str], bool] | Callable[[Tag], bool] +_Strainable: TypeAlias = _SimpleStrainable | Iterable[_SimpleStrainable] +_SimpleNormalizedStrainable: TypeAlias = str | bool | None | Pattern[str] | Callable[[str], bool] | Callable[[Tag], bool] +_NormalizedStrainable: TypeAlias = _SimpleNormalizedStrainable | Iterable[_SimpleNormalizedStrainable] class PageElement: parent: Tag | None diff --git a/stubs/beautifulsoup4/bs4/formatter.pyi b/stubs/beautifulsoup4/bs4/formatter.pyi index 4250419fd..19ceb3cf6 100644 --- a/stubs/beautifulsoup4/bs4/formatter.pyi +++ b/stubs/beautifulsoup4/bs4/formatter.pyi @@ -1,8 +1,9 @@ from typing import Callable +from typing_extensions import TypeAlias from .dammit import EntitySubstitution as EntitySubstitution -_EntitySubstitution = Callable[[str], str] +_EntitySubstitution: TypeAlias = Callable[[str], str] class Formatter(EntitySubstitution): HTML: str diff --git a/stubs/bleach/bleach/callbacks.pyi b/stubs/bleach/bleach/callbacks.pyi index de8a14d93..4fe9723ee 100644 --- a/stubs/bleach/bleach/callbacks.pyi +++ b/stubs/bleach/bleach/callbacks.pyi @@ -1,7 +1,8 @@ from collections.abc import MutableMapping from typing import Any +from typing_extensions import TypeAlias -_Attrs = MutableMapping[Any, str] +_Attrs: TypeAlias = MutableMapping[Any, str] def nofollow(attrs: _Attrs, new: bool = ...) -> _Attrs: ... def target_blank(attrs: _Attrs, new: bool = ...) -> _Attrs: ... diff --git a/stubs/bleach/bleach/linkifier.pyi b/stubs/bleach/bleach/linkifier.pyi index cb3013cac..66abcccd3 100644 --- a/stubs/bleach/bleach/linkifier.pyi +++ b/stubs/bleach/bleach/linkifier.pyi @@ -1,9 +1,10 @@ from collections.abc import Container, Iterable, MutableMapping from typing import Any, Pattern, Protocol +from typing_extensions import TypeAlias from .html5lib_shim import Filter -_Attrs = MutableMapping[Any, str] +_Attrs: TypeAlias = MutableMapping[Any, str] class _Callback(Protocol): def __call__(self, attrs: _Attrs, new: bool = ...) -> _Attrs: ... diff --git a/stubs/bleach/bleach/sanitizer.pyi b/stubs/bleach/bleach/sanitizer.pyi index 9e550a76d..5576255c3 100644 --- a/stubs/bleach/bleach/sanitizer.pyi +++ b/stubs/bleach/bleach/sanitizer.pyi @@ -1,5 +1,6 @@ from collections.abc import Callable, Container, Iterable from typing import Any, Pattern +from typing_extensions import TypeAlias from .css_sanitizer import CSSSanitizer from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter @@ -38,9 +39,9 @@ class Cleaner: ) -> None: ... def clean(self, text: str) -> str: ... -_AttributeFilter = Callable[[str, str, str], bool] -_AttributeDict = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter] -_Attributes = _AttributeFilter | _AttributeDict | list[str] +_AttributeFilter: TypeAlias = Callable[[str, str, str], bool] +_AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter] +_Attributes: TypeAlias = _AttributeFilter | _AttributeDict | list[str] def attribute_filter_factory(attributes: _Attributes) -> _AttributeFilter: ... diff --git a/stubs/boto/boto/utils.pyi b/stubs/boto/boto/utils.pyi index fea0e3a73..09c090a41 100644 --- a/stubs/boto/boto/utils.pyi +++ b/stubs/boto/boto/utils.pyi @@ -5,6 +5,7 @@ import sys import time from contextlib import AbstractContextManager from typing import IO, Any, Callable, Iterable, Mapping, Sequence, TypeVar +from typing_extensions import TypeAlias import boto.connection @@ -15,28 +16,28 @@ if sys.version_info >= (3,): # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO import io - _StringIO = io.StringIO + _StringIO: TypeAlias = io.StringIO from hashlib import _Hash - _HashType = _Hash + _HashType: TypeAlias = _Hash from email.message import Message as _Message else: # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO import StringIO - _StringIO = StringIO.StringIO[Any] + _StringIO: TypeAlias = StringIO.StringIO[Any] from hashlib import _hash - _HashType = _hash + _HashType: TypeAlias = _hash # TODO use email.message.Message once stubs exist - _Message = Any + _Message: TypeAlias = Any -_Provider = Any # TODO replace this with boto.provider.Provider once stubs exist -_LockType = Any # TODO replace this with _thread.LockType once stubs exist +_Provider: TypeAlias = Any # TODO replace this with boto.provider.Provider once stubs exist +_LockType: TypeAlias = Any # TODO replace this with _thread.LockType once stubs exist JSONDecodeError: type[ValueError] qsa_of_interest: list[str] diff --git a/stubs/chevron/chevron/main.pyi b/stubs/chevron/chevron/main.pyi index 8b0f75583..99a589d52 100755 --- a/stubs/chevron/chevron/main.pyi +++ b/stubs/chevron/chevron/main.pyi @@ -1,7 +1,8 @@ from _typeshed import StrOrBytesPath from typing import Any +from typing_extensions import TypeAlias -_OpenFile = StrOrBytesPath | int +_OpenFile: TypeAlias = StrOrBytesPath | int def main(template: _OpenFile, data: _OpenFile | None = ..., **kwargs: Any) -> str: ... def cli_main() -> None: ... diff --git a/stubs/colorama/colorama/ansitowin32.pyi b/stubs/colorama/colorama/ansitowin32.pyi index 0bb2694f8..3c0569853 100644 --- a/stubs/colorama/colorama/ansitowin32.pyi +++ b/stubs/colorama/colorama/ansitowin32.pyi @@ -2,6 +2,7 @@ import sys from _typeshed import SupportsWrite from types import TracebackType from typing import Any, Callable, Pattern, Sequence, TextIO +from typing_extensions import TypeAlias if sys.platform == "win32": from .winterm import WinTerm @@ -22,8 +23,8 @@ class StreamWrapper: @property def closed(self) -> bool: ... -_WinTermCall = Callable[[int | None, bool, bool], None] -_WinTermCallDict = dict[int, tuple[_WinTermCall] | tuple[_WinTermCall, int] | tuple[_WinTermCall, int, bool]] +_WinTermCall: TypeAlias = Callable[[int | None, bool, bool], None] +_WinTermCallDict: TypeAlias = dict[int, tuple[_WinTermCall] | tuple[_WinTermCall, int] | tuple[_WinTermCall, int, bool]] class AnsiToWin32: ANSI_CSI_RE: Pattern[str] = ... diff --git a/stubs/croniter/croniter.pyi b/stubs/croniter/croniter.pyi index 891e76f79..2950327ac 100644 --- a/stubs/croniter/croniter.pyi +++ b/stubs/croniter/croniter.pyi @@ -1,9 +1,9 @@ import datetime from _typeshed import Self from typing import Any, Iterator, Text -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias -_RetType = type[float | datetime.datetime] +_RetType: TypeAlias = type[float | datetime.datetime] class CroniterError(ValueError): ... class CroniterBadCronError(CroniterError): ... diff --git a/stubs/dateparser/dateparser/__init__.pyi b/stubs/dateparser/dateparser/__init__.pyi index c3bb15660..b649b36f5 100644 --- a/stubs/dateparser/dateparser/__init__.pyi +++ b/stubs/dateparser/dateparser/__init__.pyi @@ -1,5 +1,5 @@ import datetime -from typing_extensions import Literal, TypedDict +from typing_extensions import Literal, TypeAlias, TypedDict from .date import DateDataParser, _DetectLanguagesFunction @@ -7,8 +7,8 @@ __version__: str _default_parser: DateDataParser -_Part = Literal["day", "month", "year"] -_ParserKind = Literal["timestamp", "relative-time", "custom-formats", "absolute-time", "no-spaces-time"] +_Part: TypeAlias = Literal["day", "month", "year"] +_ParserKind: TypeAlias = Literal["timestamp", "relative-time", "custom-formats", "absolute-time", "no-spaces-time"] class _Settings(TypedDict, total=False): DATE_ORDER: str diff --git a/stubs/dateparser/dateparser/date.pyi b/stubs/dateparser/dateparser/date.pyi index fe2cea9aa..dd4a4cd44 100644 --- a/stubs/dateparser/dateparser/date.pyi +++ b/stubs/dateparser/dateparser/date.pyi @@ -3,15 +3,15 @@ from _typeshed import Self as Self from collections.abc import Callable, Iterable, Iterator from datetime import datetime from typing import ClassVar, Pattern, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from dateparser import _Settings from dateparser.conf import Settings from dateparser.languages.loader import LocaleDataLoader from dateparser.languages.locale import Locale -_DetectLanguagesFunction = Callable[[str, float], list[str]] -_Period = Literal["time", "day", "week", "month", "year"] +_DetectLanguagesFunction: TypeAlias = Callable[[str, float], list[str]] +_Period: TypeAlias = Literal["time", "day", "week", "month", "year"] APOSTROPHE_LOOK_ALIKE_CHARS: list[str] RE_NBSP: Pattern[str] diff --git a/stubs/docopt/docopt.pyi b/stubs/docopt/docopt.pyi index d3774d4c5..c272c4de0 100644 --- a/stubs/docopt/docopt.pyi +++ b/stubs/docopt/docopt.pyi @@ -1,8 +1,9 @@ from typing import Any, Iterable +from typing_extensions import TypeAlias __version__: str -_Argv = Iterable[str] | str +_Argv: TypeAlias = Iterable[str] | str def docopt( doc: str, argv: _Argv | None = ..., help: bool = ..., version: Any | None = ..., options_first: bool = ... diff --git a/stubs/docutils/docutils/parsers/rst/roles.pyi b/stubs/docutils/docutils/parsers/rst/roles.pyi index b433542e1..b35f2be7a 100644 --- a/stubs/docutils/docutils/parsers/rst/roles.pyi +++ b/stubs/docutils/docutils/parsers/rst/roles.pyi @@ -1,11 +1,12 @@ from typing import Any, Callable +from typing_extensions import TypeAlias import docutils.nodes import docutils.parsers.rst.states from docutils.languages import _LanguageModule from docutils.utils import Reporter, SystemMessage -_RoleFn = Callable[ +_RoleFn: TypeAlias = Callable[ [str, str, str, int, docutils.parsers.rst.states.Inliner, dict[str, Any], list[str]], tuple[list[docutils.nodes.reference], list[docutils.nodes.reference]], ] diff --git a/stubs/docutils/docutils/utils/__init__.pyi b/stubs/docutils/docutils/utils/__init__.pyi index fc0c2f346..74e606648 100644 --- a/stubs/docutils/docutils/utils/__init__.pyi +++ b/stubs/docutils/docutils/utils/__init__.pyi @@ -1,7 +1,7 @@ import optparse from collections.abc import Iterable from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from docutils import ApplicationError from docutils.io import FileOutput @@ -17,7 +17,7 @@ class DependencyList: def add(self, *filenames: str) -> None: ... def close(self) -> None: ... -_SystemMessageLevel = Literal[0, 1, 2, 3, 4] +_SystemMessageLevel: TypeAlias = Literal[0, 1, 2, 3, 4] class Reporter: DEBUG_LEVEL: Literal[0] diff --git a/stubs/flake8-plugin-utils/flake8_plugin_utils/plugin.pyi b/stubs/flake8-plugin-utils/flake8_plugin_utils/plugin.pyi index da825d2fe..353b6df11 100644 --- a/stubs/flake8-plugin-utils/flake8_plugin_utils/plugin.pyi +++ b/stubs/flake8-plugin-utils/flake8_plugin_utils/plugin.pyi @@ -1,8 +1,9 @@ import argparse import ast from typing import Any, Generic, Iterable, Iterator, TypeVar +from typing_extensions import TypeAlias -FLAKE8_ERROR = tuple[int, int, str, type[Any]] +FLAKE8_ERROR: TypeAlias = tuple[int, int, str, type[Any]] TConfig = TypeVar("TConfig") # noqa: Y001 # Name of the TypeVar matches the name at runtime class Error: diff --git a/stubs/fpdf2/fpdf/fpdf.pyi b/stubs/fpdf2/fpdf/fpdf.pyi index f17a00b03..220fa07b2 100644 --- a/stubs/fpdf2/fpdf/fpdf.pyi +++ b/stubs/fpdf2/fpdf/fpdf.pyi @@ -7,7 +7,7 @@ from enum import IntEnum from io import BytesIO from pathlib import Path from typing import Any, NamedTuple, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from PIL import Image @@ -16,10 +16,10 @@ from .recorder import FPDFRecorder from .syntax import DestinationXYZ from .util import _Unit -_Orientation = Literal["", "portrait", "p", "P", "landscape", "l", "L"] -_Format = Literal["", "a3", "A3", "a4", "A4", "a5", "A5", "letter", "Letter", "legal", "Legal"] -_FontStyle = Literal["", "B", "I"] -_FontStyles = Literal["", "B", "I", "U", "BU", "UB", "BI", "IB", "IU", "UI", "BIU", "BUI", "IBU", "IUB", "UBI", "UIB"] +_Orientation: TypeAlias = Literal["", "portrait", "p", "P", "landscape", "l", "L"] +_Format: TypeAlias = Literal["", "a3", "A3", "a4", "A4", "a5", "A5", "letter", "Letter", "legal", "Legal"] +_FontStyle: TypeAlias = Literal["", "B", "I"] +_FontStyles: TypeAlias = Literal["", "B", "I", "U", "BU", "UB", "BI", "IB", "IU", "UI", "BIU", "BUI", "IBU", "IUB", "UBI", "UIB"] PAGE_FORMATS: dict[_Format, tuple[float, float]] class DocumentState(IntEnum): @@ -64,10 +64,10 @@ def get_page_format(format: _Format | tuple[float, float], k: float | None = ... def load_cache(filename: Path): ... # TODO: TypedDicts -_Page = dict[str, Any] -_Font = dict[str, Any] -_FontFile = dict[str, Any] -_Image = dict[str, Any] +_Page: TypeAlias = dict[str, Any] +_Font: TypeAlias = dict[str, Any] +_FontFile: TypeAlias = dict[str, Any] +_Image: TypeAlias = dict[str, Any] class FPDF: MARKDOWN_BOLD_MARKER: str diff --git a/stubs/fpdf2/fpdf/image_parsing.pyi b/stubs/fpdf2/fpdf/image_parsing.pyi index 14c4f4bcd..586aad2a4 100644 --- a/stubs/fpdf2/fpdf/image_parsing.pyi +++ b/stubs/fpdf2/fpdf/image_parsing.pyi @@ -1,7 +1,7 @@ from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias -_ImageFilter = Literal["AUTO", "FlateDecode", "DCTDecode", "JPXDecode"] +_ImageFilter: TypeAlias = Literal["AUTO", "FlateDecode", "DCTDecode", "JPXDecode"] SUPPORTED_IMAGE_FILTERS: tuple[_ImageFilter, ...] diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index 21b00796a..a98988cbe 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -1,8 +1,8 @@ from collections.abc import Iterable from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias -_Unit = Literal["pt", "mm", "cm", "in"] +_Unit: TypeAlias = Literal["pt", "mm", "cm", "in"] def substr(s, start, length: int = ...): ... def enclose_in_parens(s): ... diff --git a/stubs/freezegun/freezegun/api.pyi b/stubs/freezegun/freezegun/api.pyi index 6efe819ad..e05d2b0d1 100644 --- a/stubs/freezegun/freezegun/api.pyi +++ b/stubs/freezegun/freezegun/api.pyi @@ -2,9 +2,10 @@ from collections.abc import Awaitable, Callable, Iterator, Sequence from datetime import date, datetime, timedelta from numbers import Real from typing import Any, TypeVar, overload +from typing_extensions import TypeAlias _T = TypeVar("_T") -_Freezable = str | datetime | date | timedelta +_Freezable: TypeAlias = str | datetime | date | timedelta class TickingDateTimeFactory: def __init__(self, time_to_freeze: datetime, start: datetime) -> None: ... diff --git a/stubs/google-cloud-ndb/google/cloud/ndb/model.pyi b/stubs/google-cloud-ndb/google/cloud/ndb/model.pyi index 54e20fab3..7b63e881f 100644 --- a/stubs/google-cloud-ndb/google/cloud/ndb/model.pyi +++ b/stubs/google-cloud-ndb/google/cloud/ndb/model.pyi @@ -2,7 +2,7 @@ import datetime from _typeshed import Self from collections.abc import Iterable, Sequence from typing import Any, Callable, NoReturn -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from google.cloud.ndb import exceptions, key as key_module, query as query_module, tasklets as tasklets_module @@ -24,7 +24,7 @@ class UserNotFoundError(exceptions.Error): ... class _NotEqualMixin: def __ne__(self, other: object) -> bool: ... -DirectionT = Literal["asc", "desc"] +DirectionT: TypeAlias = Literal["asc", "desc"] class IndexProperty(_NotEqualMixin): def __new__(cls: type[Self], name: str, direction: DirectionT) -> Self: ... diff --git a/stubs/hdbcli/hdbcli/dbapi.pyi b/stubs/hdbcli/hdbcli/dbapi.pyi index 33406fb93..89b3dde56 100644 --- a/stubs/hdbcli/hdbcli/dbapi.pyi +++ b/stubs/hdbcli/hdbcli/dbapi.pyi @@ -2,7 +2,7 @@ import decimal from _typeshed import ReadableBuffer from datetime import date, datetime, time from typing import Any, Sequence, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .resultrow import ResultRow @@ -44,7 +44,7 @@ class LOB: def read(self, size: int = ..., position: int = ...) -> str | bytes: ... def write(self, object: str | bytes) -> int: ... -_Parameters = Sequence[tuple[Any, ...]] +_Parameters: TypeAlias = Sequence[tuple[Any, ...]] class Cursor: description: tuple[tuple[Any, ...], ...] diff --git a/stubs/html5lib/html5lib/_tokenizer.pyi b/stubs/html5lib/html5lib/_tokenizer.pyi index fd9f6dac7..6c7d0b41e 100644 --- a/stubs/html5lib/html5lib/_tokenizer.pyi +++ b/stubs/html5lib/html5lib/_tokenizer.pyi @@ -1,12 +1,13 @@ import sys from collections import OrderedDict from typing import Any +from typing_extensions import TypeAlias entitiesTrie: Any if sys.version_info >= (3, 7): - attributeMap = dict[Any, Any] + attributeMap: TypeAlias = dict[Any, Any] else: - attributeMap = OrderedDict[Any, Any] + attributeMap: TypeAlias = OrderedDict[Any, Any] class HTMLTokenizer: stream: Any diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index 2c8f53137..70787bb61 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -1,10 +1,11 @@ from _typeshed import SupportsKeysAndGetItem from collections.abc import Callable, Generator, Iterable from typing import Any, ClassVar, Mapping +from typing_extensions import TypeAlias from ._utils import URIDict -_Schema = Mapping[str, Any] +_Schema: TypeAlias = Mapping[str, Any] # This class does not exist at runtime. Compatible classes are created at # runtime by create(). @@ -43,7 +44,7 @@ class Draft7Validator(_Validator): ... class Draft201909Validator(_Validator): ... class Draft202012Validator(_Validator): ... -_Handler = Callable[[str], Any] +_Handler: TypeAlias = Callable[[str], Any] class RefResolver: referrer: dict[str, Any] diff --git a/stubs/ldap3/ldap3/core/connection.pyi b/stubs/ldap3/ldap3/core/connection.pyi index bcea8aae5..503abeebb 100644 --- a/stubs/ldap3/ldap3/core/connection.pyi +++ b/stubs/ldap3/ldap3/core/connection.pyi @@ -2,7 +2,7 @@ from _collections_abc import Generator, dict_keys from _typeshed import Self from types import TracebackType from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .pooling import ServerPool from .server import Server @@ -10,7 +10,9 @@ from .server import Server SASL_AVAILABLE_MECHANISMS: Any CLIENT_STRATEGIES: Any -_ServerSequence = set[Server] | list[Server] | tuple[Server, ...] | Generator[Server, None, None] | dict_keys[Server, Any] +_ServerSequence: TypeAlias = ( + set[Server] | list[Server] | tuple[Server, ...] | Generator[Server, None, None] | dict_keys[Server, Any] +) class Connection: connection_lock: Any diff --git a/stubs/paramiko/paramiko/auth_handler.pyi b/stubs/paramiko/paramiko/auth_handler.pyi index 11721bd22..abb758338 100644 --- a/stubs/paramiko/paramiko/auth_handler.pyi +++ b/stubs/paramiko/paramiko/auth_handler.pyi @@ -1,11 +1,12 @@ from threading import Event from typing import Callable +from typing_extensions import TypeAlias from paramiko.pkey import PKey from paramiko.ssh_gss import _SSH_GSSAuth from paramiko.transport import Transport -_InteractiveCallback = Callable[[str, str, list[tuple[str, bool]]], list[str]] +_InteractiveCallback: TypeAlias = Callable[[str, str, list[tuple[str, bool]]], list[str]] class AuthHandler: transport: Transport diff --git a/stubs/paramiko/paramiko/common.pyi b/stubs/paramiko/paramiko/common.pyi index 0da180a86..7127032f8 100644 --- a/stubs/paramiko/paramiko/common.pyi +++ b/stubs/paramiko/paramiko/common.pyi @@ -1,5 +1,6 @@ import sys from typing import Protocol +from typing_extensions import TypeAlias MSG_DISCONNECT: int MSG_IGNORE: int @@ -109,7 +110,7 @@ else: class _SupportsAsBytes(Protocol): def asbytes(self) -> bytes: ... -_LikeBytes = bytes | str | _SupportsAsBytes +_LikeBytes: TypeAlias = bytes | str | _SupportsAsBytes def asbytes(s: _LikeBytes) -> bytes: ... diff --git a/stubs/paramiko/paramiko/message.pyi b/stubs/paramiko/paramiko/message.pyi index 8aa478702..0f469a3aa 100644 --- a/stubs/paramiko/paramiko/message.pyi +++ b/stubs/paramiko/paramiko/message.pyi @@ -1,5 +1,6 @@ import sys from typing import Any, Iterable +from typing_extensions import TypeAlias from .common import _LikeBytes @@ -8,7 +9,7 @@ if sys.version_info >= (3, 0): else: from StringIO import StringIO - BytesIO = StringIO[bytes] + BytesIO: TypeAlias = StringIO[bytes] class Message: big_int: int diff --git a/stubs/paramiko/paramiko/sftp_client.pyi b/stubs/paramiko/paramiko/sftp_client.pyi index 86cfd043d..b22de5520 100644 --- a/stubs/paramiko/paramiko/sftp_client.pyi +++ b/stubs/paramiko/paramiko/sftp_client.pyi @@ -1,6 +1,7 @@ from _typeshed import Self from logging import Logger from typing import IO, Any, Callable, Iterator +from typing_extensions import TypeAlias from paramiko.channel import Channel from paramiko.sftp import BaseSFTP @@ -9,7 +10,7 @@ from paramiko.sftp_file import SFTPFile from paramiko.transport import Transport from paramiko.util import ClosingContextManager -_Callback = Callable[[int, int], Any] +_Callback: TypeAlias = Callable[[int, int], Any] b_slash: bytes diff --git a/stubs/paramiko/paramiko/transport.pyi b/stubs/paramiko/paramiko/transport.pyi index 599afe0a9..7781f8bf2 100644 --- a/stubs/paramiko/paramiko/transport.pyi +++ b/stubs/paramiko/paramiko/transport.pyi @@ -3,6 +3,7 @@ from socket import socket from threading import Condition, Event, Lock, Thread from types import ModuleType from typing import Any, Callable, Iterable, Protocol, Sequence +from typing_extensions import TypeAlias from paramiko.auth_handler import AuthHandler, _InteractiveCallback from paramiko.channel import Channel @@ -14,8 +15,8 @@ from paramiko.sftp_client import SFTPClient from paramiko.ssh_gss import _SSH_GSSAuth from paramiko.util import ClosingContextManager -_Addr = tuple[str, int] -_SocketLike = str | _Addr | socket | Channel +_Addr: TypeAlias = tuple[str, int] +_SocketLike: TypeAlias = str | _Addr | socket | Channel class _KexEngine(Protocol): def start_kex(self) -> None: ... diff --git a/stubs/parsimonious/parsimonious/expressions.pyi b/stubs/parsimonious/parsimonious/expressions.pyi index 9818c6a1b..1fb124e56 100644 --- a/stubs/parsimonious/parsimonious/expressions.pyi +++ b/stubs/parsimonious/parsimonious/expressions.pyi @@ -1,5 +1,6 @@ import typing from typing import Any, Callable, Mapping, Pattern, Union +from typing_extensions import TypeAlias from parsimonious.exceptions import ParseError from parsimonious.grammar import Grammar @@ -8,8 +9,8 @@ from parsimonious.utils import StrAndRepr MARKER: Any -_CALLABLE_RETURN_TYPE = Union[int, tuple[int, list[Node]], Node, None] -_CALLABLE_TYPE = ( +_CALLABLE_RETURN_TYPE: TypeAlias = Union[int, tuple[int, list[Node]], Node, None] +_CALLABLE_TYPE: TypeAlias = ( Callable[[str, int], _CALLABLE_RETURN_TYPE] | Callable[[str, int, Mapping[tuple[int, int], Node], ParseError, Grammar], _CALLABLE_RETURN_TYPE] ) diff --git a/stubs/protobuf/google/protobuf/internal/decoder.pyi b/stubs/protobuf/google/protobuf/internal/decoder.pyi index db08f0a46..09afc636d 100644 --- a/stubs/protobuf/google/protobuf/internal/decoder.pyi +++ b/stubs/protobuf/google/protobuf/internal/decoder.pyi @@ -1,10 +1,11 @@ from typing import Any, Callable +from typing_extensions import TypeAlias from google.protobuf.descriptor import Descriptor, FieldDescriptor from google.protobuf.message import Message -_Decoder = Callable[[str, int, int, Message, dict[FieldDescriptor, Any]], int] -_NewDefault = Callable[[Message], Message] +_Decoder: TypeAlias = Callable[[str, int, int, Message, dict[FieldDescriptor, Any]], int] +_NewDefault: TypeAlias = Callable[[Message], Message] def ReadTag(buffer, pos): ... diff --git a/stubs/protobuf/google/protobuf/internal/encoder.pyi b/stubs/protobuf/google/protobuf/internal/encoder.pyi index 058d2ff9f..9dc9b195c 100644 --- a/stubs/protobuf/google/protobuf/internal/encoder.pyi +++ b/stubs/protobuf/google/protobuf/internal/encoder.pyi @@ -1,8 +1,9 @@ from typing import Callable +from typing_extensions import TypeAlias from google.protobuf.descriptor import FieldDescriptor -_Sizer = Callable[[int, bool, bool], int] +_Sizer: TypeAlias = Callable[[int, bool, bool], int] Int32Sizer: _Sizer UInt32Sizer: _Sizer @@ -19,7 +20,7 @@ def MessageSetItemSizer(field_number: int) -> _Sizer: ... def MapSizer(field_descriptor: FieldDescriptor, is_message_map: bool) -> _Sizer: ... def TagBytes(field_number: int, wire_type: int) -> bytes: ... -_Encoder = Callable[[Callable[[bytes], int], bytes, bool], int] +_Encoder: TypeAlias = Callable[[Callable[[bytes], int], bytes, bool], int] Int32Encoder: _Encoder UInt32Encoder: _Encoder diff --git a/stubs/protobuf/google/protobuf/text_format.pyi b/stubs/protobuf/google/protobuf/text_format.pyi index 1f9f21aec..e2ce22d47 100644 --- a/stubs/protobuf/google/protobuf/text_format.pyi +++ b/stubs/protobuf/google/protobuf/text_format.pyi @@ -1,5 +1,6 @@ from _typeshed import SupportsWrite from typing import Any, Callable, Iterable, Text, TypeVar +from typing_extensions import TypeAlias from .descriptor import FieldDescriptor from .descriptor_pool import DescriptorPool @@ -20,7 +21,7 @@ class TextWriter: def getvalue(self) -> str: ... def close(self) -> None: ... -_MessageFormatter = Callable[[Message, int, bool], Text | None] +_MessageFormatter: TypeAlias = Callable[[Message, int, bool], Text | None] def MessageToString( message: Message, diff --git a/stubs/psutil/psutil/_common.pyi b/stubs/psutil/psutil/_common.pyi index 9fa49d105..00377d538 100644 --- a/stubs/psutil/psutil/_common.pyi +++ b/stubs/psutil/psutil/_common.pyi @@ -2,7 +2,7 @@ import enum from _typeshed import StrOrBytesPath, SupportsWrite from socket import AddressFamily, SocketKind from typing import Any, Callable, NamedTuple, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias POSIX: bool WINDOWS: bool @@ -31,7 +31,7 @@ STATUS_WAITING: Literal["waiting"] STATUS_SUSPENDED: Literal["suspended"] STATUS_PARKED: Literal["parked"] -_Status = Literal[ +_Status: TypeAlias = Literal[ "running", "sleeping", "disk-sleep", diff --git a/stubs/psycopg2/psycopg2/_psycopg.pyi b/stubs/psycopg2/psycopg2/_psycopg.pyi index bde672976..a5eb75070 100644 --- a/stubs/psycopg2/psycopg2/_psycopg.pyi +++ b/stubs/psycopg2/psycopg2/_psycopg.pyi @@ -2,12 +2,13 @@ from _typeshed import Self from collections.abc import Callable, Iterable, Mapping, Sequence from types import TracebackType from typing import Any, TypeVar, overload +from typing_extensions import TypeAlias import psycopg2 import psycopg2.extensions from psycopg2.sql import Composable -_Vars = Sequence[Any] | Mapping[str, Any] | None +_Vars: TypeAlias = Sequence[Any] | Mapping[str, Any] | None BINARY: Any BINARYARRAY: Any diff --git a/stubs/pyOpenSSL/OpenSSL/crypto.pyi b/stubs/pyOpenSSL/OpenSSL/crypto.pyi index 851680321..b14f39c98 100644 --- a/stubs/pyOpenSSL/OpenSSL/crypto.pyi +++ b/stubs/pyOpenSSL/OpenSSL/crypto.pyi @@ -1,12 +1,13 @@ from _typeshed import StrOrBytesPath from datetime import datetime from typing import Any, Callable, Iterable, Sequence +from typing_extensions import TypeAlias from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPublicKey from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey from cryptography.x509 import Certificate, CertificateRevocationList, CertificateSigningRequest -_Key = DSAPrivateKey | DSAPublicKey | RSAPrivateKey | RSAPublicKey +_Key: TypeAlias = DSAPrivateKey | DSAPublicKey | RSAPrivateKey | RSAPublicKey FILETYPE_PEM: int FILETYPE_ASN1: int diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 6e8d4f2bc..127ed73a7 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -1,5 +1,5 @@ from typing import Callable, Mapping, Sequence -from typing_extensions import Final +from typing_extensions import Final, TypeAlias paFloat32: Final[int] paInt32: Final[int] @@ -67,10 +67,10 @@ paPrimingOutput: Final[int] paMacCoreStreamInfo: PaMacCoreStreamInfo # Auxiliary types -_ChannelMap = Sequence[int] -_PaHostApiInfo = Mapping[str, str | int] -_PaDeviceInfo = Mapping[str, str | int | float] -_StreamCallback = Callable[[bytes | None, int, Mapping[str, float], int], tuple[bytes | None, int]] +_ChannelMap: TypeAlias = Sequence[int] +_PaHostApiInfo: TypeAlias = Mapping[str, str | int] +_PaDeviceInfo: TypeAlias = Mapping[str, str | int | float] +_StreamCallback: TypeAlias = Callable[[bytes | None, int, Mapping[str, float], int], tuple[bytes | None, int]] def get_format_from_width(width: int, unsigned: bool = ...) -> int: ... def get_portaudio_version() -> int: ... diff --git a/stubs/pyflakes/pyflakes/checker.pyi b/stubs/pyflakes/pyflakes/checker.pyi index 833cdb9dc..0f933ceb4 100644 --- a/stubs/pyflakes/pyflakes/checker.pyi +++ b/stubs/pyflakes/pyflakes/checker.pyi @@ -3,11 +3,11 @@ import sys from collections.abc import Callable, Iterable, Iterator from tokenize import TokenInfo from typing import Any, ClassVar, Pattern, TypeVar, overload -from typing_extensions import Literal, ParamSpec +from typing_extensions import Literal, ParamSpec, TypeAlias from pyflakes.messages import Message -_AnyFunction = Callable[..., Any] +_AnyFunction: TypeAlias = Callable[..., Any] _F = TypeVar("_F", bound=_AnyFunction) _P = ParamSpec("_P") _T = TypeVar("_T") @@ -37,8 +37,8 @@ PRECISION_RE: Pattern[str] LENGTH_RE: Pattern[str] VALID_CONVERSIONS: frozenset[str] -_FormatType = tuple[str | None, str | None, str | None, str | None, str] -_PercentFormat = tuple[str, _FormatType | None] +_FormatType: TypeAlias = tuple[str | None, str | None, str | None, str | None, str] +_PercentFormat: TypeAlias = tuple[str, _FormatType | None] def parse_percent_format(s: str) -> tuple[_PercentFormat, ...]: ... @@ -47,7 +47,7 @@ class _FieldsOrder(dict[type[ast.AST], tuple[str, ...]]): def counter(items: Iterable[_T]) -> dict[_T, int]: ... -_OmitType = str | tuple[str, ...] | None +_OmitType: TypeAlias = str | tuple[str, ...] | None def iter_child_nodes(node: ast.AST, omit: _OmitType = ..., _fields_order: _FieldsOrder = ...) -> Iterator[ast.AST]: ... @overload diff --git a/stubs/pysftp/pysftp/__init__.pyi b/stubs/pysftp/pysftp/__init__.pyi index ab0d4dddb..35d29e989 100644 --- a/stubs/pysftp/pysftp/__init__.pyi +++ b/stubs/pysftp/pysftp/__init__.pyi @@ -3,7 +3,7 @@ from contextlib import AbstractContextManager from stat import S_IMODE as S_IMODE from types import TracebackType from typing import IO, Any, Callable, Sequence -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias import paramiko from paramiko import AuthenticationException as AuthenticationException @@ -32,8 +32,8 @@ class CnOpts: def __init__(self, knownhosts: str | None = ...) -> None: ... def get_hostkey(self, host: str) -> paramiko.PKey: ... -_Callback = Callable[[int, int], Any] -_Path = str | bytes +_Callback: TypeAlias = Callable[[int, int], Any] +_Path: TypeAlias = str | bytes class Connection: def __init__( diff --git a/stubs/pysftp/pysftp/helpers.pyi b/stubs/pysftp/pysftp/helpers.pyi index 00372237e..d8278c029 100644 --- a/stubs/pysftp/pysftp/helpers.pyi +++ b/stubs/pysftp/pysftp/helpers.pyi @@ -1,5 +1,6 @@ from collections.abc import Callable, Iterator from contextlib import AbstractContextManager +from typing_extensions import TypeAlias def known_hosts() -> str: ... def st_mode_to_int(val: int) -> int: ... @@ -26,7 +27,7 @@ def path_advance(thepath: str, sep: str = ...) -> Iterator[str]: ... def path_retreat(thepath: str, sep: str = ...) -> Iterator[str]: ... def reparent(newparent: str, oldpath: str) -> str: ... -_PathCallback = Callable[[str], None] +_PathCallback: TypeAlias = Callable[[str], None] def walktree( localpath: str, fcallback: _PathCallback, dcallback: _PathCallback, ucallback: _PathCallback, recurse: bool = ... diff --git a/stubs/python-dateutil/dateutil/parser/__init__.pyi b/stubs/python-dateutil/dateutil/parser/__init__.pyi index d62990449..5c4ca94bc 100644 --- a/stubs/python-dateutil/dateutil/parser/__init__.pyi +++ b/stubs/python-dateutil/dateutil/parser/__init__.pyi @@ -1,9 +1,10 @@ from datetime import datetime, tzinfo from typing import IO, Any, Mapping, Text +from typing_extensions import TypeAlias from .isoparser import isoparse as isoparse, isoparser as isoparser -_FileOrStr = bytes | Text | IO[str] | IO[Any] +_FileOrStr: TypeAlias = bytes | Text | IO[str] | IO[Any] class parserinfo(object): JUMP: list[str] diff --git a/stubs/python-dateutil/dateutil/parser/isoparser.pyi b/stubs/python-dateutil/dateutil/parser/isoparser.pyi index 69d983ae7..02ff48c57 100644 --- a/stubs/python-dateutil/dateutil/parser/isoparser.pyi +++ b/stubs/python-dateutil/dateutil/parser/isoparser.pyi @@ -1,9 +1,10 @@ from _typeshed import SupportsRead from datetime import date, datetime, time, tzinfo from typing import Text +from typing_extensions import TypeAlias -_Readable = SupportsRead[Text | bytes] -_TakesAscii = Text | bytes | _Readable +_Readable: TypeAlias = SupportsRead[Text | bytes] +_TakesAscii: TypeAlias = Text | bytes | _Readable class isoparser: def __init__(self, sep: Text | bytes | None = ...): ... diff --git a/stubs/python-dateutil/dateutil/tz/tz.pyi b/stubs/python-dateutil/dateutil/tz/tz.pyi index 296d4418e..8b4efbf8a 100644 --- a/stubs/python-dateutil/dateutil/tz/tz.pyi +++ b/stubs/python-dateutil/dateutil/tz/tz.pyi @@ -1,10 +1,11 @@ import datetime from typing import IO, Any, Text, TypeVar +from typing_extensions import TypeAlias from ..relativedelta import relativedelta from ._common import _tzinfo as _tzinfo, enfold as enfold, tzname_in_python2 as tzname_in_python2, tzrangebase as tzrangebase -_FileObj = str | Text | IO[str] | IO[Text] +_FileObj: TypeAlias = str | Text | IO[str] | IO[Text] _DT = TypeVar("_DT", bound=datetime.datetime) ZERO: datetime.timedelta diff --git a/stubs/python-nmap/nmap/nmap.pyi b/stubs/python-nmap/nmap/nmap.pyi index 70be8d261..689288d3b 100644 --- a/stubs/python-nmap/nmap/nmap.pyi +++ b/stubs/python-nmap/nmap/nmap.pyi @@ -1,8 +1,8 @@ from typing import Any, Callable, Iterable, Iterator, Text, TypeVar -from typing_extensions import TypedDict +from typing_extensions import TypeAlias, TypedDict _T = TypeVar("_T") -_Callback = Callable[[str, _Result], Any] +_Callback: TypeAlias = Callable[[str, _Result], Any] class _Result(TypedDict): nmap: _ResultNmap diff --git a/stubs/redis/redis/client.pyi b/stubs/redis/redis/client.pyi index 83345c0b5..4cb799367 100644 --- a/stubs/redis/redis/client.pyi +++ b/stubs/redis/redis/client.pyi @@ -3,15 +3,15 @@ from _typeshed import Self, SupportsItems from datetime import datetime, timedelta from types import TracebackType from typing import Any, Callable, ClassVar, Generic, Iterable, Iterator, Mapping, Pattern, Sequence, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .commands import CoreCommands, RedisModuleCommands, SentinelCommands from .connection import ConnectionPool, _ConnectionPoolOptions from .lock import Lock from .retry import Retry -_Value = bytes | float | int | str -_Key = str | bytes +_Value: TypeAlias = bytes | float | int | str +_Key: TypeAlias = str | bytes # Lib returns str or bytes depending on value of decode_responses _StrType = TypeVar("_StrType", bound=str | bytes) @@ -21,9 +21,9 @@ _T = TypeVar("_T") _ScoreCastFuncReturn = TypeVar("_ScoreCastFuncReturn") # Keyword arguments that are passed to Redis.parse_response(). -_ParseResponseOptions = Any +_ParseResponseOptions: TypeAlias = Any # Keyword arguments that are passed to Redis.execute_command(). -_CommandOptions = _ConnectionPoolOptions | _ParseResponseOptions +_CommandOptions: TypeAlias = _ConnectionPoolOptions | _ParseResponseOptions SYM_EMPTY: bytes EMPTY_RESPONSE: str diff --git a/stubs/redis/redis/commands/search/commands.pyi b/stubs/redis/redis/commands/search/commands.pyi index 5a65c9264..b7a3fcc74 100644 --- a/stubs/redis/redis/commands/search/commands.pyi +++ b/stubs/redis/redis/commands/search/commands.pyi @@ -1,12 +1,12 @@ from collections.abc import Mapping from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .aggregation import AggregateRequest, AggregateResult, Cursor from .query import Query from .result import Result -_QueryParams = Mapping[str, str | float] +_QueryParams: TypeAlias = Mapping[str, str | float] NUMERIC: Literal["NUMERIC"] diff --git a/stubs/requests/requests/sessions.pyi b/stubs/requests/requests/sessions.pyi index ec266a30f..f629d46c3 100644 --- a/stubs/requests/requests/sessions.pyi +++ b/stubs/requests/requests/sessions.pyi @@ -1,5 +1,6 @@ from _typeshed import Self, SupportsItems from typing import IO, Any, Callable, Iterable, Mapping, MutableMapping, TypeVar, Union +from typing_extensions import TypeAlias from urllib3 import _collections @@ -27,8 +28,8 @@ TooManyRedirects = exceptions.TooManyRedirects InvalidSchema = exceptions.InvalidSchema ChunkedEncodingError = exceptions.ChunkedEncodingError ContentDecodingError = exceptions.ContentDecodingError -RecentlyUsedContainer = _collections.RecentlyUsedContainer[_KT, _VT] -CaseInsensitiveDict = structures.CaseInsensitiveDict[_VT] +RecentlyUsedContainer: TypeAlias = _collections.RecentlyUsedContainer[_KT, _VT] +CaseInsensitiveDict: TypeAlias = structures.CaseInsensitiveDict[_VT] HTTPAdapter = adapters.HTTPAdapter requote_uri = utils.requote_uri get_environ_proxies = utils.get_environ_proxies @@ -47,21 +48,21 @@ class SessionRedirectMixin: def rebuild_proxies(self, prepared_request, proxies): ... def should_strip_auth(self, old_url, new_url): ... -_Data = str | bytes | Mapping[str, Any] | Iterable[tuple[str, str | None]] | IO[Any] | None +_Data: TypeAlias = str | bytes | Mapping[str, Any] | Iterable[tuple[str, str | None]] | IO[Any] | None -_Hook = Callable[[Response], Any] -_Hooks = MutableMapping[str, _Hook | list[_Hook]] -_HooksInput = MutableMapping[str, Iterable[_Hook] | _Hook] +_Hook: TypeAlias = Callable[[Response], Any] +_Hooks: TypeAlias = MutableMapping[str, _Hook | list[_Hook]] +_HooksInput: TypeAlias = MutableMapping[str, Iterable[_Hook] | _Hook] -_ParamsMappingKeyType = str | bytes | int | float -_ParamsMappingValueType = str | bytes | int | float | Iterable[str | bytes | int | float] | None -_Params = Union[ +_ParamsMappingKeyType: TypeAlias = str | bytes | int | float +_ParamsMappingValueType: TypeAlias = str | bytes | int | float | Iterable[str | bytes | int | float] | None +_Params: TypeAlias = Union[ SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType], tuple[_ParamsMappingKeyType, _ParamsMappingValueType], Iterable[tuple[_ParamsMappingKeyType, _ParamsMappingValueType]], str | bytes, ] -_TextMapping = MutableMapping[str, str] +_TextMapping: TypeAlias = MutableMapping[str, str] class Session(SessionRedirectMixin): __attrs__: Any diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index 61ed6e90d..6e4da0afd 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -4,18 +4,19 @@ import zipimport from _typeshed import Self from abc import ABCMeta from typing import IO, Any, Callable, Generator, Iterable, Sequence, TypeVar, overload +from typing_extensions import TypeAlias -LegacyVersion = Any # from packaging.version -Version = Any # from packaging.version +LegacyVersion: TypeAlias = Any # from packaging.version +Version: TypeAlias = Any # from packaging.version _T = TypeVar("_T") -_NestedStr = str | Iterable[str | Iterable[Any]] -_InstallerType = Callable[[Requirement], Distribution | None] -_EPDistType = Distribution | Requirement | str -_MetadataType = IResourceProvider | None -_PkgReqType = str | Requirement -_DistFinderType = Callable[[_Importer, str, bool], Generator[Distribution, None, None]] -_NSHandlerType = Callable[[_Importer, str, str, types.ModuleType], str] +_NestedStr: TypeAlias = str | Iterable[str | Iterable[Any]] +_InstallerType: TypeAlias = Callable[[Requirement], Distribution | None] +_EPDistType: TypeAlias = Distribution | Requirement | str +_MetadataType: TypeAlias = IResourceProvider | None +_PkgReqType: TypeAlias = str | Requirement +_DistFinderType: TypeAlias = Callable[[_Importer, str, bool], Generator[Distribution, None, None]] +_NSHandlerType: TypeAlias = Callable[[_Importer, str, str, types.ModuleType], str] def declare_namespace(name: str) -> None: ... def fixup_namespace_packages(path_item: str) -> None: ... diff --git a/stubs/simplejson/simplejson/__init__.pyi b/stubs/simplejson/simplejson/__init__.pyi index 9e3401e78..294df3aad 100644 --- a/stubs/simplejson/simplejson/__init__.pyi +++ b/stubs/simplejson/simplejson/__init__.pyi @@ -1,11 +1,12 @@ from typing import IO, Any, Text +from typing_extensions import TypeAlias from simplejson.decoder import JSONDecoder as JSONDecoder from simplejson.encoder import JSONEncoder as JSONEncoder, JSONEncoderForHTML as JSONEncoderForHTML from simplejson.raw_json import RawJSON as RawJSON from simplejson.scanner import JSONDecodeError as JSONDecodeError -_LoadsString = Text | bytes | bytearray +_LoadsString: TypeAlias = Text | bytes | bytearray def dumps(obj: Any, *args: Any, **kwds: Any) -> str: ... def dump(obj: Any, fp: IO[str], *args: Any, **kwds: Any) -> None: ... diff --git a/stubs/stripe/stripe/util.pyi b/stubs/stripe/stripe/util.pyi index a5fbdbedf..7aef8744b 100644 --- a/stubs/stripe/stripe/util.pyi +++ b/stubs/stripe/stripe/util.pyi @@ -1,4 +1,5 @@ from typing import Any, overload +from typing_extensions import TypeAlias from stripe.stripe_object import StripeObject from stripe.stripe_response import StripeResponse @@ -21,7 +22,7 @@ def populate_headers(idempotency_key: None) -> None: ... @overload def populate_headers(idempotency_key: str) -> dict[str, str]: ... -_RespType = dict[Any, Any] | StripeObject | StripeResponse +_RespType: TypeAlias = dict[Any, Any] | StripeObject | StripeResponse # undocumented @overload diff --git a/stubs/tabulate/tabulate.pyi b/stubs/tabulate/tabulate.pyi index e5208e0be..d1d4669f0 100644 --- a/stubs/tabulate/tabulate.pyi +++ b/stubs/tabulate/tabulate.pyi @@ -1,4 +1,5 @@ from typing import Any, Callable, Container, Iterable, Mapping, NamedTuple, Sequence +from typing_extensions import TypeAlias LATEX_ESCAPE_RULES: dict[str, str] MIN_PADDING: int @@ -18,8 +19,8 @@ class DataRow(NamedTuple): sep: str end: str -_TableFormatLine = None | Line | Callable[[list[int], list[str]], str] -_TableFormatRow = None | DataRow | Callable[[list[Any], list[int], list[str]], str] +_TableFormatLine: TypeAlias = None | Line | Callable[[list[int], list[str]], str] +_TableFormatRow: TypeAlias = None | DataRow | Callable[[list[Any], list[int], list[str]], str] class TableFormat(NamedTuple): lineabove: _TableFormatLine diff --git a/stubs/toml/toml/decoder.pyi b/stubs/toml/toml/decoder.pyi index 6996ba5f7..a79c16070 100644 --- a/stubs/toml/toml/decoder.pyi +++ b/stubs/toml/toml/decoder.pyi @@ -1,6 +1,7 @@ import sys from _typeshed import SupportsRead from typing import Any, Callable, Generic, MutableMapping, Pattern, Text, TypeVar, overload +from typing_extensions import TypeAlias _MutableMappingT = TypeVar("_MutableMappingT", bound=MutableMapping[str, Any]) @@ -8,10 +9,10 @@ if sys.version_info >= (3, 0): from pathlib import PurePath FNFError = FileNotFoundError - _PathLike = str | bytes | PurePath + _PathLike: TypeAlias = str | bytes | PurePath else: FNFError = IOError - _PathLike = Text + _PathLike: TypeAlias = Text TIME_RE: Pattern[str] diff --git a/stubs/urllib3/urllib3/connection.pyi b/stubs/urllib3/urllib3/connection.pyi index 9493332d7..d17829a54 100644 --- a/stubs/urllib3/urllib3/connection.pyi +++ b/stubs/urllib3/urllib3/connection.pyi @@ -1,6 +1,7 @@ import ssl import sys from typing import IO, Any, Iterable +from typing_extensions import TypeAlias from . import exceptions, util from .packages import ssl_match_hostname @@ -14,7 +15,7 @@ else: class ConnectionError(Exception): ... -_TYPE_BODY = bytes | IO[Any] | Iterable[bytes] | str +_TYPE_BODY: TypeAlias = bytes | IO[Any] | Iterable[bytes] | str class DummyConnection: ...