From 558faba999d271a9835713ef3907518da9cce60f Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 16 Dec 2021 19:33:35 +0200 Subject: [PATCH 01/11] modify script --- tests/check_new_syntax.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/check_new_syntax.py b/tests/check_new_syntax.py index 09efdac84428..029747fdd521 100755 --- a/tests/check_new_syntax.py +++ b/tests/check_new_syntax.py @@ -28,6 +28,8 @@ def is_dotdotdot(node: ast.AST) -> bool: def add_contextlib_alias_error(node: ast.ImportFrom | ast.Attribute, alias: str) -> None: errors.append(f"{path}:{node.lineno}: Use `contextlib.{CONTEXT_MANAGER_ALIASES[alias]}` instead of `typing.{alias}`") + # TODO: Get rid of this class. It skips checking type aliases and base + # classes, but those can now be checked too, with new mypy version. class OldSyntaxFinder(ast.NodeVisitor): def __init__(self, *, set_from_collections_abc: bool) -> None: self.set_from_collections_abc = set_from_collections_abc @@ -67,10 +69,6 @@ def visit_Subscript(self, node: ast.Subscript) -> None: self.generic_visit(node) - # This doesn't check type aliases (or type var bounds, etc), since those are not - # currently supported - # - # TODO: can use built-in generics in type aliases class AnnotationFinder(ast.NodeVisitor): def __init__(self) -> None: self.set_from_collections_abc = False @@ -79,6 +77,16 @@ def old_syntax_finder(self) -> OldSyntaxFinder: """Convenience method to create an `OldSyntaxFinder` instance with the correct state""" return OldSyntaxFinder(set_from_collections_abc=self.set_from_collections_abc) + def visit_Subscript(self, node: ast.Subscript) -> None: + if isinstance(node.value, ast.Name): + if node.value.id == "Union" and isinstance(node.slice, ast.Tuple): + new_syntax = " | ".join(ast.unparse(x) for x in node.slice.elts) + errors.append(f"{path}:{node.lineno}: Use PEP 604 syntax for Union, e.g. `{new_syntax}`") + if node.value.id == "Optional": + new_syntax = f"{ast.unparse(node.slice)} | None" + errors.append(f"{path}:{node.lineno}: Use PEP 604 syntax for Optional, e.g. `{new_syntax}`") + self.generic_visit(node) + def visit_ImportFrom(self, node: ast.ImportFrom) -> None: if node.module == "collections.abc": imported_classes = node.names @@ -102,10 +110,12 @@ def visit_Attribute(self, node: ast.Attribute) -> None: def visit_AnnAssign(self, node: ast.AnnAssign) -> None: self.old_syntax_finder().visit(node.annotation) + self.generic_visit(node) def visit_arg(self, node: ast.arg) -> None: if node.annotation is not None: self.old_syntax_finder().visit(node.annotation) + self.generic_visit(node) def visit_FunctionDef(self, node: ast.FunctionDef) -> None: if node.returns is not None: From dc67692af9210081fcae829d4c30cf948c39cce8 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 16 Dec 2021 19:44:20 +0200 Subject: [PATCH 02/11] pipe output of tests/check_new_syntax.py to quick and dirty fixing script import sys for line in sys.stdin: filename, lineno, message = line.split(":") lineno = int(lineno) - 1 assert "Use PEP 604 syntax" in message new = message.split("`")[1] parts = new.split(" | ") assert all(part.count("[") == part.count("]") for part in parts) olds = [] olds.append("Union[" + ", ".join(parts) + "]") if len(parts) == 2 and parts.count("None") == 1: [x] = [p for p in parts if p != "None"] olds.append("Optional[" + x + "]") lines = open(filename).readlines() for old in olds: if lines[lineno].count(old) == 1: lines[lineno] = lines[lineno].replace(old, new) open(filename, "w").writelines(lines) --- stdlib/_codecs.pyi | 2 +- stdlib/_csv.pyi | 2 +- stdlib/_curses.pyi | 2 +- stdlib/_dummy_threading.pyi | 2 +- stdlib/_socket.pyi | 2 +- stdlib/_thread.pyi | 2 +- stdlib/_typeshed/__init__.pyi | 20 +++++++++---------- stdlib/aifc.pyi | 2 +- stdlib/array.pyi | 2 +- stdlib/asyncio/base_events.pyi | 2 +- stdlib/asyncio/base_subprocess.pyi | 2 +- stdlib/asyncio/events.pyi | 2 +- stdlib/asyncio/format_helpers.pyi | 2 +- stdlib/asyncio/streams.pyi | 2 +- stdlib/asyncio/subprocess.pyi | 2 +- stdlib/asyncio/tasks.pyi | 4 ++-- stdlib/asyncio/trsock.pyi | 4 ++-- stdlib/binhex.pyi | 2 +- stdlib/builtins.pyi | 4 ++-- stdlib/cgitb.pyi | 2 +- stdlib/cmath.pyi | 4 ++-- stdlib/configparser.pyi | 2 +- stdlib/contextlib.pyi | 6 +++--- stdlib/copyreg.pyi | 2 +- stdlib/ctypes/__init__.pyi | 8 ++++---- stdlib/dbm/__init__.pyi | 4 ++-- stdlib/dbm/dumb.pyi | 4 ++-- stdlib/dbm/gnu.pyi | 4 ++-- stdlib/dbm/ndbm.pyi | 4 ++-- stdlib/decimal.pyi | 6 +++--- stdlib/difflib.pyi | 2 +- stdlib/dis.pyi | 4 ++-- stdlib/distutils/ccompiler.pyi | 2 +- stdlib/distutils/fancy_getopt.pyi | 2 +- stdlib/email/_header_value_parser.pyi | 2 +- stdlib/email/message.pyi | 8 ++++---- stdlib/email/mime/application.pyi | 2 +- stdlib/email/mime/audio.pyi | 2 +- stdlib/email/mime/base.pyi | 2 +- stdlib/email/mime/image.pyi | 2 +- stdlib/email/mime/multipart.pyi | 2 +- stdlib/email/utils.pyi | 4 ++-- stdlib/enum.pyi | 2 +- stdlib/fractions.pyi | 2 +- stdlib/hmac.pyi | 2 +- stdlib/http/client.pyi | 2 +- stdlib/http/cookies.pyi | 2 +- stdlib/imaplib.pyi | 2 +- stdlib/importlib/abc.pyi | 2 +- stdlib/importlib/resources.pyi | 4 ++-- stdlib/inspect.pyi | 2 +- stdlib/itertools.pyi | 2 +- stdlib/lib2to3/pgen2/grammar.pyi | 2 +- stdlib/lib2to3/pytree.pyi | 4 ++-- stdlib/logging/__init__.pyi | 10 +++++----- stdlib/lzma.pyi | 2 +- stdlib/mailbox.pyi | 2 +- stdlib/mailcap.pyi | 2 +- stdlib/math.pyi | 2 +- stdlib/msilib/sequence.pyi | 2 +- stdlib/multiprocessing/__init__.pyi | 2 +- stdlib/multiprocessing/connection.pyi | 2 +- stdlib/multiprocessing/context.pyi | 2 +- stdlib/multiprocessing/dummy/connection.pyi | 2 +- stdlib/multiprocessing/synchronize.pyi | 2 +- stdlib/nntplib.pyi | 2 +- stdlib/os/__init__.pyi | 12 +++++------ stdlib/pickle.pyi | 4 ++-- stdlib/pstats.pyi | 2 +- stdlib/pydoc.pyi | 2 +- stdlib/pyexpat/__init__.pyi | 2 +- stdlib/re.pyi | 2 +- stdlib/readline.pyi | 4 ++-- stdlib/shutil.pyi | 2 +- stdlib/signal.pyi | 4 ++-- stdlib/smtplib.pyi | 2 +- stdlib/socketserver.pyi | 4 ++-- stdlib/sre_parse.pyi | 8 ++++---- stdlib/ssl.pyi | 10 +++++----- stdlib/statistics.pyi | 2 +- stdlib/subprocess.pyi | 10 +++++----- stdlib/sunau.pyi | 2 +- stdlib/sys.pyi | 6 +++--- stdlib/tempfile.pyi | 2 +- stdlib/termios.pyi | 2 +- stdlib/threading.pyi | 2 +- stdlib/timeit.pyi | 2 +- stdlib/tkinter/__init__.pyi | 18 ++++++++--------- stdlib/tkinter/ttk.pyi | 2 +- stdlib/tokenize.pyi | 2 +- stdlib/trace.pyi | 2 +- stdlib/traceback.pyi | 2 +- stdlib/tracemalloc.pyi | 2 +- stdlib/tty.pyi | 2 +- stdlib/turtle.pyi | 4 ++-- stdlib/unittest/result.pyi | 2 +- stdlib/unittest/suite.pyi | 2 +- stdlib/urllib/parse.pyi | 2 +- stdlib/uu.pyi | 2 +- stdlib/wave.pyi | 2 +- stdlib/winreg.pyi | 2 +- stdlib/wsgiref/handlers.pyi | 2 +- stdlib/xml/dom/pulldom.pyi | 4 ++-- stdlib/xml/dom/xmlbuilder.pyi | 8 ++++---- stdlib/xml/etree/ElementTree.pyi | 2 +- stdlib/xmlrpc/client.pyi | 8 ++++---- stdlib/xmlrpc/server.pyi | 4 ++-- stdlib/zipapp.pyi | 2 +- stubs/Pillow/PIL/Image.pyi | 2 +- stubs/Pillow/PIL/ImageColor.pyi | 4 ++-- stubs/Pillow/PIL/ImageDraw.pyi | 2 +- stubs/Pillow/PIL/TiffTags.pyi | 2 +- stubs/PyMySQL/pymysql/converters.pyi | 2 +- stubs/PyYAML/yaml/constructor.pyi | 2 +- stubs/PyYAML/yaml/cyaml.pyi | 2 +- stubs/Pygments/pygments/lexers/__init__.pyi | 2 +- stubs/aiofiles/aiofiles/os.pyi | 2 +- .../aiofiles/aiofiles/threadpool/__init__.pyi | 2 +- stubs/beautifulsoup4/bs4/element.pyi | 8 ++++---- stubs/bleach/bleach/sanitizer.pyi | 4 ++-- stubs/colorama/colorama/ansitowin32.pyi | 4 ++-- stubs/croniter/croniter.pyi | 2 +- stubs/docopt/docopt.pyi | 2 +- stubs/freezegun/freezegun/api.pyi | 2 +- stubs/paramiko/paramiko/common.pyi | 2 +- stubs/pyOpenSSL/OpenSSL/crypto.pyi | 2 +- stubs/pyaudio/pyaudio.pyi | 4 ++-- stubs/pysftp/pysftp/__init__.pyi | 2 +- .../dateutil/parser/__init__.pyi | 2 +- .../dateutil/parser/isoparser.pyi | 4 ++-- stubs/python-dateutil/dateutil/tz/tz.pyi | 2 +- stubs/redis/redis/client.pyi | 6 +++--- stubs/redis/redis/commands/core.pyi | 2 +- stubs/requests/requests/sessions.pyi | 10 +++++----- stubs/setuptools/pkg_resources/__init__.pyi | 10 +++++----- stubs/simplejson/simplejson/__init__.pyi | 2 +- stubs/tabulate/tabulate.pyi | 4 ++-- stubs/toml/toml.pyi | 2 +- 138 files changed, 231 insertions(+), 231 deletions(-) diff --git a/stdlib/_codecs.pyi b/stdlib/_codecs.pyi index a44a8a1a7c2a..78285ce99e89 100644 --- a/stdlib/_codecs.pyi +++ b/stdlib/_codecs.pyi @@ -6,7 +6,7 @@ from typing import Any, Callable, Dict, Tuple, Union class _EncodingMap: def size(self) -> int: ... -_MapT = Union[Dict[int, int], _EncodingMap] +_MapT = Dict[int, int] | _EncodingMap _Handler = Callable[[Exception], Tuple[str, int]] def register(__search_function: Callable[[str], Any]) -> None: ... diff --git a/stdlib/_csv.pyi b/stdlib/_csv.pyi index 65f0ca27f0ec..859bb64c73cb 100644 --- a/stdlib/_csv.pyi +++ b/stdlib/_csv.pyi @@ -18,7 +18,7 @@ class Dialect: strict: int def __init__(self) -> None: ... -_DialectLike = Union[str, Dialect, Type[Dialect]] +_DialectLike = str | Dialect | Type[Dialect] class _reader(Iterator[List[str]]): dialect: Dialect diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 80e7776c1f0a..ca059e02a137 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,7 +1,7 @@ import sys from typing import IO, Any, BinaryIO, NamedTuple, Union, overload -_chtype = Union[str, bytes, int] +_chtype = 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 64998d86bf9f..4481a04f8f6b 100644 --- a/stdlib/_dummy_threading.pyi +++ b/stdlib/_dummy_threading.pyi @@ -3,7 +3,7 @@ from types import FrameType, TracebackType from typing import Any, Callable, Iterable, Mapping, Optional, Type, TypeVar # TODO recursive type -_TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]] +_TF = Callable[[FrameType, str, Any], Callable[..., Any] | None] _PF = Callable[[FrameType, str, Any], None] _T = TypeVar("_T") diff --git a/stdlib/_socket.pyi b/stdlib/_socket.pyi index 82898177286b..dbc58469c8f0 100644 --- a/stdlib/_socket.pyi +++ b/stdlib/_socket.pyi @@ -15,7 +15,7 @@ _CMSGArg = 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 = Union[Tuple[Any, ...], str] +_Address = Tuple[Any, ...] | str _RetAddress = Any # TODO Most methods allow bytes as address objects diff --git a/stdlib/_thread.pyi b/stdlib/_thread.pyi index 2f4252981b68..09a10fadb54c 100644 --- a/stdlib/_thread.pyi +++ b/stdlib/_thread.pyi @@ -32,7 +32,7 @@ TIMEOUT_MAX: float if sys.version_info >= (3, 8): def get_native_id() -> int: ... # only available on some platforms @final - class _ExceptHookArgs(Tuple[Type[BaseException], Optional[BaseException], Optional[TracebackType], Optional[Thread]]): + class _ExceptHookArgs(Tuple[Type[BaseException], BaseException | None, TracebackType | None, Thread | None]): @property def exc_type(self) -> Type[BaseException]: ... @property diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index b756a6213736..5bc65ab25af5 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -51,9 +51,9 @@ class SupportsDunderGE(Protocol): class SupportsAllComparisons(SupportsDunderLT, SupportsDunderGT, SupportsDunderLE, SupportsDunderGE, Protocol): ... -SupportsRichComparison = Union[SupportsDunderLT, SupportsDunderGT] +SupportsRichComparison = SupportsDunderLT | SupportsDunderGT SupportsRichComparisonT = TypeVar("SupportsRichComparisonT", bound=SupportsRichComparison) # noqa: Y001 -SupportsAnyComparison = Union[SupportsDunderLE, SupportsDunderGE, SupportsDunderGT, SupportsDunderLT] +SupportsAnyComparison = SupportsDunderLE | SupportsDunderGE | SupportsDunderGT | SupportsDunderLT class SupportsDivMod(Protocol[_T_contra, _T_co]): def __divmod__(self, __other: _T_contra) -> _T_co: ... @@ -89,9 +89,9 @@ class SupportsItemAccess(SupportsGetItem[_KT_contra, _VT], Protocol[_KT_contra, def __delitem__(self, __v: _KT_contra) -> None: ... # These aliases are simple strings in Python 2. -StrPath = Union[str, PathLike[str]] # stable -BytesPath = Union[bytes, PathLike[bytes]] # stable -StrOrBytesPath = Union[str, bytes, PathLike[str], PathLike[bytes]] # stable +StrPath = str | PathLike[str] # stable +BytesPath = bytes | PathLike[bytes] # stable +StrOrBytesPath = str | bytes | PathLike[str] | PathLike[bytes] # stable OpenTextModeUpdating = Literal[ "r+", @@ -129,7 +129,7 @@ OpenTextModeUpdating = Literal[ ] OpenTextModeWriting = Literal["w", "wt", "tw", "a", "at", "ta", "x", "xt", "tx"] OpenTextModeReading = Literal["r", "rt", "tr", "U", "rU", "Ur", "rtU", "rUt", "Urt", "trU", "tUr", "Utr"] -OpenTextMode = Union[OpenTextModeUpdating, OpenTextModeWriting, OpenTextModeReading] +OpenTextMode = OpenTextModeUpdating | OpenTextModeWriting | OpenTextModeReading OpenBinaryModeUpdating = Literal[ "rb+", "r+b", @@ -158,14 +158,14 @@ OpenBinaryModeUpdating = Literal[ ] OpenBinaryModeWriting = Literal["wb", "bw", "ab", "ba", "xb", "bx"] OpenBinaryModeReading = Literal["rb", "br", "rbU", "rUb", "Urb", "brU", "bUr", "Ubr"] -OpenBinaryMode = Union[OpenBinaryModeUpdating, OpenBinaryModeReading, OpenBinaryModeWriting] +OpenBinaryMode = OpenBinaryModeUpdating | OpenBinaryModeReading | OpenBinaryModeWriting # stable class HasFileno(Protocol): def fileno(self) -> int: ... FileDescriptor = int # stable -FileDescriptorLike = Union[int, HasFileno] # stable +FileDescriptorLike = int | HasFileno # stable # stable class SupportsRead(Protocol[_T_co]): @@ -187,9 +187,9 @@ ReadOnlyBuffer = bytes # stable # Anything that implements the read-write buffer interface. # The buffer interface is defined purely on the C level, so we cannot define a normal Protocol # for it. Instead we have to list the most common stdlib buffer classes in a Union. -WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, ctypes._CData] # stable +WriteableBuffer = bytearray | memoryview | array.array[Any] | mmap.mmap | ctypes._CData # stable # Same as _WriteableBuffer, but also includes read-only buffer types (like bytes). -ReadableBuffer = Union[ReadOnlyBuffer, WriteableBuffer] # stable +ReadableBuffer = ReadOnlyBuffer | WriteableBuffer # stable # stable if sys.version_info >= (3, 10): diff --git a/stdlib/aifc.pyi b/stdlib/aifc.pyi index 79f470a366bb..5d9d60162bec 100644 --- a/stdlib/aifc.pyi +++ b/stdlib/aifc.pyi @@ -14,7 +14,7 @@ class _aifc_params(NamedTuple): comptype: bytes compname: bytes -_File = Union[str, IO[bytes]] +_File = str | IO[bytes] _Marker = Tuple[int, int, bytes] class Aifc_read: diff --git a/stdlib/array.pyi b/stdlib/array.pyi index f49eb2c916c2..f0c883f6c337 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -5,7 +5,7 @@ from typing_extensions import Literal, SupportsIndex _IntTypeCode = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] _FloatTypeCode = Literal["f", "d"] _UnicodeTypeCode = Literal["u"] -_TypeCode = Union[_IntTypeCode, _FloatTypeCode, _UnicodeTypeCode] +_TypeCode = _IntTypeCode | _FloatTypeCode | _UnicodeTypeCode _T = TypeVar("_T", int, float, str) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index e804c2f5d3bd..932c9d41a45a 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -19,7 +19,7 @@ _T = TypeVar("_T") _Context = Dict[str, Any] _ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] _ProtocolFactory = Callable[[], BaseProtocol] -_SSLContext = Union[bool, None, ssl.SSLContext] +_SSLContext = bool | None | ssl.SSLContext _TransProtPair = Tuple[BaseTransport, BaseProtocol] class Server(AbstractServer): diff --git a/stdlib/asyncio/base_subprocess.pyi b/stdlib/asyncio/base_subprocess.pyi index 096bce60f7e3..077aacf9b94e 100644 --- a/stdlib/asyncio/base_subprocess.pyi +++ b/stdlib/asyncio/base_subprocess.pyi @@ -4,7 +4,7 @@ from typing import IO, Any, Callable, Optional, Sequence, Tuple, Union from . import events, futures, protocols, transports -_File = Optional[Union[int, IO[Any]]] +_File = int | IO[Any] | None class BaseSubprocessTransport(transports.SubprocessTransport): diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 6ef9117b6491..ab04de51e006 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -20,7 +20,7 @@ _T = TypeVar("_T") _Context = Dict[str, Any] _ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] _ProtocolFactory = Callable[[], BaseProtocol] -_SSLContext = Union[bool, None, ssl.SSLContext] +_SSLContext = bool | None | ssl.SSLContext _TransProtPair = Tuple[BaseTransport, BaseProtocol] class Handle: diff --git a/stdlib/asyncio/format_helpers.pyi b/stdlib/asyncio/format_helpers.pyi index be80efe266b1..096a0990a81a 100644 --- a/stdlib/asyncio/format_helpers.pyi +++ b/stdlib/asyncio/format_helpers.pyi @@ -7,7 +7,7 @@ from typing import Any, Iterable, Union, overload class _HasWrapper: __wrapper__: _HasWrapper | FunctionType -_FuncType = Union[FunctionType, _HasWrapper, functools.partial[Any], functools.partialmethod[Any]] +_FuncType = FunctionType | _HasWrapper | functools.partial[Any] | functools.partialmethod[Any] if sys.version_info >= (3, 7): @overload diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 595222280d58..814c77f37656 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -5,7 +5,7 @@ from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, Optional from . import events, protocols, transports from .base_events import Server -_ClientConnectedCallback = Callable[[StreamReader, StreamWriter], Optional[Awaitable[None]]] +_ClientConnectedCallback = 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 d835c12af3d8..3744106769c4 100644 --- a/stdlib/asyncio/subprocess.pyi +++ b/stdlib/asyncio/subprocess.pyi @@ -8,7 +8,7 @@ from typing_extensions import Literal if sys.version_info >= (3, 8): _ExecArg = StrOrBytesPath else: - _ExecArg = Union[str, bytes] + _ExecArg = str | bytes PIPE: int STDOUT: int diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index f12dcbcd79a8..ebd8ab9dd6c2 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -18,8 +18,8 @@ _T3 = TypeVar("_T3") _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") _FT = TypeVar("_FT", bound=Future[Any]) -_FutureT = Union[Future[_T], Generator[Any, None, _T], Awaitable[_T]] -_TaskYieldType = Optional[Future[object]] +_FutureT = Future[_T] | Generator[Any, None, _T] | Awaitable[_T] +_TaskYieldType = Future[object] | None FIRST_EXCEPTION: str FIRST_COMPLETED: str diff --git a/stdlib/asyncio/trsock.pyi b/stdlib/asyncio/trsock.pyi index 33ec5d67aaf9..0dc4cabbb835 100644 --- a/stdlib/asyncio/trsock.pyi +++ b/stdlib/asyncio/trsock.pyi @@ -5,9 +5,9 @@ from typing import Any, BinaryIO, Iterable, NoReturn, Tuple, Type, Union, overlo if sys.version_info >= (3, 8): # These are based in socket, maybe move them out into _typeshed.pyi or such - _Address = Union[Tuple[Any, ...], str] + _Address = Tuple[Any, ...] | str _RetAddress = Any - _WriteBuffer = Union[bytearray, memoryview] + _WriteBuffer = bytearray | memoryview _CMSG = Tuple[int, int, bytes] class TransportSocket: def __init__(self, sock: socket.socket) -> None: ... diff --git a/stdlib/binhex.pyi b/stdlib/binhex.pyi index 02d094faf923..a8280b819539 100644 --- a/stdlib/binhex.pyi +++ b/stdlib/binhex.pyi @@ -13,7 +13,7 @@ class FInfo: Flags: int _FileInfoTuple = Tuple[str, FInfo, int, int] -_FileHandleUnion = Union[str, IO[bytes]] +_FileHandleUnion = str | IO[bytes] def getfileinfo(name: str) -> _FileInfoTuple: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 0c66c7972ca1..f6bc5ce1509d 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1173,7 +1173,7 @@ def next(__i: SupportsNext[_T]) -> _T: ... def next(__i: SupportsNext[_T], __default: _VT) -> _T | _VT: ... def oct(__number: int | SupportsIndex) -> str: ... -_OpenFile = Union[StrOrBytesPath, int] +_OpenFile = StrOrBytesPath | int _Opener = Callable[[str, int], int] # Text mode: always returns a TextIOWrapper @@ -1292,7 +1292,7 @@ class _SupportsPow3NoneOnly(Protocol[_E, _T_co]): class _SupportsPow3(Protocol[_E, _M, _T_co]): def __pow__(self, __other: _E, __modulo: _M) -> _T_co: ... -_SupportsSomeKindOfPow = Union[_SupportsPow2[Any, Any], _SupportsPow3NoneOnly[Any, Any], _SupportsPow3[Any, Any, Any]] +_SupportsSomeKindOfPow = _SupportsPow2[Any, Any] | _SupportsPow3NoneOnly[Any, Any] | _SupportsPow3[Any, Any, Any] if sys.version_info >= (3, 8): @overload diff --git a/stdlib/cgitb.pyi b/stdlib/cgitb.pyi index 7576740fc1c0..69498a7e1b53 100644 --- a/stdlib/cgitb.pyi +++ b/stdlib/cgitb.pyi @@ -2,7 +2,7 @@ from _typeshed import StrOrBytesPath from types import FrameType, TracebackType from typing import IO, Any, Callable, Optional, Tuple, Type -_ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] +_ExcInfo = Tuple[Type[BaseException] | None, BaseException | None, TracebackType | None] def reset() -> str: ... # undocumented def small(text: str) -> str: ... # undocumented diff --git a/stdlib/cmath.pyi b/stdlib/cmath.pyi index 04c2b632d411..01ec16baf79f 100644 --- a/stdlib/cmath.pyi +++ b/stdlib/cmath.pyi @@ -13,9 +13,9 @@ nanj: complex tau: float if sys.version_info >= (3, 8): - _C = Union[SupportsFloat, SupportsComplex, SupportsIndex, complex] + _C = SupportsFloat | SupportsComplex | SupportsIndex | complex else: - _C = Union[SupportsFloat, SupportsComplex, complex] + _C = SupportsFloat | SupportsComplex | complex def acos(__z: _C) -> complex: ... def acosh(__z: _C) -> complex: ... diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index 83d9d969080a..809c60aa2b66 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -180,7 +180,7 @@ class SectionProxy(MutableMapping[str, str]): # SectionProxy can have arbitrary attributes when custom converters are used def __getattr__(self, key: str) -> Callable[..., Any]: ... -class ConverterMapping(MutableMapping[str, Optional[_converter]]): +class ConverterMapping(MutableMapping[str, _converter | None]): GETTERCRE: Pattern[Any] def __init__(self, parser: RawConfigParser) -> None: ... def __getitem__(self, key: str) -> _converter: ... diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 876a3647f47c..e0306a12901f 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -25,11 +25,11 @@ if sys.version_info >= (3, 7): _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) -_T_io = TypeVar("_T_io", bound=Optional[IO[str]]) +_T_io = TypeVar("_T_io", bound=IO[str] | None) _F = TypeVar("_F", bound=Callable[..., Any]) _P = ParamSpec("_P") -_ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool] +_ExitFunc = Callable[[Type[BaseException] | None, BaseException | None, TracebackType | None], bool] _CM_EF = TypeVar("_CM_EF", AbstractContextManager[Any], _ExitFunc) class _GeneratorContextManager(AbstractContextManager[_T_co]): @@ -87,7 +87,7 @@ class ExitStack(AbstractContextManager[ExitStack]): ) -> bool: ... if sys.version_info >= (3, 7): - _ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]] + _ExitCoroFunc = Callable[[Type[BaseException] | None, BaseException | None, TracebackType | None], Awaitable[bool]] _CallbackCoroFunc = Callable[..., Awaitable[Any]] _ACM_EF = TypeVar("_ACM_EF", AbstractAsyncContextManager[Any], _ExitCoroFunc) class AsyncExitStack(AbstractAsyncContextManager[AsyncExitStack]): diff --git a/stdlib/copyreg.pyi b/stdlib/copyreg.pyi index 320097b3a204..811c5fbfad95 100644 --- a/stdlib/copyreg.pyi +++ b/stdlib/copyreg.pyi @@ -1,7 +1,7 @@ from typing import Any, Callable, Hashable, Optional, SupportsInt, Tuple, TypeVar, Union _TypeT = TypeVar("_TypeT", bound=type) -_Reduce = Union[Tuple[Callable[..., _TypeT], Tuple[Any, ...]], Tuple[Callable[..., _TypeT], Tuple[Any, ...], Optional[Any]]] +_Reduce = Tuple[Callable[..., _TypeT], Tuple[Any, ...]] | Tuple[Callable[..., _TypeT], Tuple[Any, ...], Any | None] __all__: list[str] diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index b76c59becab8..a9d5db88cfac 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -98,7 +98,7 @@ class _CData(metaclass=_CDataMeta): class _CanCastTo(_CData): ... class _PointerLike(_CanCastTo): ... -_ECT = Callable[[Optional[Type[_CData]], _FuncPointer, Tuple[_CData, ...]], _CData] +_ECT = Callable[[Type[_CData] | None, _FuncPointer, Tuple[_CData, ...]], _CData] _PF = _UnionT[Tuple[int], Tuple[int, str], Tuple[int, str, Any]] class _FuncPointer(_PointerLike, _CData): @@ -209,7 +209,7 @@ class c_byte(_SimpleCData[int]): ... class c_char(_SimpleCData[bytes]): def __init__(self, value: int | bytes = ...) -> None: ... -class c_char_p(_PointerLike, _SimpleCData[Optional[bytes]]): +class c_char_p(_PointerLike, _SimpleCData[bytes | None]): def __init__(self, value: int | bytes | None = ...) -> None: ... class c_double(_SimpleCData[float]): ... @@ -234,10 +234,10 @@ class c_uint64(_SimpleCData[int]): ... class c_ulong(_SimpleCData[int]): ... class c_ulonglong(_SimpleCData[int]): ... class c_ushort(_SimpleCData[int]): ... -class c_void_p(_PointerLike, _SimpleCData[Optional[int]]): ... +class c_void_p(_PointerLike, _SimpleCData[int | None]): ... class c_wchar(_SimpleCData[str]): ... -class c_wchar_p(_PointerLike, _SimpleCData[Optional[str]]): +class c_wchar_p(_PointerLike, _SimpleCData[str | None]): def __init__(self, value: int | str | None = ...) -> None: ... class c_bool(_SimpleCData[bool]): diff --git a/stdlib/dbm/__init__.pyi b/stdlib/dbm/__init__.pyi index 5ecacd91b4ed..e780270fbec7 100644 --- a/stdlib/dbm/__init__.pyi +++ b/stdlib/dbm/__init__.pyi @@ -3,8 +3,8 @@ from types import TracebackType from typing import Iterator, MutableMapping, Type, Union from typing_extensions import Literal -_KeyType = Union[str, bytes] -_ValueType = Union[str, bytes] +_KeyType = str | bytes +_ValueType = str | bytes _TFlags = Literal[ "r", "w", diff --git a/stdlib/dbm/dumb.pyi b/stdlib/dbm/dumb.pyi index 0a941b070754..f88142b072b6 100644 --- a/stdlib/dbm/dumb.pyi +++ b/stdlib/dbm/dumb.pyi @@ -2,8 +2,8 @@ from _typeshed import Self from types import TracebackType from typing import Iterator, MutableMapping, Type, Union -_KeyType = Union[str, bytes] -_ValueType = Union[str, bytes] +_KeyType = str | bytes +_ValueType = str | bytes error = OSError diff --git a/stdlib/dbm/gnu.pyi b/stdlib/dbm/gnu.pyi index 850c32ac0ea9..28af500fd66b 100644 --- a/stdlib/dbm/gnu.pyi +++ b/stdlib/dbm/gnu.pyi @@ -3,8 +3,8 @@ from types import TracebackType from typing import Type, TypeVar, Union, overload _T = TypeVar("_T") -_KeyType = Union[str, bytes] -_ValueType = Union[str, bytes] +_KeyType = str | bytes +_ValueType = str | bytes class error(OSError): ... diff --git a/stdlib/dbm/ndbm.pyi b/stdlib/dbm/ndbm.pyi index 7b04c5385dbe..8e27b9545627 100644 --- a/stdlib/dbm/ndbm.pyi +++ b/stdlib/dbm/ndbm.pyi @@ -3,8 +3,8 @@ from types import TracebackType from typing import Type, TypeVar, Union, overload _T = TypeVar("_T") -_KeyType = Union[str, bytes] -_ValueType = Union[str, bytes] +_KeyType = str | bytes +_ValueType = str | bytes class error(OSError): ... diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index 30c8e973348d..945394295b4c 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -2,9 +2,9 @@ import numbers from types import TracebackType from typing import Any, Container, NamedTuple, Sequence, Tuple, Type, TypeVar, Union, overload -_Decimal = Union[Decimal, int] -_DecimalNew = Union[Decimal, float, str, Tuple[int, Sequence[int], int]] -_ComparableNum = Union[Decimal, float, numbers.Rational] +_Decimal = Decimal | int +_DecimalNew = Decimal | float | str | Tuple[int, Sequence[int], int] +_ComparableNum = Decimal | float | numbers.Rational _DecimalT = TypeVar("_DecimalT", bound=Decimal) class DecimalTuple(NamedTuple): diff --git a/stdlib/difflib.pyi b/stdlib/difflib.pyi index 944a63966241..fb3e2dc7e81d 100644 --- a/stdlib/difflib.pyi +++ b/stdlib/difflib.pyi @@ -5,7 +5,7 @@ if sys.version_info >= (3, 9): from types import GenericAlias _T = TypeVar("_T") -_JunkCallback = Union[Callable[[str], bool], Callable[[str], bool]] +_JunkCallback = Callable[[str], bool] | Callable[[str], bool] class Match(NamedTuple): a: int diff --git a/stdlib/dis.pyi b/stdlib/dis.pyi index ac0632d25c9c..62050b2fe084 100644 --- a/stdlib/dis.pyi +++ b/stdlib/dis.pyi @@ -20,8 +20,8 @@ from typing import IO, Any, Callable, Iterator, NamedTuple, Union # Strictly this should not have to include Callable, but mypy doesn't use FunctionType # for functions (python/mypy#3171) -_HaveCodeType = Union[types.MethodType, types.FunctionType, types.CodeType, type, Callable[..., Any]] -_HaveCodeOrStringType = Union[_HaveCodeType, str, bytes] +_HaveCodeType = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] +_HaveCodeOrStringType = _HaveCodeType | str | bytes class Instruction(NamedTuple): opname: str diff --git a/stdlib/distutils/ccompiler.pyi b/stdlib/distutils/ccompiler.pyi index d21de4691503..f4221cacfe39 100644 --- a/stdlib/distutils/ccompiler.pyi +++ b/stdlib/distutils/ccompiler.pyi @@ -1,6 +1,6 @@ from typing import Any, Callable, Optional, Tuple, Union -_Macro = Union[Tuple[str], Tuple[str, Optional[str]]] +_Macro = 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 06a0847e4687..600704a139a2 100644 --- a/stdlib/distutils/fancy_getopt.pyi +++ b/stdlib/distutils/fancy_getopt.pyi @@ -1,6 +1,6 @@ from typing import Any, Iterable, List, Mapping, Optional, Tuple, overload -_Option = Tuple[str, Optional[str], str] +_Option = Tuple[str, str | None, str] _GR = Tuple[List[str], OptionDummy] def fancy_getopt( diff --git a/stdlib/email/_header_value_parser.pyi b/stdlib/email/_header_value_parser.pyi index a14f5a2d2238..1c493af54846 100644 --- a/stdlib/email/_header_value_parser.pyi +++ b/stdlib/email/_header_value_parser.pyi @@ -23,7 +23,7 @@ def quote_string(value: Any) -> str: ... if sys.version_info >= (3, 7): rfc2047_matcher: Pattern[str] -class TokenList(List[Union[TokenList, Terminal]]): +class TokenList(List[TokenList | Terminal]): token_type: str | None syntactic_break: bool ew_combine_allowed: bool diff --git a/stdlib/email/message.pyi b/stdlib/email/message.pyi index a1749a4cfc2e..79ae7abd3bef 100644 --- a/stdlib/email/message.pyi +++ b/stdlib/email/message.pyi @@ -6,10 +6,10 @@ from typing import Any, Generator, Iterator, List, Optional, Sequence, Tuple, Ty _T = TypeVar("_T") -_PayloadType = Union[List[Message], str, bytes] -_CharsetType = Union[Charset, str, None] -_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] -_ParamType = Union[str, Tuple[Optional[str], Optional[str], str]] +_PayloadType = List[Message] | str | bytes +_CharsetType = Charset | str | None +_ParamsType = str | None | Tuple[str, str | None, str] +_ParamType = str | Tuple[Optional[str], Optional[str], str] _HeaderType = Any class Message: diff --git a/stdlib/email/mime/application.pyi b/stdlib/email/mime/application.pyi index 11fc470e9dd1..6dd7b5225a5a 100644 --- a/stdlib/email/mime/application.pyi +++ b/stdlib/email/mime/application.pyi @@ -2,7 +2,7 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy from typing import Callable, Optional, Tuple, Union -_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] +_ParamsType = str | None | Tuple[str, str | None, str] class MIMEApplication(MIMENonMultipart): def __init__( diff --git a/stdlib/email/mime/audio.pyi b/stdlib/email/mime/audio.pyi index ee6de410bf53..9f75b40e487f 100644 --- a/stdlib/email/mime/audio.pyi +++ b/stdlib/email/mime/audio.pyi @@ -2,7 +2,7 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy from typing import Callable, Optional, Tuple, Union -_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] +_ParamsType = str | None | Tuple[str, str | None, str] class MIMEAudio(MIMENonMultipart): def __init__( diff --git a/stdlib/email/mime/base.pyi b/stdlib/email/mime/base.pyi index b88dfd492554..299e005bc8f8 100644 --- a/stdlib/email/mime/base.pyi +++ b/stdlib/email/mime/base.pyi @@ -2,7 +2,7 @@ import email.message from email.policy import Policy from typing import Optional, Tuple, Union -_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] +_ParamsType = str | None | Tuple[str, str | None, str] class MIMEBase(email.message.Message): def __init__(self, _maintype: str, _subtype: str, *, policy: Policy | None = ..., **_params: _ParamsType) -> None: ... diff --git a/stdlib/email/mime/image.pyi b/stdlib/email/mime/image.pyi index 886aa74d5fe5..3197a3c4b783 100644 --- a/stdlib/email/mime/image.pyi +++ b/stdlib/email/mime/image.pyi @@ -2,7 +2,7 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy from typing import Callable, Optional, Tuple, Union -_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] +_ParamsType = str | None | Tuple[str, str | None, str] class MIMEImage(MIMENonMultipart): def __init__( diff --git a/stdlib/email/mime/multipart.pyi b/stdlib/email/mime/multipart.pyi index 6259ddf5ab8f..074dee798427 100644 --- a/stdlib/email/mime/multipart.pyi +++ b/stdlib/email/mime/multipart.pyi @@ -3,7 +3,7 @@ from email.mime.base import MIMEBase from email.policy import Policy from typing import Optional, Sequence, Tuple, Union -_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] +_ParamsType = str | None | Tuple[str, str | None, str] class MIMEMultipart(MIMEBase): def __init__( diff --git a/stdlib/email/utils.pyi b/stdlib/email/utils.pyi index 3c07e98079fc..c2621d3c60eb 100644 --- a/stdlib/email/utils.pyi +++ b/stdlib/email/utils.pyi @@ -3,8 +3,8 @@ import sys from email.charset import Charset from typing import Optional, Tuple, Union, overload -_ParamType = Union[str, Tuple[Optional[str], Optional[str], str]] -_PDTZ = Tuple[int, int, int, int, int, int, int, int, int, Optional[int]] +_ParamType = str | Tuple[Optional[str], Optional[str], str] +_PDTZ = 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 f4ce81eaf1ce..165ea5715ede 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -19,7 +19,7 @@ _S = TypeVar("_S", bound=Type[Enum]) # # >>> Enum('Foo', names={'RED': 1, 'YELLOW': 2}) # -_EnumNames = Union[str, Iterable[str], Iterable[Iterable[Union[str, Any]]], Mapping[str, Any]] +_EnumNames = str | Iterable[str] | Iterable[Iterable[str | Any]] | Mapping[str, Any] class _EnumDict(Dict[str, Any]): def __init__(self) -> None: ... diff --git a/stdlib/fractions.pyi b/stdlib/fractions.pyi index 8de5ae20971c..e670c690dca1 100644 --- a/stdlib/fractions.pyi +++ b/stdlib/fractions.pyi @@ -4,7 +4,7 @@ from numbers import Integral, Rational, Real from typing import Type, TypeVar, Union, overload from typing_extensions import Literal -_ComparableNum = Union[int, float, Decimal, Real] +_ComparableNum = int | float | Decimal | Real _T = TypeVar("_T") if sys.version_info < (3, 9): diff --git a/stdlib/hmac.pyi b/stdlib/hmac.pyi index 440bddd7919c..93c82b7b74bd 100644 --- a/stdlib/hmac.pyi +++ b/stdlib/hmac.pyi @@ -5,7 +5,7 @@ from typing import Any, AnyStr, Callable, Union, overload # TODO more precise type for object of hashlib _Hash = Any -_DigestMod = Union[str, Callable[[], _Hash], ModuleType] +_DigestMod = str | Callable[[], _Hash] | ModuleType digest_size: None diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index 1558f6ff46e8..253a8b368ef7 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -7,7 +7,7 @@ from _typeshed import Self, WriteableBuffer from socket import socket from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, Mapping, Protocol, Type, TypeVar, Union, overload -_DataType = Union[bytes, IO[Any], Iterable[bytes], str] +_DataType = 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 4244c0c6aa0d..26c4779e72e0 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -4,7 +4,7 @@ from typing import Any, Dict, Generic, Iterable, Mapping, TypeVar, Union, overlo if sys.version_info >= (3, 9): from types import GenericAlias -_DataType = Union[str, Mapping[str, Union[str, Morsel[Any]]]] +_DataType = str | Mapping[str, str | Morsel[Any]] _T = TypeVar("_T") @overload diff --git a/stdlib/imaplib.pyi b/stdlib/imaplib.pyi index a9f19048c9ae..8755c32bdc56 100644 --- a/stdlib/imaplib.pyi +++ b/stdlib/imaplib.pyi @@ -12,7 +12,7 @@ from typing_extensions import Literal # E.g. Tuple[Literal["OK"], List[bytes]] _CommandResults = Tuple[str, List[Any]] -_AnyResponseData = Union[List[None], List[Union[bytes, Tuple[bytes, bytes]]]] +_AnyResponseData = List[None] | List[bytes | Tuple[bytes, bytes]] _list = list # conflicts with a method named "list" diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index 47a00643e485..794fb568be2a 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -15,7 +15,7 @@ from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWra from typing import IO, Any, BinaryIO, Iterator, Mapping, NoReturn, Protocol, Sequence, Union, overload from typing_extensions import Literal, runtime_checkable -_Path = Union[bytes, str] +_Path = bytes | str class Finder(metaclass=ABCMeta): ... diff --git a/stdlib/importlib/resources.pyi b/stdlib/importlib/resources.pyi index b484d7126b21..579e99fa61cd 100644 --- a/stdlib/importlib/resources.pyi +++ b/stdlib/importlib/resources.pyi @@ -9,8 +9,8 @@ if sys.version_info >= (3, 7): from types import ModuleType from typing import BinaryIO, Iterator, TextIO, Union - Package = Union[str, ModuleType] - Resource = Union[str, os.PathLike[Any]] + Package = str | ModuleType + Resource = str | os.PathLike[Any] def open_binary(package: Package, resource: Resource) -> BinaryIO: ... def open_text(package: Package, resource: Resource, encoding: str = ..., errors: str = ...) -> TextIO: ... def read_binary(package: Package, resource: Resource) -> bytes: ... diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index bd00d9ba677e..cbde9dbe0b70 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -123,7 +123,7 @@ 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 = 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/itertools.pyi b/stdlib/itertools.pyi index 1ff7ffc181ed..6380a31c4fd7 100644 --- a/stdlib/itertools.pyi +++ b/stdlib/itertools.pyi @@ -23,7 +23,7 @@ if sys.version_info >= (3, 9): _T = TypeVar("_T") _S = TypeVar("_S") _N = TypeVar("_N", int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex) -_Step = Union[int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex] +_Step = int | float | SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex Predicate = Callable[[_T], object] diff --git a/stdlib/lib2to3/pgen2/grammar.pyi b/stdlib/lib2to3/pgen2/grammar.pyi index 48cb4eae916c..2dc5a5686b64 100644 --- a/stdlib/lib2to3/pgen2/grammar.pyi +++ b/stdlib/lib2to3/pgen2/grammar.pyi @@ -2,7 +2,7 @@ from _typeshed import StrPath from typing import Dict, List, Optional, Tuple, TypeVar _P = TypeVar("_P") -_Label = Tuple[int, Optional[str]] +_Label = Tuple[int, str | None] _DFA = List[List[Tuple[int, int]]] _DFAS = Tuple[_DFA, Dict[int, int]] diff --git a/stdlib/lib2to3/pytree.pyi b/stdlib/lib2to3/pytree.pyi index eab82cbc200d..b943902103e5 100644 --- a/stdlib/lib2to3/pytree.pyi +++ b/stdlib/lib2to3/pytree.pyi @@ -2,10 +2,10 @@ from lib2to3.pgen2.grammar import Grammar from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, TypeVar, Union _P = TypeVar("_P") -_NL = Union[Node, Leaf] +_NL = Node | Leaf _Context = Tuple[str, int, int] _Results = Dict[str, _NL] -_RawNode = Tuple[int, str, _Context, Optional[List[_NL]]] +_RawNode = Tuple[int, str, _Context, List[_NL] | None] _Convert = Callable[[Grammar, _RawNode], Any] HUGE: int diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 70d6a1fda2fc..f1e66ba06027 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -9,11 +9,11 @@ from types import FrameType, TracebackType from typing import Any, ClassVar, Generic, Optional, Pattern, TextIO, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal -_SysExcInfoType = Union[Tuple[Type[BaseException], BaseException, Optional[TracebackType]], Tuple[None, None, None]] -_ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException] -_ArgsType = Union[Tuple[object, ...], Mapping[str, object]] -_FilterType = Union[Filter, Callable[[LogRecord], int]] -_Level = Union[int, str] +_SysExcInfoType = 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["%", "{", "$"] raiseExceptions: bool diff --git a/stdlib/lzma.pyi b/stdlib/lzma.pyi index e1da3024c4ac..ecf488defa69 100644 --- a/stdlib/lzma.pyi +++ b/stdlib/lzma.pyi @@ -6,7 +6,7 @@ from typing_extensions import Literal, final _OpenBinaryWritingMode = Literal["w", "wb", "x", "xb", "a", "ab"] _OpenTextWritingMode = Literal["wt", "xt", "at"] -_PathOrFile = Union[StrOrBytesPath, IO[bytes]] +_PathOrFile = StrOrBytesPath | IO[bytes] _FilterChain = Sequence[Mapping[str, Any]] diff --git a/stdlib/mailbox.pyi b/stdlib/mailbox.pyi index ffd9c3005cec..b10cb2f6e2e5 100644 --- a/stdlib/mailbox.pyi +++ b/stdlib/mailbox.pyi @@ -25,7 +25,7 @@ if sys.version_info >= (3, 9): _T = TypeVar("_T") _MessageT = TypeVar("_MessageT", bound=Message) -_MessageData = Union[email.message.Message, bytes, str, IO[str], IO[bytes]] +_MessageData = 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 9eaa771ed3d3..084b705bdd2c 100644 --- a/stdlib/mailcap.pyi +++ b/stdlib/mailcap.pyi @@ -1,6 +1,6 @@ from typing import Dict, Mapping, Sequence, Union -_Cap = Dict[str, Union[str, int]] +_Cap = Dict[str, str | int] def findmatch( caps: Mapping[str, list[_Cap]], MIMEtype: str, key: str = ..., filename: str = ..., plist: Sequence[str] = ... diff --git a/stdlib/math.pyi b/stdlib/math.pyi index d5e6f99dfa68..367ad6076095 100644 --- a/stdlib/math.pyi +++ b/stdlib/math.pyi @@ -4,7 +4,7 @@ from typing import Iterable, SupportsFloat, Union, overload from typing_extensions import SupportsIndex if sys.version_info >= (3, 8): - _SupportsFloatOrIndex = Union[SupportsFloat, SupportsIndex] + _SupportsFloatOrIndex = SupportsFloat | SupportsIndex else: _SupportsFloatOrIndex = SupportsFloat diff --git a/stdlib/msilib/sequence.pyi b/stdlib/msilib/sequence.pyi index 123d232886f7..6d5d45ef117f 100644 --- a/stdlib/msilib/sequence.pyi +++ b/stdlib/msilib/sequence.pyi @@ -3,7 +3,7 @@ from typing import List, Optional, Tuple if sys.platform == "win32": - _SequenceType = List[Tuple[str, Optional[str], int]] + _SequenceType = List[Tuple[str, str | None, int]] AdminExecuteSequence: _SequenceType AdminUISequence: _SequenceType diff --git a/stdlib/multiprocessing/__init__.pyi b/stdlib/multiprocessing/__init__.pyi index 000fed79f3e4..69437de379e3 100644 --- a/stdlib/multiprocessing/__init__.pyi +++ b/stdlib/multiprocessing/__init__.pyi @@ -54,7 +54,7 @@ _SemaphoreType = synchronize.Semaphore # be identical (modulo self). # Synchronization primitives -_LockLike = Union[synchronize.Lock, synchronize.RLock] +_LockLike = 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 56ea5c7c0b0b..d76de7bac282 100644 --- a/stdlib/multiprocessing/connection.pyi +++ b/stdlib/multiprocessing/connection.pyi @@ -8,7 +8,7 @@ if sys.version_info >= (3, 8): from typing import SupportsIndex # https://docs.python.org/3/library/multiprocessing.html#address-formats -_Address = Union[str, Tuple[str, int]] +_Address = str | Tuple[str, int] class _ConnectionBase: if sys.version_info >= (3, 8): diff --git a/stdlib/multiprocessing/context.pyi b/stdlib/multiprocessing/context.pyi index e65a387819bc..3d008baa68f5 100644 --- a/stdlib/multiprocessing/context.pyi +++ b/stdlib/multiprocessing/context.pyi @@ -11,7 +11,7 @@ from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase from typing import Any, Type, TypeVar, Union, overload from typing_extensions import Literal -_LockLike = Union[synchronize.Lock, synchronize.RLock] +_LockLike = 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 4ef3d095911f..baaa29df629e 100644 --- a/stdlib/multiprocessing/dummy/connection.pyi +++ b/stdlib/multiprocessing/dummy/connection.pyi @@ -5,7 +5,7 @@ from typing import Any, Tuple, Type, Union families: list[None] -_Address = Union[str, Tuple[str, int]] +_Address = str | Tuple[str, int] class Connection(object): _in: Any diff --git a/stdlib/multiprocessing/synchronize.pyi b/stdlib/multiprocessing/synchronize.pyi index c32c9aafe9a4..c6f6c96fcffe 100644 --- a/stdlib/multiprocessing/synchronize.pyi +++ b/stdlib/multiprocessing/synchronize.pyi @@ -4,7 +4,7 @@ from contextlib import AbstractContextManager from multiprocessing.context import BaseContext from typing import Any, Callable, Union -_LockLike = Union[Lock, RLock] +_LockLike = Lock | RLock class Barrier(threading.Barrier): def __init__( diff --git a/stdlib/nntplib.pyi b/stdlib/nntplib.pyi index 508b5f679bc3..f52e33baca83 100644 --- a/stdlib/nntplib.pyi +++ b/stdlib/nntplib.pyi @@ -5,7 +5,7 @@ import sys from _typeshed import Self from typing import IO, Any, Iterable, NamedTuple, Tuple, Union -_File = Union[IO[bytes], bytes, str, None] +_File = IO[bytes] | bytes | str | None class NNTPError(Exception): response: str diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index c68a587671a2..41eabbe98910 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -341,7 +341,7 @@ def listdir(path: int) -> list[str]: ... @overload def listdir(path: PathLike[str]) -> list[str]: ... -_FdOrAnyPath = Union[int, StrOrBytesPath] +_FdOrAnyPath = int | StrOrBytesPath @final class DirEntry(Generic[AnyStr]): @@ -778,12 +778,12 @@ _ExecVArgs = Union[ List[bytes], List[str], List[PathLike[Any]], - List[Union[bytes, str]], - List[Union[bytes, PathLike[Any]]], - List[Union[str, PathLike[Any]]], - List[Union[bytes, str, PathLike[Any]]], + List[bytes | str], + List[bytes | PathLike[Any]], + List[str | PathLike[Any]], + List[bytes | str | PathLike[Any]], ] -_ExecEnv = Union[Mapping[bytes, Union[bytes, str]], Mapping[str, Union[bytes, str]]] +_ExecEnv = Mapping[bytes, Union[bytes, str]] | Mapping[str, Union[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 cef1ffe9eb9b..7faf94f350bb 100644 --- a/stdlib/pickle.pyi +++ b/stdlib/pickle.pyi @@ -22,7 +22,7 @@ if sys.version_info >= (3, 8): def __init__(self, buffer: Any) -> None: ... def raw(self) -> memoryview: ... def release(self) -> None: ... - _BufferCallback = Optional[Callable[[PickleBuffer], Any]] + _BufferCallback = Callable[[PickleBuffer], Any] | None def dump( obj: Any, file: _WritableFileobj, @@ -60,7 +60,7 @@ _reducedtype = Union[ str, Tuple[Callable[..., Any], Tuple[Any, ...]], Tuple[Callable[..., Any], Tuple[Any, ...], Any], - Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator[Any]]], + Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None], Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator[Any]], Optional[Iterator[Any]]], ] diff --git a/stdlib/pstats.pyi b/stdlib/pstats.pyi index e8256f9f98ab..63621eb3cb82 100644 --- a/stdlib/pstats.pyi +++ b/stdlib/pstats.pyi @@ -4,7 +4,7 @@ from cProfile import Profile as _cProfile from profile import Profile from typing import IO, Any, Iterable, Tuple, TypeVar, Union, overload -_Selector = Union[str, float, int] +_Selector = str | float | int _T = TypeVar("_T", bound=Stats) if sys.version_info >= (3, 7): diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index b60ef8f9bcb3..77ae62190632 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -4,7 +4,7 @@ from types import MethodType, ModuleType, TracebackType from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, Optional, Tuple, Type # the return type of sys.exc_info(), used by ErrorDuringImport.__init__ -_Exc_Info = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] +_Exc_Info = Tuple[Type[BaseException] | None, BaseException | None, TracebackType | None] __author__: str __date__: str diff --git a/stdlib/pyexpat/__init__.pyi b/stdlib/pyexpat/__init__.pyi index 6a3d6cd56791..3f02ab8b3d44 100644 --- a/stdlib/pyexpat/__init__.pyi +++ b/stdlib/pyexpat/__init__.pyi @@ -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, Optional[str], Tuple[Any, ...]] +_Model = Tuple[int, int, str | None, Tuple[Any, ...]] @final class XMLParserType(object): diff --git a/stdlib/re.pyi b/stdlib/re.pyi index 01a60d170c50..7980571eea6a 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -45,7 +45,7 @@ U = RegexFlag.U UNICODE = RegexFlag.UNICODE T = RegexFlag.T TEMPLATE = RegexFlag.TEMPLATE -_FlagsType = Union[int, RegexFlag] +_FlagsType = int | RegexFlag if sys.version_info < (3, 7): # undocumented diff --git a/stdlib/readline.pyi b/stdlib/readline.pyi index 2de749b2c216..8b7381225941 100644 --- a/stdlib/readline.pyi +++ b/stdlib/readline.pyi @@ -1,8 +1,8 @@ from _typeshed import StrOrBytesPath from typing import Callable, Optional, Sequence -_CompleterT = Optional[Callable[[str, int], Optional[str]]] -_CompDispT = Optional[Callable[[str, Sequence[str], int], None]] +_CompleterT = Callable[[str, int], str | None] | None +_CompDispT = Callable[[str, Sequence[str], int], None] | None def parse_and_bind(__string: str) -> None: ... def read_init_file(__filename: StrOrBytesPath | None = ...) -> None: ... diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index f4c492caccaf..fc6a3dce8118 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -46,7 +46,7 @@ else: def rmtree(path: bytes | StrPath, ignore_errors: bool = ..., onerror: Callable[[Any, Any, Any], Any] | None = ...) -> None: ... -_CopyFn = Union[Callable[[str, str], None], Callable[[StrPath, StrPath], None]] +_CopyFn = Callable[[str, str], None] | Callable[[StrPath, StrPath], None] if sys.version_info >= (3, 9): def move(src: StrPath, dst: StrPath, copy_function: _CopyFn = ...) -> _PathReturn: ... diff --git a/stdlib/signal.pyi b/stdlib/signal.pyi index 80fe5cac268e..c845c23a6459 100644 --- a/stdlib/signal.pyi +++ b/stdlib/signal.pyi @@ -58,8 +58,8 @@ class Handlers(IntEnum): SIG_DFL: Handlers SIG_IGN: Handlers -_SIGNUM = Union[int, Signals] -_HANDLER = Union[Callable[[int, Optional[FrameType]], Any], int, Handlers, None] +_SIGNUM = int | Signals +_HANDLER = Callable[[int, FrameType | None], Any] | int | Handlers | None def default_int_handler(signum: int, frame: FrameType | None) -> None: ... def getsignal(__signalnum: _SIGNUM) -> _HANDLER: ... diff --git a/stdlib/smtplib.pyi b/stdlib/smtplib.pyi index a6f7d07ee7ec..d7e00dba87a5 100644 --- a/stdlib/smtplib.pyi +++ b/stdlib/smtplib.pyi @@ -9,7 +9,7 @@ from typing import Any, Dict, Pattern, Protocol, Sequence, Tuple, Type, Union, o _Reply = Tuple[int, bytes] _SendErrs = Dict[str, _Reply] # Should match source_address for socket.create_connection -_SourceAddress = Tuple[Union[bytearray, bytes, str], int] +_SourceAddress = Tuple[bytearray | bytes | str, int] SMTP_PORT: int SMTP_SSL_PORT: int diff --git a/stdlib/socketserver.pyi b/stdlib/socketserver.pyi index c64408cfab07..7b3a28c72603 100644 --- a/stdlib/socketserver.pyi +++ b/stdlib/socketserver.pyi @@ -5,8 +5,8 @@ from socket import socket as _socket from typing import Any, BinaryIO, Callable, ClassVar, Tuple, Type, TypeVar, Union _T = TypeVar("_T") -_RequestType = Union[_socket, Tuple[bytes, _socket]] -_AddressType = Union[Tuple[str, int], str] +_RequestType = _socket | Tuple[bytes, _socket] +_AddressType = Tuple[str, int] | str class BaseServer: address_family: int diff --git a/stdlib/sre_parse.pyi b/stdlib/sre_parse.pyi index 8a60c2f990d6..4f1038854f06 100644 --- a/stdlib/sre_parse.pyi +++ b/stdlib/sre_parse.pyi @@ -34,11 +34,11 @@ if sys.version_info >= (3, 8): else: Pattern = _State -_OpSubpatternType = Tuple[Optional[int], int, int, SubPattern] +_OpSubpatternType = Tuple[int | None, int, int, SubPattern] _OpGroupRefExistsType = Tuple[int, SubPattern, SubPattern] _OpInType = List[Tuple[_NIC, int]] _OpBranchType = Tuple[None, List[SubPattern]] -_AvType = Union[_OpInType, _OpBranchType, Iterable[SubPattern], _OpGroupRefExistsType, _OpSubpatternType] +_AvType = _OpInType | _OpBranchType | Iterable[SubPattern] | _OpGroupRefExistsType | _OpSubpatternType _CodeType = Tuple[_NIC, _AvType] class SubPattern: @@ -82,8 +82,8 @@ class Tokenizer: def fix_flags(src: str | bytes, flags: int) -> int: ... -_TemplateType = Tuple[List[Tuple[int, int]], List[Optional[str]]] -_TemplateByteType = Tuple[List[Tuple[int, int]], List[Optional[bytes]]] +_TemplateType = Tuple[List[Tuple[int, int]], List[str | None]] +_TemplateByteType = 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 489327fd4406..d8530599cf41 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -7,12 +7,12 @@ from typing_extensions import Literal, TypedDict _PCTRTT = Tuple[Tuple[str, str], ...] _PCTRTTT = Tuple[_PCTRTT, ...] -_PeerCertRetDictType = Dict[str, Union[str, _PCTRTTT, _PCTRTT]] -_PeerCertRetType = Union[_PeerCertRetDictType, bytes, None] -_EnumRetType = List[Tuple[bytes, str, Union[Set[str], bool]]] -_PasswordType = Union[Callable[[], Union[str, bytes]], str, bytes] +_PeerCertRetDictType = Dict[str, str | _PCTRTTT | _PCTRTT] +_PeerCertRetType = _PeerCertRetDictType | bytes | None +_EnumRetType = List[Tuple[bytes, str, Set[str] | bool]] +_PasswordType = Callable[[], str | bytes] | str | bytes -_SrvnmeCbType = Callable[[Union[SSLSocket, SSLObject], Optional[str], SSLSocket], Optional[int]] +_SrvnmeCbType = Callable[[SSLSocket | SSLObject, str | None, SSLSocket], int | None] class _Cipher(TypedDict): aead: bool diff --git a/stdlib/statistics.pyi b/stdlib/statistics.pyi index 908d6adaf45d..04bdcc676d01 100644 --- a/stdlib/statistics.pyi +++ b/stdlib/statistics.pyi @@ -6,7 +6,7 @@ from typing import Any, Hashable, Iterable, NamedTuple, Sequence, SupportsFloat, _T = TypeVar("_T") # Most functions in this module accept homogeneous collections of one of these types -_Number = Union[float, Decimal, Fraction] +_Number = float | Decimal | Fraction _NumberT = TypeVar("_NumberT", float, Decimal, Fraction) # Used in mode, multimode diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index fce517745ee6..8c9f91c6941a 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -21,18 +21,18 @@ if sys.version_info >= (3, 9): # reveal_type(x) # bytes, based on the overloads # except TimeoutError as e: # reveal_type(e.cmd) # Any, but morally is _CMD -_FILE = Union[None, int, IO[Any]] -_TXT = Union[bytes, str] +_FILE = None | int | IO[Any] +_TXT = bytes | str if sys.version_info >= (3, 8): - _CMD = Union[StrOrBytesPath, Sequence[StrOrBytesPath]] + _CMD = StrOrBytesPath | Sequence[StrOrBytesPath] else: # Python 3.6 doesn't support _CMD being a single PathLike. # See: https://bugs.python.org/issue31961 - _CMD = Union[_TXT, Sequence[StrOrBytesPath]] + _CMD = _TXT | Sequence[StrOrBytesPath] if sys.platform == "win32": _ENV = Mapping[str, str] else: - _ENV = Union[Mapping[bytes, StrOrBytesPath], Mapping[str, StrOrBytesPath]] + _ENV = Mapping[bytes, StrOrBytesPath] | Mapping[str, StrOrBytesPath] _T = TypeVar("_T") diff --git a/stdlib/sunau.pyi b/stdlib/sunau.pyi index 8393136aa795..f6479939f0c8 100644 --- a/stdlib/sunau.pyi +++ b/stdlib/sunau.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Self from typing import IO, Any, NamedTuple, NoReturn, Union -_File = Union[str, IO[bytes]] +_File = str | IO[bytes] class Error(Exception): ... diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index 274e4b90fd6e..8603040941bd 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -25,7 +25,7 @@ _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]] +_OptExcInfo = _ExcInfo | Tuple[None, None, None] # Intentionally omits one deprecated and one optional method of `importlib.abc.MetaPathFinder` class _MetaPathFinder(Protocol): @@ -187,7 +187,7 @@ _ProfileFunc = Callable[[FrameType, str, Any], Any] def getprofile() -> _ProfileFunc | None: ... def setprofile(profilefunc: _ProfileFunc | None) -> None: ... -_TraceFunc = Callable[[FrameType, str, Any], Optional[Callable[[FrameType, str, Any], Any]]] +_TraceFunc = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None] def gettrace() -> _TraceFunc | None: ... def settrace(tracefunc: _TraceFunc | None) -> None: ... @@ -237,7 +237,7 @@ if sys.version_info >= (3, 8): def addaudithook(hook: Callable[[str, Tuple[Any, ...]], Any]) -> None: ... def audit(__event: str, *args: Any) -> None: ... -_AsyncgenHook = Optional[Callable[[AsyncGenerator[Any, Any]], None]] +_AsyncgenHook = Callable[[AsyncGenerator[Any, Any]], None] | None class _asyncgen_hooks(Tuple[_AsyncgenHook, _AsyncgenHook]): firstiter: _AsyncgenHook diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index 119c111bc4e1..21f75784a746 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -13,7 +13,7 @@ TMP_MAX: int tempdir: str | None template: str -_DirT = Union[AnyStr, os.PathLike[AnyStr]] +_DirT = AnyStr | os.PathLike[AnyStr] if sys.version_info >= (3, 8): @overload diff --git a/stdlib/termios.pyi b/stdlib/termios.pyi index ed8522dccc51..80e378c5ecb2 100644 --- a/stdlib/termios.pyi +++ b/stdlib/termios.pyi @@ -1,7 +1,7 @@ from _typeshed import FileDescriptorLike from typing import Any, List, Union -_Attr = List[Union[int, List[Union[bytes, int]]]] +_Attr = List[int | List[bytes | int]] # TODO constants not really documented B0: int diff --git a/stdlib/threading.pyi b/stdlib/threading.pyi index d6ac9f7251c2..9a8d26fee48e 100644 --- a/stdlib/threading.pyi +++ b/stdlib/threading.pyi @@ -3,7 +3,7 @@ from types import FrameType, TracebackType from typing import Any, Callable, Iterable, Mapping, Optional, Type, TypeVar # TODO recursive type -_TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]] +_TF = Callable[[FrameType, str, Any], Callable[..., Any] | None] _PF = Callable[[FrameType, str, Any], None] _T = TypeVar("_T") diff --git a/stdlib/timeit.pyi b/stdlib/timeit.pyi index d82dd80598dc..c3c6fd6bed0a 100644 --- a/stdlib/timeit.pyi +++ b/stdlib/timeit.pyi @@ -1,7 +1,7 @@ from typing import IO, Any, Callable, Sequence, Union _Timer = Callable[[], float] -_Stmt = Union[str, Callable[[], Any]] +_Stmt = str | Callable[[], Any] default_timer: _Timer diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index fd21aaa1cc6e..88df1520876a 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -86,16 +86,16 @@ EXCEPTION = _tkinter.EXCEPTION # 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 = Union[str, Callable[[], Any]] # return value is returned from Button.invoke() +_ButtonCommand = str | Callable[[], Any] # 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 +_Cursor = str | Tuple[str] | Tuple[str, str] | Tuple[str, str, str] | Tuple[str, str, str, str] # manual page: Tk_GetCursor _EntryValidateCommand = Union[ Callable[[], bool], str, List[str], Tuple[str, ...] ] # example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P'] _GridIndex = Union[int, str, Literal["all"]] -_ImageSpec = Union[_Image, str] # str can be from e.g. tkinter.image_names() +_ImageSpec = _Image | str # str can be from e.g. tkinter.image_names() _Padding = Union[ _ScreenUnits, Tuple[_ScreenUnits], @@ -104,9 +104,9 @@ _Padding = Union[ Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits], ] _Relief = Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] # manual page: Tk_GetRelief -_ScreenUnits = Union[str, float] # manual page: Tk_GetPixels -_XYScrollCommand = Union[str, Callable[[float, float], Any]] # -xscrollcommand and -yscrollcommand in 'options' manual page -_TakeFocusValue = Union[int, Literal[""], Callable[[str], Optional[bool]]] # -takefocus in manual page named 'options' +_ScreenUnits = str | float # 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' class EventType(str, Enum): Activate: str @@ -1606,7 +1606,7 @@ class Checkbutton(Widget): def select(self): ... def toggle(self): ... -_EntryIndex = Union[str, int] # "INDICES" in manual page +_EntryIndex = str | int # "INDICES" in manual page class Entry(Widget, XView): def __init__( @@ -1964,7 +1964,7 @@ class Listbox(Widget, XView, YView): def itemconfigure(self, index, cnf: Any | None = ..., **kw): ... itemconfig: Any -_MenuIndex = Union[str, int] +_MenuIndex = str | int class Menu(Widget): def __init__( @@ -2650,7 +2650,7 @@ class Scrollbar(Widget): def get(self): ... def set(self, first, last): ... -_TextIndex = Union[_tkinter.Tcl_Obj, str, float, Misc] +_TextIndex = _tkinter.Tcl_Obj | str | float | Misc class Text(Widget, XView, YView): def __init__( diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 0cb806fddd52..2c1f8d75a9f8 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -914,7 +914,7 @@ class _TreeviewColumnDict(TypedDict): anchor: tkinter._Anchor id: str -_TreeviewColumnId = Union[int, str] # manual page: "COLUMN IDENTIFIERS" +_TreeviewColumnId = 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 a8294adb653f..512fd6c85e73 100644 --- a/stdlib/tokenize.pyi +++ b/stdlib/tokenize.pyi @@ -26,7 +26,7 @@ class TokenInfo(_TokenInfo): def exact_type(self) -> int: ... # Backwards compatible tokens can be sequences of a shorter length too -_Token = Union[TokenInfo, Sequence[Union[int, str, _Position]]] +_Token = TokenInfo | Sequence[int | str | _Position] class TokenError(Exception): ... class StopTokenizing(Exception): ... # undocumented diff --git a/stdlib/trace.pyi b/stdlib/trace.pyi index bab75c9ada8d..53891a7a931a 100644 --- a/stdlib/trace.pyi +++ b/stdlib/trace.pyi @@ -7,7 +7,7 @@ from typing_extensions import ParamSpec _T = TypeVar("_T") _P = ParamSpec("_P") _localtrace = Callable[[types.FrameType, str, Any], Callable[..., Any]] -_fileModuleFunction = Tuple[str, Optional[str], str] +_fileModuleFunction = Tuple[str, str | None, str] class CoverageResults: def __init__( diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index f09a3cc70ade..ff4b5b4d4a9e 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -3,7 +3,7 @@ from _typeshed import SupportsWrite from types import FrameType, TracebackType from typing import IO, Any, Generator, Iterable, Iterator, List, Mapping, Optional, Tuple, Type, overload -_PT = Tuple[str, int, str, Optional[str]] +_PT = 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 4666bd1565a0..e425a864c1aa 100644 --- a/stdlib/tracemalloc.pyi +++ b/stdlib/tracemalloc.pyi @@ -43,7 +43,7 @@ class Frame: def __init__(self, frame: _FrameTupleT) -> None: ... if sys.version_info >= (3, 9): - _TraceTupleT = Union[Tuple[int, int, Sequence[_FrameTupleT], Optional[int]], Tuple[int, int, Sequence[_FrameTupleT]]] + _TraceTupleT = Tuple[int, int, Sequence[_FrameTupleT], int | None] | Tuple[int, int, Sequence[_FrameTupleT]] else: _TraceTupleT = Tuple[int, int, Sequence[_FrameTupleT]] diff --git a/stdlib/tty.pyi b/stdlib/tty.pyi index c0dc418e9933..47132006edeb 100644 --- a/stdlib/tty.pyi +++ b/stdlib/tty.pyi @@ -1,6 +1,6 @@ from typing import IO, Union -_FD = Union[int, IO[str]] +_FD = int | IO[str] # XXX: Undocumented integer constants IFLAG: int diff --git a/stdlib/turtle.pyi b/stdlib/turtle.pyi index 8542fc8bfa24..3df64e911662 100644 --- a/stdlib/turtle.pyi +++ b/stdlib/turtle.pyi @@ -5,13 +5,13 @@ from typing import Any, Callable, ClassVar, Dict, Sequence, Tuple, TypeVar, Unio # 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 = str | Tuple[float, float, float] _AnyColor = Any # TODO: Replace this with a TypedDict once it becomes standardized. _PenState = Dict[str, Any] -_Speed = Union[str, float] +_Speed = str | float _PolygonCoords = Sequence[Tuple[float, float]] # TODO: Type this more accurately diff --git a/stdlib/unittest/result.pyi b/stdlib/unittest/result.pyi index 20c43cf38aa4..fe7ac36d205f 100644 --- a/stdlib/unittest/result.pyi +++ b/stdlib/unittest/result.pyi @@ -2,7 +2,7 @@ import unittest.case from types import TracebackType from typing import Any, Callable, TextIO, Tuple, Type, TypeVar, Union -_SysExcInfoType = Union[Tuple[Type[BaseException], BaseException, TracebackType], Tuple[None, None, None]] +_SysExcInfoType = Tuple[Type[BaseException], BaseException, TracebackType] | Tuple[None, None, None] _F = TypeVar("_F", bound=Callable[..., Any]) diff --git a/stdlib/unittest/suite.pyi b/stdlib/unittest/suite.pyi index 396b46eadf5a..1a925e6d9753 100644 --- a/stdlib/unittest/suite.pyi +++ b/stdlib/unittest/suite.pyi @@ -2,7 +2,7 @@ import unittest.case import unittest.result from typing import Iterable, Iterator, Union -_TestType = Union[unittest.case.TestCase, TestSuite] +_TestType = unittest.case.TestCase | TestSuite class BaseTestSuite(Iterable[_TestType]): _tests: list[unittest.case.TestCase] diff --git a/stdlib/urllib/parse.pyi b/stdlib/urllib/parse.pyi index a2467e96c43c..e974215e9eb7 100644 --- a/stdlib/urllib/parse.pyi +++ b/stdlib/urllib/parse.pyi @@ -4,7 +4,7 @@ from typing import Any, AnyStr, Callable, Generic, Mapping, NamedTuple, Sequence if sys.version_info >= (3, 9): from types import GenericAlias -_Str = Union[bytes, str] +_Str = bytes | str uses_relative: list[str] uses_netloc: list[str] diff --git a/stdlib/uu.pyi b/stdlib/uu.pyi index aacd458c02c7..fd7e83dc0f6a 100644 --- a/stdlib/uu.pyi +++ b/stdlib/uu.pyi @@ -1,7 +1,7 @@ import sys from typing import BinaryIO, Union -_File = Union[str, BinaryIO] +_File = str | BinaryIO class Error(Exception): ... diff --git a/stdlib/wave.pyi b/stdlib/wave.pyi index 3ce1b88a6835..edd9e1042043 100644 --- a/stdlib/wave.pyi +++ b/stdlib/wave.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Self from typing import IO, Any, BinaryIO, NamedTuple, NoReturn, Union -_File = Union[str, IO[bytes]] +_File = str | IO[bytes] class Error(Exception): ... diff --git a/stdlib/winreg.pyi b/stdlib/winreg.pyi index 5fff1104e246..b449062c2f78 100644 --- a/stdlib/winreg.pyi +++ b/stdlib/winreg.pyi @@ -3,7 +3,7 @@ from types import TracebackType from typing import Any, Type, Union from typing_extensions import final -_KeyType = Union[HKEYType, int] +_KeyType = HKEYType | int def CloseKey(__hkey: _KeyType) -> None: ... def ConnectRegistry(__computer_name: str | None, __key: _KeyType) -> HKEYType: ... diff --git a/stdlib/wsgiref/handlers.pyi b/stdlib/wsgiref/handlers.pyi index ac1e56b7664e..26b268dcc242 100644 --- a/stdlib/wsgiref/handlers.pyi +++ b/stdlib/wsgiref/handlers.pyi @@ -6,7 +6,7 @@ from .headers import Headers from .types import ErrorStream, InputStream, StartResponse, WSGIApplication, WSGIEnvironment from .util import FileWrapper -_exc_info = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] +_exc_info = 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/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index 530c1988e743..69125f1796c4 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -14,8 +14,8 @@ PROCESSING_INSTRUCTION: Literal["PROCESSING_INSTRUCTION"] IGNORABLE_WHITESPACE: Literal["IGNORABLE_WHITESPACE"] CHARACTERS: Literal["CHARACTERS"] -_DocumentFactory = Union[DOMImplementation, None] -_Node = Union[Document, Element, Text] +_DocumentFactory = DOMImplementation | None +_Node = Document | Element | Text _Event = Tuple[ Literal[ diff --git a/stdlib/xml/dom/xmlbuilder.pyi b/stdlib/xml/dom/xmlbuilder.pyi index 2738d735e73f..49d72ba6dc1a 100644 --- a/stdlib/xml/dom/xmlbuilder.pyi +++ b/stdlib/xml/dom/xmlbuilder.pyi @@ -16,13 +16,13 @@ from xml.dom.minidom import Node # probably the same as `Options.errorHandler`? # Maybe `xml.sax.handler.ErrorHandler`? -_DOMBuilderErrorHandlerType = Optional[Any] +_DOMBuilderErrorHandlerType = Any | None # probably some kind of IO... -_DOMInputSourceCharacterStreamType = Optional[Any] +_DOMInputSourceCharacterStreamType = Any | None # probably a string?? -_DOMInputSourceStringDataType = Optional[Any] +_DOMInputSourceStringDataType = Any | None # probably a string?? -_DOMInputSourceEncodingType = Optional[Any] +_DOMInputSourceEncodingType = Any | None class Options: namespaces: int diff --git a/stdlib/xml/etree/ElementTree.pyi b/stdlib/xml/etree/ElementTree.pyi index 6ee578b9aa81..f9b073176437 100644 --- a/stdlib/xml/etree/ElementTree.pyi +++ b/stdlib/xml/etree/ElementTree.pyi @@ -20,7 +20,7 @@ from typing import ( from typing_extensions import Literal, SupportsIndex _T = TypeVar("_T") -_File = Union[StrOrBytesPath, FileDescriptor, IO[Any]] +_File = StrOrBytesPath | FileDescriptor | IO[Any] VERSION: str diff --git a/stdlib/xmlrpc/client.pyi b/stdlib/xmlrpc/client.pyi index b715e8b2928a..ab84bc546582 100644 --- a/stdlib/xmlrpc/client.pyi +++ b/stdlib/xmlrpc/client.pyi @@ -12,10 +12,10 @@ from typing_extensions import Literal class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... -_DateTimeComparable = Union[DateTime, datetime, str, _SupportsTimeTuple] -_Marshallable = Union[None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime, DateTime, Binary] -_XMLDate = Union[int, datetime, Tuple[int, ...], time.struct_time] -_HostType = Union[Tuple[str, Dict[str, str]], str] +_DateTimeComparable = DateTime | datetime | str | _SupportsTimeTuple +_Marshallable = None | bool | int | float | str | bytes | Tuple[Any, ...] | List[Any] | Dict[Any, Any] | datetime | DateTime | Binary +_XMLDate = int | datetime | Tuple[int, ...] | time.struct_time +_HostType = 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 f84253cef568..50af0f90dff0 100644 --- a/stdlib/xmlrpc/server.pyi +++ b/stdlib/xmlrpc/server.pyi @@ -7,7 +7,7 @@ from typing import Any, Callable, Dict, Iterable, List, Mapping, Pattern, Protoc from xmlrpc.client import Fault # TODO: Recursive type on tuple, list, dict -_Marshallable = Union[None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime] +_Marshallable = 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 +30,7 @@ class _DispatchArity4(Protocol): class _DispatchArityN(Protocol): def __call__(self, *args: _Marshallable) -> _Marshallable: ... -_DispatchProtocol = Union[_DispatchArity0, _DispatchArity1, _DispatchArity2, _DispatchArity3, _DispatchArity4, _DispatchArityN] +_DispatchProtocol = _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 581d2b72a664..2376dd697494 100644 --- a/stdlib/zipapp.pyi +++ b/stdlib/zipapp.pyi @@ -2,7 +2,7 @@ import sys from pathlib import Path from typing import BinaryIO, Callable, Union -_Path = Union[str, Path, BinaryIO] +_Path = str | Path | BinaryIO class ZipAppError(ValueError): ... diff --git a/stubs/Pillow/PIL/Image.pyi b/stubs/Pillow/PIL/Image.pyi index 4d7113496b60..ad7823647b0a 100644 --- a/stubs/Pillow/PIL/Image.pyi +++ b/stubs/Pillow/PIL/Image.pyi @@ -22,7 +22,7 @@ _Box = Tuple[int, int, int, int] _ConversionMatrix = Union[ Tuple[float, float, float, float], Tuple[float, float, float, float, float, float, float, float, float, float, float, float], ] -_Color = Union[float, Tuple[float, ...]] +_Color = float | Tuple[float, ...] class _Writeable(SupportsWrite[bytes], Protocol): def seek(self, __offset: int) -> Any: ... diff --git a/stubs/Pillow/PIL/ImageColor.pyi b/stubs/Pillow/PIL/ImageColor.pyi index 8e0db5292296..172376697712 100644 --- a/stubs/Pillow/PIL/ImageColor.pyi +++ b/stubs/Pillow/PIL/ImageColor.pyi @@ -1,7 +1,7 @@ from typing import Tuple, Union -_RGB = Union[Tuple[int, int, int], Tuple[int, int, int, int]] -_Ink = Union[str, int, _RGB] +_RGB = Tuple[int, int, int] | Tuple[int, int, int, int] +_Ink = str | int | _RGB _GreyScale = Tuple[int, int] def getrgb(color: _Ink) -> _RGB: ... diff --git a/stubs/Pillow/PIL/ImageDraw.pyi b/stubs/Pillow/PIL/ImageDraw.pyi index 5ca32e3b3c8f..8e3ae38494c3 100644 --- a/stubs/Pillow/PIL/ImageDraw.pyi +++ b/stubs/Pillow/PIL/ImageDraw.pyi @@ -6,7 +6,7 @@ from .Image import Image from .ImageColor import _Ink from .ImageFont import _Font -_XY = Sequence[Union[float, Tuple[float, float]]] +_XY = Sequence[float | Tuple[float, float]] _Outline = Any class ImageDraw: diff --git a/stubs/Pillow/PIL/TiffTags.pyi b/stubs/Pillow/PIL/TiffTags.pyi index 5559e169bd5c..a9ee9ddb95bb 100644 --- a/stubs/Pillow/PIL/TiffTags.pyi +++ b/stubs/Pillow/PIL/TiffTags.pyi @@ -36,7 +36,7 @@ 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]]] +_TagTuple = 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 ee2e4ba89aaa..0076660e1573 100644 --- a/stubs/PyMySQL/pymysql/converters.pyi +++ b/stubs/PyMySQL/pymysql/converters.pyi @@ -4,7 +4,7 @@ from collections.abc import Callable, Mapping, Sequence from decimal import Decimal from typing import Any, Optional, Type, TypeVar -_EscaperMapping = Optional[Mapping[Type[object], Callable[..., str]]] +_EscaperMapping = 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 e503cba6949a..7050dda1b1df 100644 --- a/stubs/PyYAML/yaml/constructor.pyi +++ b/stubs/PyYAML/yaml/constructor.pyi @@ -3,7 +3,7 @@ from typing import Any, Pattern, Union from yaml.error import MarkedYAMLError from yaml.nodes import ScalarNode -_Scalar = Union[str, int, float, bool, None] +_Scalar = str | int | float | bool | None class ConstructorError(MarkedYAMLError): ... diff --git a/stubs/PyYAML/yaml/cyaml.pyi b/stubs/PyYAML/yaml/cyaml.pyi index d70b44148bec..38e62d4c3592 100644 --- a/stubs/PyYAML/yaml/cyaml.pyi +++ b/stubs/PyYAML/yaml/cyaml.pyi @@ -9,7 +9,7 @@ from .resolver import BaseResolver, Resolver __all__ = ["CBaseLoader", "CSafeLoader", "CFullLoader", "CUnsafeLoader", "CLoader", "CBaseDumper", "CSafeDumper", "CDumper"] -_Readable = SupportsRead[Union[str, bytes]] +_Readable = SupportsRead[str | bytes] class CBaseLoader(CParser, BaseConstructor, BaseResolver): def __init__(self, stream: str | bytes | _Readable) -> None: ... diff --git a/stubs/Pygments/pygments/lexers/__init__.pyi b/stubs/Pygments/pygments/lexers/__init__.pyi index 23a2966c3890..97da2632b798 100644 --- a/stubs/Pygments/pygments/lexers/__init__.pyi +++ b/stubs/Pygments/pygments/lexers/__init__.pyi @@ -4,7 +4,7 @@ from typing import Any, Tuple, Union from pygments.lexer import Lexer, LexerMeta -_OpenFile = Union[StrOrBytesPath, int] # copy/pasted from builtins.pyi +_OpenFile = StrOrBytesPath | int # copy/pasted from builtins.pyi # TODO: use lower-case tuple once mypy updated def get_all_lexers() -> Iterator[tuple[str, Tuple[str, ...], Tuple[str, ...], Tuple[str, ...]]]: ... diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index b48884c4430e..85b1256e6e61 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -3,7 +3,7 @@ from _typeshed import StrOrBytesPath from os import stat_result from typing import Sequence, Union, overload -_FdOrAnyPath = Union[int, StrOrBytesPath] +_FdOrAnyPath = int | StrOrBytesPath async def stat(path: _FdOrAnyPath, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> stat_result: ... async def rename( diff --git a/stubs/aiofiles/aiofiles/threadpool/__init__.pyi b/stubs/aiofiles/aiofiles/threadpool/__init__.pyi index a43b5ab0defb..27e451dd44f2 100644 --- a/stubs/aiofiles/aiofiles/threadpool/__init__.pyi +++ b/stubs/aiofiles/aiofiles/threadpool/__init__.pyi @@ -14,7 +14,7 @@ from ..base import AiofilesContextManager from .binary import AsyncBufferedIOBase, AsyncBufferedReader, AsyncFileIO, _UnknownAsyncBinaryIO from .text import AsyncTextIOWrapper -_OpenFile = Union[StrOrBytesPath, int] +_OpenFile = StrOrBytesPath | int _Opener = Callable[[str, int], int] # Text mode: always returns AsyncTextIOWrapper diff --git a/stubs/beautifulsoup4/bs4/element.pyi b/stubs/beautifulsoup4/bs4/element.pyi index 9e7b2d1c2a35..7d88ddc1e1c3 100644 --- a/stubs/beautifulsoup4/bs4/element.pyi +++ b/stubs/beautifulsoup4/bs4/element.pyi @@ -28,10 +28,10 @@ class ContentMetaAttributeValue(AttributeValueWithCharsetSubstitution): _PageElementT = TypeVar("_PageElementT", bound=PageElement) # The wrapping Union[] can be removed once mypy fully supports | in type aliases. -_SimpleStrainable = Union[str, bool, None, bytes, Pattern[str], Callable[[str], bool], Callable[[Tag], bool]] -_Strainable = Union[_SimpleStrainable, Iterable[_SimpleStrainable]] -_SimpleNormalizedStrainable = Union[str, bool, None, Pattern[str], Callable[[str], bool], Callable[[Tag], bool]] -_NormalizedStrainable = Union[_SimpleNormalizedStrainable, Iterable[_SimpleNormalizedStrainable]] +_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] class PageElement: parent: Tag | None diff --git a/stubs/bleach/bleach/sanitizer.pyi b/stubs/bleach/bleach/sanitizer.pyi index 0966af2096d6..96ae5a93eb1d 100644 --- a/stubs/bleach/bleach/sanitizer.pyi +++ b/stubs/bleach/bleach/sanitizer.pyi @@ -39,8 +39,8 @@ class Cleaner(object): def clean(self, text: str) -> str: ... _AttributeFilter = Callable[[str, str, str], bool] -_AttributeDict = Union[Dict[str, Union[List[str], _AttributeFilter]], Dict[str, List[str]], Dict[str, _AttributeFilter]] -_Attributes = Union[_AttributeFilter, _AttributeDict, List[str]] +_AttributeDict = Dict[str, List[str] | _AttributeFilter] | Dict[str, List[str]] | Dict[str, _AttributeFilter] +_Attributes = _AttributeFilter | _AttributeDict | List[str] def attribute_filter_factory(attributes: _Attributes) -> _AttributeFilter: ... diff --git a/stubs/colorama/colorama/ansitowin32.pyi b/stubs/colorama/colorama/ansitowin32.pyi index 117fe8f6265c..36839ec8a6e7 100644 --- a/stubs/colorama/colorama/ansitowin32.pyi +++ b/stubs/colorama/colorama/ansitowin32.pyi @@ -19,8 +19,8 @@ class StreamWrapper: @property def closed(self) -> bool: ... -_WinTermCall = Callable[[Optional[int], bool, bool], None] -_WinTermCallDict = Dict[int, Union[Tuple[_WinTermCall], Tuple[_WinTermCall, int], Tuple[_WinTermCall, int, bool]]] +_WinTermCall = Callable[[int | None, bool, bool], None] +_WinTermCallDict = 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 820e0ee50a42..18768c4ddb7c 100644 --- a/stubs/croniter/croniter.pyi +++ b/stubs/croniter/croniter.pyi @@ -2,7 +2,7 @@ import datetime from typing import Any, Iterator, Text, Tuple, Type, TypeVar, Union from typing_extensions import Literal -_RetType = Union[Type[float], Type[datetime.datetime]] +_RetType = Type[float] | Type[datetime.datetime] _SelfT = TypeVar("_SelfT", bound=croniter) class CroniterError(ValueError): ... diff --git a/stubs/docopt/docopt.pyi b/stubs/docopt/docopt.pyi index 7f7bba6a7e69..f4f4b9025be5 100644 --- a/stubs/docopt/docopt.pyi +++ b/stubs/docopt/docopt.pyi @@ -2,7 +2,7 @@ from typing import Any, Iterable, Union __version__: str -_Argv = Union[Iterable[str], str] +_Argv = Iterable[str] | str def docopt( doc: str, argv: _Argv | None = ..., help: bool = ..., version: Any | None = ..., options_first: bool = ... diff --git a/stubs/freezegun/freezegun/api.pyi b/stubs/freezegun/freezegun/api.pyi index d2aaaf4a19ea..56084228479a 100644 --- a/stubs/freezegun/freezegun/api.pyi +++ b/stubs/freezegun/freezegun/api.pyi @@ -4,7 +4,7 @@ from numbers import Real from typing import Any, Type, TypeVar, Union, overload _T = TypeVar("_T") -_Freezable = Union[str, datetime, date, timedelta] +_Freezable = str | datetime | date | timedelta class TickingDateTimeFactory(object): def __init__(self, time_to_freeze: datetime, start: datetime) -> None: ... diff --git a/stubs/paramiko/paramiko/common.pyi b/stubs/paramiko/paramiko/common.pyi index 26c09d4f3e40..a4678986d8ee 100644 --- a/stubs/paramiko/paramiko/common.pyi +++ b/stubs/paramiko/paramiko/common.pyi @@ -109,7 +109,7 @@ else: class _SupportsAsBytes(Protocol): def asbytes(self) -> bytes: ... -_LikeBytes = Union[bytes, Text, _SupportsAsBytes] +_LikeBytes = bytes | Text | _SupportsAsBytes def asbytes(s: _LikeBytes) -> bytes: ... diff --git a/stubs/pyOpenSSL/OpenSSL/crypto.pyi b/stubs/pyOpenSSL/OpenSSL/crypto.pyi index abfb1e3ab85d..81bd0606aef4 100644 --- a/stubs/pyOpenSSL/OpenSSL/crypto.pyi +++ b/stubs/pyOpenSSL/OpenSSL/crypto.pyi @@ -5,7 +5,7 @@ from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPubl from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey from cryptography.x509 import Certificate, CertificateRevocationList, CertificateSigningRequest -_Key = Union[DSAPrivateKey, DSAPublicKey, RSAPrivateKey, RSAPublicKey] +_Key = DSAPrivateKey | DSAPublicKey | RSAPrivateKey | RSAPublicKey FILETYPE_PEM: int FILETYPE_ASN1: int diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 6849056b1d47..23587f929b13 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -68,8 +68,8 @@ paMacCoreStreamInfo: PaMacCoreStreamInfo # Auxiliary types _ChannelMap = Sequence[int] -_PaHostApiInfo = Mapping[str, Union[str, int]] -_PaDeviceInfo = Mapping[str, Union[str, int, float]] +_PaHostApiInfo = Mapping[str, str | int] +_PaDeviceInfo = Mapping[str, str | int | float] _StreamCallback = Callable[[Optional[bytes], int, Mapping[str, float], int], Tuple[Optional[bytes], int]] def get_format_from_width(width: int, unsigned: bool = ...) -> int: ... diff --git a/stubs/pysftp/pysftp/__init__.pyi b/stubs/pysftp/pysftp/__init__.pyi index 58e051248fc2..91809756f840 100644 --- a/stubs/pysftp/pysftp/__init__.pyi +++ b/stubs/pysftp/pysftp/__init__.pyi @@ -31,7 +31,7 @@ class CnOpts: def get_hostkey(self, host: str) -> paramiko.PKey: ... _Callback = Callable[[int, int], Any] -_Path = Union[Text, bytes] +_Path = Text | bytes class Connection: def __init__( diff --git a/stubs/python-dateutil/dateutil/parser/__init__.pyi b/stubs/python-dateutil/dateutil/parser/__init__.pyi index a408f649bc54..bfb7f1f2779e 100644 --- a/stubs/python-dateutil/dateutil/parser/__init__.pyi +++ b/stubs/python-dateutil/dateutil/parser/__init__.pyi @@ -3,7 +3,7 @@ from typing import IO, Any, Mapping, Text, Union from .isoparser import isoparse as isoparse, isoparser as isoparser -_FileOrStr = Union[bytes, Text, IO[str], IO[Any]] +_FileOrStr = 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 ed24582d43c4..18614065ffdc 100644 --- a/stubs/python-dateutil/dateutil/parser/isoparser.pyi +++ b/stubs/python-dateutil/dateutil/parser/isoparser.pyi @@ -2,8 +2,8 @@ from _typeshed import SupportsRead from datetime import date, datetime, time, tzinfo from typing import Text, Union -_Readable = SupportsRead[Union[Text, bytes]] -_TakesAscii = Union[Text, bytes, _Readable] +_Readable = SupportsRead[Text | bytes] +_TakesAscii = 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 dad7fa15a0b3..e58f580f551e 100644 --- a/stubs/python-dateutil/dateutil/tz/tz.pyi +++ b/stubs/python-dateutil/dateutil/tz/tz.pyi @@ -4,7 +4,7 @@ from typing import IO, Any, Text, TypeVar, Union from ..relativedelta import relativedelta from ._common import _tzinfo as _tzinfo, enfold as enfold, tzname_in_python2 as tzname_in_python2, tzrangebase as tzrangebase -_FileObj = Union[str, Text, IO[str], IO[Text]] +_FileObj = str | Text | IO[str] | IO[Text] _DT = TypeVar("_DT", bound=datetime.datetime) ZERO: datetime.timedelta diff --git a/stubs/redis/redis/client.pyi b/stubs/redis/redis/client.pyi index 90655ab8f910..916eed1f24a0 100644 --- a/stubs/redis/redis/client.pyi +++ b/stubs/redis/redis/client.pyi @@ -27,11 +27,11 @@ from .retry import Retry _ScoreCastFuncReturn = TypeVar("_ScoreCastFuncReturn") -_Value = Union[bytes, float, int, str] -_Key = Union[str, bytes] +_Value = bytes | float | int | str +_Key = str | bytes # Lib returns str or bytes depending on value of decode_responses -_StrType = TypeVar("_StrType", bound=Union[str, bytes]) +_StrType = TypeVar("_StrType", bound=str | bytes) _VT = TypeVar("_VT") _T = TypeVar("_T") diff --git a/stubs/redis/redis/commands/core.pyi b/stubs/redis/redis/commands/core.pyi index 49b69575250d..2ef6e8a3b3f2 100644 --- a/stubs/redis/redis/commands/core.pyi +++ b/stubs/redis/redis/commands/core.pyi @@ -6,7 +6,7 @@ from typing_extensions import Literal from ..client import _Key, _Value _ScoreCastFuncReturn = TypeVar("_ScoreCastFuncReturn") -_StrType = TypeVar("_StrType", bound=Union[str, bytes]) +_StrType = TypeVar("_StrType", bound=str | bytes) class CoreCommands(Generic[_StrType]): def acl_cat(self, category: str | None = ...) -> list[str]: ... diff --git a/stubs/requests/requests/sessions.pyi b/stubs/requests/requests/sessions.pyi index 89ba100c02af..d50653963b91 100644 --- a/stubs/requests/requests/sessions.pyi +++ b/stubs/requests/requests/sessions.pyi @@ -43,19 +43,19 @@ class SessionRedirectMixin: def rebuild_proxies(self, prepared_request, proxies): ... def should_strip_auth(self, old_url, new_url): ... -_Data = Union[None, Text, bytes, Mapping[str, Any], Mapping[Text, Any], Iterable[Tuple[Text, Optional[Text]]], IO[Any]] +_Data = None | Text | bytes | Mapping[str, Any] | Mapping[Text, Any] | Iterable[Tuple[Text, Text | None]] | IO[Any] _Hook = Callable[[Response], Any] _Hooks = MutableMapping[Text, List[_Hook]] -_HooksInput = MutableMapping[Text, Union[Iterable[_Hook], _Hook]] +_HooksInput = MutableMapping[Text, Iterable[_Hook] | _Hook] -_ParamsMappingKeyType = Union[Text, bytes, int, float] -_ParamsMappingValueType = Union[Text, bytes, int, float, Iterable[Union[Text, bytes, int, float]], None] +_ParamsMappingKeyType = Text | bytes | int | float +_ParamsMappingValueType = Text | bytes | int | float | Iterable[Text | bytes | int | float] | None _Params = Union[ SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType], Tuple[_ParamsMappingKeyType, _ParamsMappingValueType], Iterable[Tuple[_ParamsMappingKeyType, _ParamsMappingValueType]], - Union[Text, bytes], + Text | bytes, ] _TextMapping = MutableMapping[Text, Text] _SessionT = TypeVar("_SessionT", bound=Session) diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index 9f121f3340fc..16cfdce4aea1 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -8,11 +8,11 @@ LegacyVersion = Any # from packaging.version Version = Any # from packaging.version _T = TypeVar("_T") -_NestedStr = Union[str, Iterable[Union[str, Iterable[Any]]]] -_InstallerType = Callable[[Requirement], Optional[Distribution]] -_EPDistType = Union[Distribution, Requirement, str] -_MetadataType = Optional[IResourceProvider] -_PkgReqType = Union[str, Requirement] +_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] diff --git a/stubs/simplejson/simplejson/__init__.pyi b/stubs/simplejson/simplejson/__init__.pyi index 798a77062823..d374f70dc3f4 100644 --- a/stubs/simplejson/simplejson/__init__.pyi +++ b/stubs/simplejson/simplejson/__init__.pyi @@ -5,7 +5,7 @@ from simplejson.encoder import JSONEncoder as JSONEncoder, JSONEncoderForHTML as from simplejson.raw_json import RawJSON as RawJSON from simplejson.scanner import JSONDecodeError as JSONDecodeError -_LoadsString = Union[Text, bytes, bytearray] +_LoadsString = 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/tabulate/tabulate.pyi b/stubs/tabulate/tabulate.pyi index 8b5efde5bf08..eafcfb352c06 100644 --- a/stubs/tabulate/tabulate.pyi +++ b/stubs/tabulate/tabulate.pyi @@ -18,8 +18,8 @@ class DataRow(NamedTuple): sep: str end: str -_TableFormatLine = Union[None, Line, Callable[[List[int], List[str]], str]] -_TableFormatRow = Union[None, DataRow, Callable[[List[Any], List[int], List[str]], str]] +_TableFormatLine = None | Line | Callable[[List[int], List[str]], str] +_TableFormatRow = None | DataRow | Callable[[List[Any], List[int], List[str]], str] class TableFormat(NamedTuple): lineabove: _TableFormatLine diff --git a/stubs/toml/toml.pyi b/stubs/toml/toml.pyi index 3f8580b33376..3c672e648228 100644 --- a/stubs/toml/toml.pyi +++ b/stubs/toml/toml.pyi @@ -7,7 +7,7 @@ if sys.version_info >= (3, 6): elif sys.version_info >= (3, 4): import pathlib - _PathLike = Union[StrPath, pathlib.PurePath] + _PathLike = StrPath | pathlib.PurePath else: _PathLike = StrPath From c1ac28543759e6481a0a5eddf459b86b7a348176 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 16 Dec 2021 19:53:04 +0200 Subject: [PATCH 03/11] manual fixes --- stdlib/calendar.pyi | 2 +- stdlib/email/message.pyi | 2 +- stdlib/email/utils.pyi | 2 +- stdlib/netrc.pyi | 2 +- stdlib/os/__init__.pyi | 13 ++----------- stdlib/pickle.pyi | 8 +------- stdlib/tkinter/__init__.pyi | 23 +++++++++++------------ stdlib/tkinter/font.pyi | 14 +++++++------- stdlib/typing.pyi | 26 ++++++++++++-------------- stubs/Pillow/PIL/Image.pyi | 4 +--- stubs/pyaudio/pyaudio.pyi | 2 +- stubs/requests/requests/sessions.pyi | 7 +------ 12 files changed, 40 insertions(+), 65 deletions(-) diff --git a/stdlib/calendar.pyi b/stdlib/calendar.pyi index 26073fb7281b..bcdde53118e9 100644 --- a/stdlib/calendar.pyi +++ b/stdlib/calendar.pyi @@ -3,7 +3,7 @@ import sys from time import struct_time from typing import Any, Iterable, Optional, Sequence, Tuple -_LocaleType = Tuple[Optional[str], Optional[str]] +_LocaleType = Tuple[str | None, str | None] class IllegalMonthError(ValueError): def __init__(self, month: int) -> None: ... diff --git a/stdlib/email/message.pyi b/stdlib/email/message.pyi index 79ae7abd3bef..fe6d7cc92c3e 100644 --- a/stdlib/email/message.pyi +++ b/stdlib/email/message.pyi @@ -9,7 +9,7 @@ _T = TypeVar("_T") _PayloadType = List[Message] | str | bytes _CharsetType = Charset | str | None _ParamsType = str | None | Tuple[str, str | None, str] -_ParamType = str | Tuple[Optional[str], Optional[str], str] +_ParamType = str | Tuple[str | None, str | None, str] _HeaderType = Any class Message: diff --git a/stdlib/email/utils.pyi b/stdlib/email/utils.pyi index c2621d3c60eb..b0ddf83289de 100644 --- a/stdlib/email/utils.pyi +++ b/stdlib/email/utils.pyi @@ -3,7 +3,7 @@ import sys from email.charset import Charset from typing import Optional, Tuple, Union, overload -_ParamType = str | Tuple[Optional[str], Optional[str], str] +_ParamType = str | Tuple[str | None, str | None, str] _PDTZ = Tuple[int, int, int, int, int, int, int, int, int, int | None] def quote(str: str) -> str: ... diff --git a/stdlib/netrc.pyi b/stdlib/netrc.pyi index b8eac307740a..737a97814ca9 100644 --- a/stdlib/netrc.pyi +++ b/stdlib/netrc.pyi @@ -8,7 +8,7 @@ class NetrcParseError(Exception): def __init__(self, msg: str, filename: StrOrBytesPath | None = ..., lineno: int | None = ...) -> None: ... # (login, account, password) tuple -_NetrcTuple = Tuple[str, Optional[str], Optional[str]] +_NetrcTuple = Tuple[str, str | None, str | None] class netrc: hosts: dict[str, _NetrcTuple] diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 41eabbe98910..bbdff748b5bd 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -773,17 +773,8 @@ 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 = Union[ - Tuple[StrOrBytesPath, ...], - List[bytes], - List[str], - List[PathLike[Any]], - List[bytes | str], - List[bytes | PathLike[Any]], - List[str | PathLike[Any]], - List[bytes | str | PathLike[Any]], -] -_ExecEnv = Mapping[bytes, Union[bytes, str]] | Mapping[str, Union[bytes, str]] +_ExecVArgs = Tuple[StrOrBytesPath, ...]| List[bytes]| List[str]| List[PathLike[Any]]| List[bytes | str]| List[bytes | PathLike[Any]]| List[str | PathLike[Any]]| List[bytes | str | PathLike[Any]] +_ExecEnv = 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 7faf94f350bb..8272ef7e91cc 100644 --- a/stdlib/pickle.pyi +++ b/stdlib/pickle.pyi @@ -56,13 +56,7 @@ class PickleError(Exception): ... class PicklingError(PickleError): ... class UnpicklingError(PickleError): ... -_reducedtype = Union[ - str, - Tuple[Callable[..., Any], Tuple[Any, ...]], - Tuple[Callable[..., Any], Tuple[Any, ...], Any], - Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None], - Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator[Any]], Optional[Iterator[Any]]], -] +_reducedtype = str | Tuple[Callable[..., Any], Tuple[Any, ...]] | Tuple[Callable[..., Any], Tuple[Any, ...], Any] | Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None]| Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None] class Pickler: fast: bool diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 88df1520876a..e7dfaae88407 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -91,22 +91,21 @@ _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 = str | Tuple[str] | Tuple[str, str] | Tuple[str, str, str] | Tuple[str, str, str, str] # manual page: Tk_GetCursor -_EntryValidateCommand = Union[ - Callable[[], bool], str, List[str], Tuple[str, ...] -] # example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P'] -_GridIndex = Union[int, str, Literal["all"]] +# Example: entry['invalidcommand'] = [entry.register(print), '%P'] +_EntryValidateCommand = Callable[[], bool]| str| List[str]| Tuple[str, ...] +_GridIndex = int | str| Literal["all"] _ImageSpec = _Image | str # str can be from e.g. tkinter.image_names() -_Padding = Union[ - _ScreenUnits, - Tuple[_ScreenUnits], - Tuple[_ScreenUnits, _ScreenUnits], - Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits], - Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits], -] +_Padding = ( + _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 # 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' +_TakeFocusValue = int | Literal[""] | Callable[[str], bool | None] # -takefocus in manual page named 'options' class EventType(str, Enum): Activate: str diff --git a/stdlib/tkinter/font.pyi b/stdlib/tkinter/font.pyi index fccc0fbf1f0a..3b3765ece3b2 100644 --- a/stdlib/tkinter/font.pyi +++ b/stdlib/tkinter/font.pyi @@ -9,17 +9,17 @@ ROMAN: Literal["roman"] BOLD: Literal["bold"] ITALIC: Literal["italic"] -_FontDescription = Union[ +_FontDescription = ( # "Helvetica 12" - str, + str # A font object constructed in Python - Font, + | Font # ("Helvetica", 12, BOLD) - List[Any], - Tuple[Any, ...], + | List[Any] + | Tuple[Any, ...] # A font object constructed in Tcl - _tkinter.Tcl_Obj, -] + | _tkinter.Tcl_Obj +) class _FontDict(TypedDict): family: str diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 8c2d3157bdb3..81f03ca2d64b 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -638,21 +638,19 @@ class Pattern(Generic[AnyStr]): # Functions if sys.version_info >= (3, 7): - _get_type_hints_obj_allowed_types = Union[ - object, - Callable[..., Any], - FunctionType, - BuiltinFunctionType, - MethodType, - ModuleType, - WrapperDescriptorType, - MethodWrapperType, - MethodDescriptorType, - ] + _get_type_hints_obj_allowed_types = ( + object + | Callable[..., Any] + | FunctionType + | BuiltinFunctionType + | MethodType + | ModuleType + | WrapperDescriptorType + | MethodWrapperType + | MethodDescriptorType + ) else: - _get_type_hints_obj_allowed_types = Union[ - object, Callable[..., Any], FunctionType, BuiltinFunctionType, MethodType, ModuleType, - ] + _get_type_hints_obj_allowed_types = object | Callable[..., Any] | FunctionType | BuiltinFunctionType | MethodType | ModuleType if sys.version_info >= (3, 9): def get_type_hints( diff --git a/stubs/Pillow/PIL/Image.pyi b/stubs/Pillow/PIL/Image.pyi index ad7823647b0a..5af6714842b2 100644 --- a/stubs/Pillow/PIL/Image.pyi +++ b/stubs/Pillow/PIL/Image.pyi @@ -19,9 +19,7 @@ _Resample = Literal[0, 1, 2, 3, 4, 5] _Size = Tuple[int, int] _Box = Tuple[int, int, int, int] -_ConversionMatrix = Union[ - Tuple[float, float, float, float], Tuple[float, float, float, float, float, float, float, float, float, float, float, float], -] +_ConversionMatrix = Tuple[float, float, float, float]| Tuple[float, float, float, float, float, float, float, float, float, float, float, float] _Color = float | Tuple[float, ...] class _Writeable(SupportsWrite[bytes], Protocol): diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 23587f929b13..ec13cc385bd8 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -70,7 +70,7 @@ paMacCoreStreamInfo: PaMacCoreStreamInfo _ChannelMap = Sequence[int] _PaHostApiInfo = Mapping[str, str | int] _PaDeviceInfo = Mapping[str, str | int | float] -_StreamCallback = Callable[[Optional[bytes], int, Mapping[str, float], int], Tuple[Optional[bytes], int]] +_StreamCallback = 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/requests/requests/sessions.pyi b/stubs/requests/requests/sessions.pyi index d50653963b91..74d66ffe5183 100644 --- a/stubs/requests/requests/sessions.pyi +++ b/stubs/requests/requests/sessions.pyi @@ -51,12 +51,7 @@ _HooksInput = MutableMapping[Text, Iterable[_Hook] | _Hook] _ParamsMappingKeyType = Text | bytes | int | float _ParamsMappingValueType = Text | bytes | int | float | Iterable[Text | bytes | int | float] | None -_Params = Union[ - SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType], - Tuple[_ParamsMappingKeyType, _ParamsMappingValueType], - Iterable[Tuple[_ParamsMappingKeyType, _ParamsMappingValueType]], - Text | bytes, -] +_Params = SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType]| Tuple[_ParamsMappingKeyType, _ParamsMappingValueType]| Iterable[Tuple[_ParamsMappingKeyType, _ParamsMappingValueType]]| Text | bytes _TextMapping = MutableMapping[Text, Text] _SessionT = TypeVar("_SessionT", bound=Session) From 885094b366f0923ae2022525f86c2419ff300b53 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 16 Dec 2021 19:58:00 +0200 Subject: [PATCH 04/11] clean imports based on pyright output, with script import sys for line in sys.stdin: filename, lineno, _, message = line.split(":") filename = filename.strip() lineno = int(lineno) - 1 to_remove = message.split('"')[1] lines = open(filename).readlines() if lines[lineno].count(to_remove) == 1: lines[lineno] = lines[lineno].replace(to_remove + ",", "") lines[lineno] = lines[lineno].replace(to_remove, "") open(filename, "w").writelines(lines) --- stdlib/_codecs.pyi | 2 +- stdlib/_csv.pyi | 2 +- stdlib/_curses.pyi | 2 +- stdlib/_dummy_threading.pyi | 2 +- stdlib/_socket.pyi | 2 +- stdlib/_thread.pyi | 2 +- stdlib/_typeshed/__init__.pyi | 2 +- stdlib/aifc.pyi | 2 +- stdlib/array.pyi | 2 +- stdlib/asyncio/base_events.pyi | 2 +- stdlib/asyncio/base_subprocess.pyi | 2 +- stdlib/asyncio/events.pyi | 2 +- stdlib/asyncio/format_helpers.pyi | 2 +- stdlib/asyncio/streams.pyi | 2 +- stdlib/asyncio/subprocess.pyi | 2 +- stdlib/asyncio/tasks.pyi | 2 +- stdlib/asyncio/trsock.pyi | 2 +- stdlib/binhex.pyi | 2 +- stdlib/builtins.pyi | 2 +- stdlib/calendar.pyi | 2 +- stdlib/cgitb.pyi | 2 +- stdlib/cmath.pyi | 2 +- stdlib/configparser.pyi | 2 +- stdlib/contextlib.pyi | 2 +- stdlib/copyreg.pyi | 2 +- stdlib/ctypes/__init__.pyi | 2 +- stdlib/dbm/__init__.pyi | 2 +- stdlib/dbm/dumb.pyi | 2 +- stdlib/dbm/gnu.pyi | 2 +- stdlib/dbm/ndbm.pyi | 2 +- stdlib/decimal.pyi | 2 +- stdlib/difflib.pyi | 2 +- stdlib/dis.pyi | 2 +- stdlib/distutils/ccompiler.pyi | 2 +- stdlib/distutils/fancy_getopt.pyi | 2 +- stdlib/email/_header_value_parser.pyi | 2 +- stdlib/email/message.pyi | 2 +- stdlib/email/mime/application.pyi | 2 +- stdlib/email/mime/audio.pyi | 2 +- stdlib/email/mime/base.pyi | 2 +- stdlib/email/mime/image.pyi | 2 +- stdlib/email/mime/multipart.pyi | 2 +- stdlib/email/utils.pyi | 2 +- stdlib/enum.pyi | 2 +- stdlib/fractions.pyi | 2 +- stdlib/hmac.pyi | 2 +- stdlib/http/client.pyi | 2 +- stdlib/http/cookies.pyi | 2 +- stdlib/imaplib.pyi | 2 +- stdlib/importlib/abc.pyi | 2 +- stdlib/importlib/resources.pyi | 2 +- stdlib/inspect.pyi | 2 +- stdlib/itertools.pyi | 2 +- stdlib/lib2to3/pgen2/grammar.pyi | 2 +- stdlib/lib2to3/pytree.pyi | 2 +- stdlib/logging/__init__.pyi | 2 +- stdlib/lzma.pyi | 2 +- stdlib/mailbox.pyi | 2 +- stdlib/mailcap.pyi | 2 +- stdlib/math.pyi | 2 +- stdlib/msilib/sequence.pyi | 2 +- stdlib/multiprocessing/__init__.pyi | 2 +- stdlib/multiprocessing/connection.pyi | 2 +- stdlib/multiprocessing/context.pyi | 2 +- stdlib/multiprocessing/dummy/connection.pyi | 2 +- stdlib/multiprocessing/synchronize.pyi | 2 +- stdlib/netrc.pyi | 2 +- stdlib/nntplib.pyi | 2 +- stdlib/os/__init__.pyi | 2 +- stdlib/pickle.pyi | 2 +- stdlib/pstats.pyi | 2 +- stdlib/pydoc.pyi | 2 +- stdlib/pyexpat/__init__.pyi | 2 +- stdlib/re.pyi | 2 +- stdlib/readline.pyi | 2 +- stdlib/shutil.pyi | 2 +- stdlib/signal.pyi | 2 +- stdlib/smtplib.pyi | 2 +- stdlib/socketserver.pyi | 2 +- stdlib/sre_parse.pyi | 2 +- stdlib/ssl.pyi | 2 +- stdlib/statistics.pyi | 2 +- stdlib/subprocess.pyi | 2 +- stdlib/sunau.pyi | 2 +- stdlib/sys.pyi | 4 ++-- stdlib/tempfile.pyi | 2 +- stdlib/termios.pyi | 2 +- stdlib/threading.pyi | 2 +- stdlib/timeit.pyi | 2 +- stdlib/tkinter/__init__.pyi | 2 +- stdlib/tkinter/font.pyi | 2 +- stdlib/tkinter/ttk.pyi | 2 +- stdlib/tokenize.pyi | 2 +- stdlib/trace.pyi | 2 +- stdlib/traceback.pyi | 2 +- stdlib/tracemalloc.pyi | 2 +- stdlib/tty.pyi | 2 +- stdlib/turtle.pyi | 2 +- stdlib/unittest/result.pyi | 2 +- stdlib/unittest/suite.pyi | 2 +- stdlib/urllib/parse.pyi | 2 +- stdlib/uu.pyi | 2 +- stdlib/wave.pyi | 2 +- stdlib/winreg.pyi | 2 +- stdlib/wsgiref/handlers.pyi | 2 +- stdlib/xml/dom/pulldom.pyi | 2 +- stdlib/xml/dom/xmlbuilder.pyi | 2 +- stdlib/xml/etree/ElementTree.pyi | 2 +- stdlib/xmlrpc/client.pyi | 2 +- stdlib/xmlrpc/server.pyi | 2 +- stdlib/zipapp.pyi | 2 +- stubs/Pillow/PIL/Image.pyi | 2 +- stubs/Pillow/PIL/ImageColor.pyi | 2 +- stubs/Pillow/PIL/ImageDraw.pyi | 2 +- stubs/Pillow/PIL/TiffTags.pyi | 2 +- stubs/PyMySQL/pymysql/converters.pyi | 2 +- stubs/PyYAML/yaml/constructor.pyi | 2 +- stubs/PyYAML/yaml/cyaml.pyi | 2 +- stubs/Pygments/pygments/lexers/__init__.pyi | 2 +- stubs/aiofiles/aiofiles/os.pyi | 2 +- stubs/aiofiles/aiofiles/threadpool/__init__.pyi | 2 +- stubs/beautifulsoup4/bs4/element.pyi | 2 +- stubs/bleach/bleach/sanitizer.pyi | 2 +- stubs/colorama/colorama/ansitowin32.pyi | 2 +- stubs/croniter/croniter.pyi | 2 +- stubs/docopt/docopt.pyi | 2 +- stubs/freezegun/freezegun/api.pyi | 2 +- stubs/paramiko/paramiko/common.pyi | 2 +- stubs/pyOpenSSL/OpenSSL/crypto.pyi | 2 +- stubs/pyaudio/pyaudio.pyi | 2 +- stubs/pysftp/pysftp/__init__.pyi | 2 +- stubs/python-dateutil/dateutil/parser/__init__.pyi | 2 +- stubs/python-dateutil/dateutil/parser/isoparser.pyi | 2 +- stubs/python-dateutil/dateutil/tz/tz.pyi | 2 +- stubs/redis/redis/client.pyi | 2 +- stubs/redis/redis/commands/core.pyi | 2 +- stubs/requests/requests/sessions.pyi | 2 +- stubs/setuptools/pkg_resources/__init__.pyi | 2 +- stubs/simplejson/simplejson/__init__.pyi | 2 +- stubs/tabulate/tabulate.pyi | 2 +- stubs/toml/toml.pyi | 2 +- 141 files changed, 142 insertions(+), 142 deletions(-) diff --git a/stdlib/_codecs.pyi b/stdlib/_codecs.pyi index 78285ce99e89..7a098a949269 100644 --- a/stdlib/_codecs.pyi +++ b/stdlib/_codecs.pyi @@ -1,6 +1,6 @@ import codecs import sys -from typing import Any, Callable, Dict, Tuple, Union +from typing import Any, Callable, Dict, Tuple, # This type is not exposed; it is defined in unicodeobject.c class _EncodingMap: diff --git a/stdlib/_csv.pyi b/stdlib/_csv.pyi index 859bb64c73cb..c06d74616161 100644 --- a/stdlib/_csv.pyi +++ b/stdlib/_csv.pyi @@ -1,4 +1,4 @@ -from typing import Any, Iterable, Iterator, List, Protocol, Type, Union +from typing import Any, Iterable, Iterator, List, Protocol, Type, QUOTE_ALL: int QUOTE_MINIMAL: int diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index ca059e02a137..00293874903e 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,5 +1,5 @@ import sys -from typing import IO, Any, BinaryIO, NamedTuple, Union, overload +from typing import IO, Any, BinaryIO, NamedTuple, overload _chtype = str | bytes | int diff --git a/stdlib/_dummy_threading.pyi b/stdlib/_dummy_threading.pyi index 4481a04f8f6b..c41e86569f40 100644 --- a/stdlib/_dummy_threading.pyi +++ b/stdlib/_dummy_threading.pyi @@ -1,6 +1,6 @@ import sys from types import FrameType, TracebackType -from typing import Any, Callable, Iterable, Mapping, Optional, Type, TypeVar +from typing import Any, Callable, Iterable, Mapping, Type, TypeVar # TODO recursive type _TF = Callable[[FrameType, str, Any], Callable[..., Any] | None] diff --git a/stdlib/_socket.pyi b/stdlib/_socket.pyi index dbc58469c8f0..b18011797e0c 100644 --- a/stdlib/_socket.pyi +++ b/stdlib/_socket.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import ReadableBuffer, WriteableBuffer from collections.abc import Iterable -from typing import Any, SupportsInt, Tuple, Union, overload +from typing import Any, SupportsInt, Tuple, overload if sys.version_info >= (3, 8): from typing import SupportsIndex diff --git a/stdlib/_thread.pyi b/stdlib/_thread.pyi index 09a10fadb54c..75459aa10c93 100644 --- a/stdlib/_thread.pyi +++ b/stdlib/_thread.pyi @@ -1,7 +1,7 @@ import sys from threading import Thread from types import TracebackType -from typing import Any, Callable, NoReturn, Optional, Tuple, Type +from typing import Any, Callable, NoReturn, Tuple, Type from typing_extensions import final error = RuntimeError diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 5bc65ab25af5..4fb46f6d97ff 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -7,7 +7,7 @@ import ctypes import mmap import sys from os import PathLike -from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, TypeVar, Union +from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, TypeVar, from typing_extensions import Literal, final _KT = TypeVar("_KT") diff --git a/stdlib/aifc.pyi b/stdlib/aifc.pyi index 5d9d60162bec..1d5db932b181 100644 --- a/stdlib/aifc.pyi +++ b/stdlib/aifc.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Self from types import TracebackType -from typing import IO, Any, NamedTuple, Tuple, Type, Union, overload +from typing import IO, Any, NamedTuple, Tuple, Type, overload from typing_extensions import Literal class Error(Exception): ... diff --git a/stdlib/array.pyi b/stdlib/array.pyi index f0c883f6c337..001be0bbd617 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, TypeVar, Union, overload +from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, TypeVar, overload from typing_extensions import Literal, SupportsIndex _IntTypeCode = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 932c9d41a45a..382e07d4b67e 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -9,7 +9,7 @@ from asyncio.tasks import Task from asyncio.transports import BaseTransport from collections.abc import Iterable from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket -from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, Union, overload +from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, overload from typing_extensions import Literal if sys.version_info >= (3, 7): diff --git a/stdlib/asyncio/base_subprocess.pyi b/stdlib/asyncio/base_subprocess.pyi index 077aacf9b94e..724a287ca158 100644 --- a/stdlib/asyncio/base_subprocess.pyi +++ b/stdlib/asyncio/base_subprocess.pyi @@ -1,6 +1,6 @@ import subprocess from collections import deque -from typing import IO, Any, Callable, Optional, Sequence, Tuple, Union +from typing import IO, Any, Callable, Sequence, Tuple, from . import events, futures, protocols, transports diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index ab04de51e006..41b2fe89cd2c 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -3,7 +3,7 @@ import sys 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, Dict, Generator, Sequence, Tuple, TypeVar, Union, overload +from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, overload from typing_extensions import Literal from .base_events import Server diff --git a/stdlib/asyncio/format_helpers.pyi b/stdlib/asyncio/format_helpers.pyi index 096a0990a81a..fd04ce7897d5 100644 --- a/stdlib/asyncio/format_helpers.pyi +++ b/stdlib/asyncio/format_helpers.pyi @@ -2,7 +2,7 @@ import functools import sys import traceback from types import FrameType, FunctionType -from typing import Any, Iterable, Union, overload +from typing import Any, Iterable, overload class _HasWrapper: __wrapper__: _HasWrapper | FunctionType diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 814c77f37656..51f10efcff17 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import StrPath -from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, Optional +from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, from . import events, protocols, transports from .base_events import Server diff --git a/stdlib/asyncio/subprocess.pyi b/stdlib/asyncio/subprocess.pyi index 3744106769c4..7752d42ba501 100644 --- a/stdlib/asyncio/subprocess.pyi +++ b/stdlib/asyncio/subprocess.pyi @@ -2,7 +2,7 @@ import subprocess import sys from _typeshed import StrOrBytesPath from asyncio import events, protocols, streams, transports -from typing import IO, Any, Callable, Union +from typing import IO, Any, Callable, from typing_extensions import Literal if sys.version_info >= (3, 8): diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index ebd8ab9dd6c2..c8935fc49b3f 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -2,7 +2,7 @@ import concurrent.futures import sys from collections.abc import Awaitable, Generator, Iterable, Iterator from types import FrameType -from typing import Any, Generic, Optional, TextIO, TypeVar, Union, overload +from typing import Any, Generic, TextIO, TypeVar, overload from typing_extensions import Literal from .events import AbstractEventLoop diff --git a/stdlib/asyncio/trsock.pyi b/stdlib/asyncio/trsock.pyi index 0dc4cabbb835..12253950d4f5 100644 --- a/stdlib/asyncio/trsock.pyi +++ b/stdlib/asyncio/trsock.pyi @@ -1,7 +1,7 @@ import socket import sys from types import TracebackType -from typing import Any, BinaryIO, Iterable, NoReturn, Tuple, Type, Union, overload +from typing import Any, BinaryIO, Iterable, NoReturn, Tuple, Type, overload if sys.version_info >= (3, 8): # These are based in socket, maybe move them out into _typeshed.pyi or such diff --git a/stdlib/binhex.pyi b/stdlib/binhex.pyi index a8280b819539..7ebb1c2b1957 100644 --- a/stdlib/binhex.pyi +++ b/stdlib/binhex.pyi @@ -1,4 +1,4 @@ -from typing import IO, Any, Tuple, Union +from typing import IO, Any, Tuple, class Error(Exception): ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index f6bc5ce1509d..82af307bfb98 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -54,7 +54,7 @@ from typing import ( Tuple, Type, TypeVar, - Union, + overload, ) from typing_extensions import Literal, SupportsIndex, TypeGuard, final diff --git a/stdlib/calendar.pyi b/stdlib/calendar.pyi index bcdde53118e9..e9945141f97f 100644 --- a/stdlib/calendar.pyi +++ b/stdlib/calendar.pyi @@ -1,7 +1,7 @@ import datetime import sys from time import struct_time -from typing import Any, Iterable, Optional, Sequence, Tuple +from typing import Any, Iterable, Sequence, Tuple _LocaleType = Tuple[str | None, str | None] diff --git a/stdlib/cgitb.pyi b/stdlib/cgitb.pyi index 69498a7e1b53..f773867d679c 100644 --- a/stdlib/cgitb.pyi +++ b/stdlib/cgitb.pyi @@ -1,6 +1,6 @@ from _typeshed import StrOrBytesPath from types import FrameType, TracebackType -from typing import IO, Any, Callable, Optional, Tuple, Type +from typing import IO, Any, Callable, Tuple, Type _ExcInfo = Tuple[Type[BaseException] | None, BaseException | None, TracebackType | None] diff --git a/stdlib/cmath.pyi b/stdlib/cmath.pyi index 01ec16baf79f..f97161e7dcb3 100644 --- a/stdlib/cmath.pyi +++ b/stdlib/cmath.pyi @@ -1,5 +1,5 @@ import sys -from typing import SupportsComplex, SupportsFloat, Union +from typing import SupportsComplex, SupportsFloat, if sys.version_info >= (3, 8): from typing import SupportsIndex diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index 809c60aa2b66..df7a4438bda1 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -1,7 +1,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, Dict, Optional, Pattern, Type, TypeVar, overload +from typing import Any, ClassVar, Dict, Pattern, Type, TypeVar, overload from typing_extensions import Literal # Internal type aliases diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index e0306a12901f..8d2495e27ab4 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -10,7 +10,7 @@ from typing import ( ContextManager, Generic, Iterator, - Optional, + Type, TypeVar, overload, diff --git a/stdlib/copyreg.pyi b/stdlib/copyreg.pyi index 811c5fbfad95..8c83a3bbb49b 100644 --- a/stdlib/copyreg.pyi +++ b/stdlib/copyreg.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Hashable, Optional, SupportsInt, Tuple, TypeVar, Union +from typing import Any, Callable, Hashable, SupportsInt, Tuple, TypeVar, _TypeT = TypeVar("_TypeT", bound=type) _Reduce = Tuple[Callable[..., _TypeT], Tuple[Any, ...]] | Tuple[Callable[..., _TypeT], Tuple[Any, ...], Any | None] diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index a9d5db88cfac..2cf28297d9a8 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -9,7 +9,7 @@ from typing import ( Iterable, Iterator, Mapping, - Optional, + Sequence, Tuple, Type, diff --git a/stdlib/dbm/__init__.pyi b/stdlib/dbm/__init__.pyi index e780270fbec7..39653fbf78e5 100644 --- a/stdlib/dbm/__init__.pyi +++ b/stdlib/dbm/__init__.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Iterator, MutableMapping, Type, Union +from typing import Iterator, MutableMapping, Type, from typing_extensions import Literal _KeyType = str | bytes diff --git a/stdlib/dbm/dumb.pyi b/stdlib/dbm/dumb.pyi index f88142b072b6..8d63d4f85124 100644 --- a/stdlib/dbm/dumb.pyi +++ b/stdlib/dbm/dumb.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Iterator, MutableMapping, Type, Union +from typing import Iterator, MutableMapping, Type, _KeyType = str | bytes _ValueType = str | bytes diff --git a/stdlib/dbm/gnu.pyi b/stdlib/dbm/gnu.pyi index 28af500fd66b..167f7aedee1a 100644 --- a/stdlib/dbm/gnu.pyi +++ b/stdlib/dbm/gnu.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Type, TypeVar, Union, overload +from typing import Type, TypeVar, overload _T = TypeVar("_T") _KeyType = str | bytes diff --git a/stdlib/dbm/ndbm.pyi b/stdlib/dbm/ndbm.pyi index 8e27b9545627..3690db77ca09 100644 --- a/stdlib/dbm/ndbm.pyi +++ b/stdlib/dbm/ndbm.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Type, TypeVar, Union, overload +from typing import Type, TypeVar, overload _T = TypeVar("_T") _KeyType = str | bytes diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index 945394295b4c..2ee4c67437ce 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -1,6 +1,6 @@ import numbers from types import TracebackType -from typing import Any, Container, NamedTuple, Sequence, Tuple, Type, TypeVar, Union, overload +from typing import Any, Container, NamedTuple, Sequence, Tuple, Type, TypeVar, overload _Decimal = Decimal | int _DecimalNew = Decimal | float | str | Tuple[int, Sequence[int], int] diff --git a/stdlib/difflib.pyi b/stdlib/difflib.pyi index fb3e2dc7e81d..41ec0865dab1 100644 --- a/stdlib/difflib.pyi +++ b/stdlib/difflib.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, AnyStr, Callable, Generic, Iterable, Iterator, NamedTuple, Sequence, TypeVar, Union, overload +from typing import Any, AnyStr, Callable, Generic, Iterable, Iterator, NamedTuple, Sequence, TypeVar, overload if sys.version_info >= (3, 9): from types import GenericAlias diff --git a/stdlib/dis.pyi b/stdlib/dis.pyi index 62050b2fe084..a98f5c11fc17 100644 --- a/stdlib/dis.pyi +++ b/stdlib/dis.pyi @@ -16,7 +16,7 @@ from opcode import ( opname as opname, stack_effect as stack_effect, ) -from typing import IO, Any, Callable, Iterator, NamedTuple, Union +from typing import IO, Any, Callable, Iterator, NamedTuple, # Strictly this should not have to include Callable, but mypy doesn't use FunctionType # for functions (python/mypy#3171) diff --git a/stdlib/distutils/ccompiler.pyi b/stdlib/distutils/ccompiler.pyi index f4221cacfe39..be3cb80b54d3 100644 --- a/stdlib/distutils/ccompiler.pyi +++ b/stdlib/distutils/ccompiler.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Optional, Tuple, Union +from typing import Any, Callable, Tuple, _Macro = Tuple[str] | Tuple[str, str | None] diff --git a/stdlib/distutils/fancy_getopt.pyi b/stdlib/distutils/fancy_getopt.pyi index 600704a139a2..081f377b693a 100644 --- a/stdlib/distutils/fancy_getopt.pyi +++ b/stdlib/distutils/fancy_getopt.pyi @@ -1,4 +1,4 @@ -from typing import Any, Iterable, List, Mapping, Optional, Tuple, overload +from typing import Any, Iterable, List, Mapping, Tuple, overload _Option = Tuple[str, str | None, str] _GR = Tuple[List[str], OptionDummy] diff --git a/stdlib/email/_header_value_parser.pyi b/stdlib/email/_header_value_parser.pyi index 1c493af54846..e8bff4435ea0 100644 --- a/stdlib/email/_header_value_parser.pyi +++ b/stdlib/email/_header_value_parser.pyi @@ -1,7 +1,7 @@ import sys from email.errors import HeaderParseError, MessageDefect from email.policy import Policy -from typing import Any, Iterable, Iterator, List, Pattern, Type, TypeVar, Union +from typing import Any, Iterable, Iterator, List, Pattern, Type, TypeVar, from typing_extensions import Final _T = TypeVar("_T") diff --git a/stdlib/email/message.pyi b/stdlib/email/message.pyi index fe6d7cc92c3e..793b986c3250 100644 --- a/stdlib/email/message.pyi +++ b/stdlib/email/message.pyi @@ -2,7 +2,7 @@ from email.charset import Charset from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy -from typing import Any, Generator, Iterator, List, Optional, Sequence, Tuple, TypeVar, Union +from typing import Any, Generator, Iterator, List, Sequence, Tuple, TypeVar, _T = TypeVar("_T") diff --git a/stdlib/email/mime/application.pyi b/stdlib/email/mime/application.pyi index 6dd7b5225a5a..9ba62fb84da9 100644 --- a/stdlib/email/mime/application.pyi +++ b/stdlib/email/mime/application.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Optional, Tuple, Union +from typing import Callable, Tuple, _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/audio.pyi b/stdlib/email/mime/audio.pyi index 9f75b40e487f..8d82b82eb345 100644 --- a/stdlib/email/mime/audio.pyi +++ b/stdlib/email/mime/audio.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Optional, Tuple, Union +from typing import Callable, Tuple, _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/base.pyi b/stdlib/email/mime/base.pyi index 299e005bc8f8..c870eea780ec 100644 --- a/stdlib/email/mime/base.pyi +++ b/stdlib/email/mime/base.pyi @@ -1,6 +1,6 @@ import email.message from email.policy import Policy -from typing import Optional, Tuple, Union +from typing import Tuple, _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/image.pyi b/stdlib/email/mime/image.pyi index 3197a3c4b783..daa1f3be3643 100644 --- a/stdlib/email/mime/image.pyi +++ b/stdlib/email/mime/image.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Optional, Tuple, Union +from typing import Callable, Tuple, _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/multipart.pyi b/stdlib/email/mime/multipart.pyi index 074dee798427..5dcdaadd7b83 100644 --- a/stdlib/email/mime/multipart.pyi +++ b/stdlib/email/mime/multipart.pyi @@ -1,7 +1,7 @@ from email.message import Message from email.mime.base import MIMEBase from email.policy import Policy -from typing import Optional, Sequence, Tuple, Union +from typing import Sequence, Tuple, _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/utils.pyi b/stdlib/email/utils.pyi index b0ddf83289de..6239718b5548 100644 --- a/stdlib/email/utils.pyi +++ b/stdlib/email/utils.pyi @@ -1,7 +1,7 @@ import datetime import sys from email.charset import Charset -from typing import Optional, Tuple, Union, overload +from typing import Tuple, overload _ParamType = str | Tuple[str | None, str | None, str] _PDTZ = Tuple[int, int, int, int, int, int, int, int, int, int | None] diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 165ea5715ede..3beb99b86c56 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -3,7 +3,7 @@ import types from abc import ABCMeta from builtins import property as _builtins_property from collections.abc import Iterable, Iterator, Mapping -from typing import Any, Dict, Tuple, Type, TypeVar, Union, overload +from typing import Any, Dict, Tuple, Type, TypeVar, overload _T = TypeVar("_T") _S = TypeVar("_S", bound=Type[Enum]) diff --git a/stdlib/fractions.pyi b/stdlib/fractions.pyi index e670c690dca1..42cad19b4f03 100644 --- a/stdlib/fractions.pyi +++ b/stdlib/fractions.pyi @@ -1,7 +1,7 @@ import sys from decimal import Decimal from numbers import Integral, Rational, Real -from typing import Type, TypeVar, Union, overload +from typing import Type, TypeVar, overload from typing_extensions import Literal _ComparableNum = int | float | Decimal | Real diff --git a/stdlib/hmac.pyi b/stdlib/hmac.pyi index 93c82b7b74bd..93360e8aed7e 100644 --- a/stdlib/hmac.pyi +++ b/stdlib/hmac.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import ReadableBuffer from types import ModuleType -from typing import Any, AnyStr, Callable, Union, overload +from typing import Any, AnyStr, Callable, overload # TODO more precise type for object of hashlib _Hash = Any diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index 253a8b368ef7..50ae39786e17 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -5,7 +5,7 @@ import sys import types from _typeshed import Self, WriteableBuffer from socket import socket -from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, Mapping, Protocol, Type, TypeVar, Union, overload +from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, Mapping, Protocol, Type, TypeVar, overload _DataType = bytes | IO[Any] | Iterable[bytes] | str _T = TypeVar("_T") diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index 26c4779e72e0..e3490e7b8826 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Dict, Generic, Iterable, Mapping, TypeVar, Union, overload +from typing import Any, Dict, Generic, Iterable, Mapping, TypeVar, overload if sys.version_info >= (3, 9): from types import GenericAlias diff --git a/stdlib/imaplib.pyi b/stdlib/imaplib.pyi index 8755c32bdc56..d86ee35f0a05 100644 --- a/stdlib/imaplib.pyi +++ b/stdlib/imaplib.pyi @@ -5,7 +5,7 @@ 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, List, Pattern, Tuple, Type, Union +from typing import IO, Any, Callable, List, Pattern, Tuple, Type, from typing_extensions import Literal # TODO: Commands should use their actual return types, not this type alias. diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index 794fb568be2a..97af6718d122 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -12,7 +12,7 @@ from _typeshed import ( 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, Union, overload +from typing import IO, Any, BinaryIO, Iterator, Mapping, NoReturn, Protocol, Sequence, overload from typing_extensions import Literal, runtime_checkable _Path = bytes | str diff --git a/stdlib/importlib/resources.pyi b/stdlib/importlib/resources.pyi index 579e99fa61cd..6b4ec55839ea 100644 --- a/stdlib/importlib/resources.pyi +++ b/stdlib/importlib/resources.pyi @@ -7,7 +7,7 @@ if sys.version_info >= (3, 7): from contextlib import AbstractContextManager from pathlib import Path from types import ModuleType - from typing import BinaryIO, Iterator, TextIO, Union + from typing import BinaryIO, Iterator, TextIO, Package = str | ModuleType Resource = str | os.PathLike[Any] diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index cbde9dbe0b70..d8a276a2b5b9 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -23,7 +23,7 @@ from types import ( if sys.version_info >= (3, 7): from types import ClassMethodDescriptorType, WrapperDescriptorType, MemberDescriptorType, MethodDescriptorType -from typing import Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar, Union +from typing import Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar, from typing_extensions import Literal, TypeGuard # diff --git a/stdlib/itertools.pyi b/stdlib/itertools.pyi index 6380a31c4fd7..55836af38a27 100644 --- a/stdlib/itertools.pyi +++ b/stdlib/itertools.pyi @@ -12,7 +12,7 @@ from typing import ( Tuple, Type, TypeVar, - Union, + overload, ) from typing_extensions import Literal, SupportsIndex diff --git a/stdlib/lib2to3/pgen2/grammar.pyi b/stdlib/lib2to3/pgen2/grammar.pyi index 2dc5a5686b64..a9676bb5b15e 100644 --- a/stdlib/lib2to3/pgen2/grammar.pyi +++ b/stdlib/lib2to3/pgen2/grammar.pyi @@ -1,5 +1,5 @@ from _typeshed import StrPath -from typing import Dict, List, Optional, Tuple, TypeVar +from typing import Dict, List, Tuple, TypeVar _P = TypeVar("_P") _Label = Tuple[int, str | None] diff --git a/stdlib/lib2to3/pytree.pyi b/stdlib/lib2to3/pytree.pyi index b943902103e5..2c534fc4761a 100644 --- a/stdlib/lib2to3/pytree.pyi +++ b/stdlib/lib2to3/pytree.pyi @@ -1,5 +1,5 @@ from lib2to3.pgen2.grammar import Grammar -from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, TypeVar, Union +from typing import Any, Callable, Dict, Iterator, List, Tuple, TypeVar, _P = TypeVar("_P") _NL = Node | Leaf diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index f1e66ba06027..7758c8db0fd2 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -6,7 +6,7 @@ from io import TextIOWrapper from string import Template from time import struct_time from types import FrameType, TracebackType -from typing import Any, ClassVar, Generic, Optional, Pattern, TextIO, Tuple, Type, TypeVar, Union, overload +from typing import Any, ClassVar, Generic, Pattern, TextIO, Tuple, Type, TypeVar, overload from typing_extensions import Literal _SysExcInfoType = Tuple[Type[BaseException], BaseException, TracebackType | None] | Tuple[None, None, None] diff --git a/stdlib/lzma.pyi b/stdlib/lzma.pyi index ecf488defa69..5f0318d8e865 100644 --- a/stdlib/lzma.pyi +++ b/stdlib/lzma.pyi @@ -1,6 +1,6 @@ import io from _typeshed import ReadableBuffer, Self, StrOrBytesPath -from typing import IO, Any, Mapping, Sequence, TextIO, Union, overload +from typing import IO, Any, Mapping, Sequence, TextIO, overload from typing_extensions import Literal, final _OpenBinaryWritingMode = Literal["w", "wb", "x", "xb", "a", "ab"] diff --git a/stdlib/mailbox.pyi b/stdlib/mailbox.pyi index b10cb2f6e2e5..c9350357c2fa 100644 --- a/stdlib/mailbox.pyi +++ b/stdlib/mailbox.pyi @@ -15,7 +15,7 @@ from typing import ( Sequence, Type, TypeVar, - Union, + overload, ) from typing_extensions import Literal diff --git a/stdlib/mailcap.pyi b/stdlib/mailcap.pyi index 084b705bdd2c..84620c438728 100644 --- a/stdlib/mailcap.pyi +++ b/stdlib/mailcap.pyi @@ -1,4 +1,4 @@ -from typing import Dict, Mapping, Sequence, Union +from typing import Dict, Mapping, Sequence, _Cap = Dict[str, str | int] diff --git a/stdlib/math.pyi b/stdlib/math.pyi index 367ad6076095..9b0b15055c72 100644 --- a/stdlib/math.pyi +++ b/stdlib/math.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import SupportsTrunc -from typing import Iterable, SupportsFloat, Union, overload +from typing import Iterable, SupportsFloat, overload from typing_extensions import SupportsIndex if sys.version_info >= (3, 8): diff --git a/stdlib/msilib/sequence.pyi b/stdlib/msilib/sequence.pyi index 6d5d45ef117f..2f807325dbce 100644 --- a/stdlib/msilib/sequence.pyi +++ b/stdlib/msilib/sequence.pyi @@ -1,5 +1,5 @@ import sys -from typing import List, Optional, Tuple +from typing import List, Tuple if sys.platform == "win32": diff --git a/stdlib/multiprocessing/__init__.pyi b/stdlib/multiprocessing/__init__.pyi index 69437de379e3..b7aff1601887 100644 --- a/stdlib/multiprocessing/__init__.pyi +++ b/stdlib/multiprocessing/__init__.pyi @@ -20,7 +20,7 @@ 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, Union, overload +from typing import Any, overload from typing_extensions import Literal if sys.version_info >= (3, 8): diff --git a/stdlib/multiprocessing/connection.pyi b/stdlib/multiprocessing/connection.pyi index d76de7bac282..af13c6f8b74c 100644 --- a/stdlib/multiprocessing/connection.pyi +++ b/stdlib/multiprocessing/connection.pyi @@ -2,7 +2,7 @@ import socket import sys import types from _typeshed import Self -from typing import Any, Iterable, Tuple, Type, Union +from typing import Any, Iterable, Tuple, Type, if sys.version_info >= (3, 8): from typing import SupportsIndex diff --git a/stdlib/multiprocessing/context.pyi b/stdlib/multiprocessing/context.pyi index 3d008baa68f5..2e77c2b81abf 100644 --- a/stdlib/multiprocessing/context.pyi +++ b/stdlib/multiprocessing/context.pyi @@ -8,7 +8,7 @@ from multiprocessing import queues, synchronize from multiprocessing.pool import Pool as _Pool from multiprocessing.process import BaseProcess from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase -from typing import Any, Type, TypeVar, Union, overload +from typing import Any, Type, TypeVar, overload from typing_extensions import Literal _LockLike = synchronize.Lock | synchronize.RLock diff --git a/stdlib/multiprocessing/dummy/connection.pyi b/stdlib/multiprocessing/dummy/connection.pyi index baaa29df629e..13688de53aea 100644 --- a/stdlib/multiprocessing/dummy/connection.pyi +++ b/stdlib/multiprocessing/dummy/connection.pyi @@ -1,7 +1,7 @@ from _typeshed import Self from queue import Queue from types import TracebackType -from typing import Any, Tuple, Type, Union +from typing import Any, Tuple, Type, families: list[None] diff --git a/stdlib/multiprocessing/synchronize.pyi b/stdlib/multiprocessing/synchronize.pyi index c6f6c96fcffe..61de45a4216c 100644 --- a/stdlib/multiprocessing/synchronize.pyi +++ b/stdlib/multiprocessing/synchronize.pyi @@ -2,7 +2,7 @@ import sys import threading from contextlib import AbstractContextManager from multiprocessing.context import BaseContext -from typing import Any, Callable, Union +from typing import Any, Callable, _LockLike = Lock | RLock diff --git a/stdlib/netrc.pyi b/stdlib/netrc.pyi index 737a97814ca9..139b151ccb6a 100644 --- a/stdlib/netrc.pyi +++ b/stdlib/netrc.pyi @@ -1,5 +1,5 @@ from _typeshed import StrOrBytesPath -from typing import Optional, Tuple +from typing import Tuple class NetrcParseError(Exception): filename: str | None diff --git a/stdlib/nntplib.pyi b/stdlib/nntplib.pyi index f52e33baca83..23cddd033484 100644 --- a/stdlib/nntplib.pyi +++ b/stdlib/nntplib.pyi @@ -3,7 +3,7 @@ import socket import ssl import sys from _typeshed import Self -from typing import IO, Any, Iterable, NamedTuple, Tuple, Union +from typing import IO, Any, Iterable, NamedTuple, Tuple, _File = IO[bytes] | bytes | str | None diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index bbdff748b5bd..cee8edd11b83 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -32,7 +32,7 @@ from typing import ( Sequence, Tuple, TypeVar, - Union, + overload, runtime_checkable, ) diff --git a/stdlib/pickle.pyi b/stdlib/pickle.pyi index 8272ef7e91cc..e5212ed485ff 100644 --- a/stdlib/pickle.pyi +++ b/stdlib/pickle.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Optional, Protocol, Tuple, Type, Union +from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Protocol, Tuple, Type, from typing_extensions import final HIGHEST_PROTOCOL: int diff --git a/stdlib/pstats.pyi b/stdlib/pstats.pyi index 63621eb3cb82..c8308901ad5c 100644 --- a/stdlib/pstats.pyi +++ b/stdlib/pstats.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import StrOrBytesPath from cProfile import Profile as _cProfile from profile import Profile -from typing import IO, Any, Iterable, Tuple, TypeVar, Union, overload +from typing import IO, Any, Iterable, Tuple, TypeVar, overload _Selector = str | float | int _T = TypeVar("_T", bound=Stats) diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index 77ae62190632..9c6b94ba1791 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -1,7 +1,7 @@ from _typeshed import SupportsWrite from reprlib import Repr from types import MethodType, ModuleType, TracebackType -from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, Optional, Tuple, Type +from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, Tuple, Type # the return type of sys.exc_info(), used by ErrorDuringImport.__init__ _Exc_Info = Tuple[Type[BaseException] | None, BaseException | None, TracebackType | None] diff --git a/stdlib/pyexpat/__init__.pyi b/stdlib/pyexpat/__init__.pyi index 3f02ab8b3d44..e80c9ea2b4ea 100644 --- a/stdlib/pyexpat/__init__.pyi +++ b/stdlib/pyexpat/__init__.pyi @@ -1,7 +1,7 @@ import pyexpat.errors as errors import pyexpat.model as model from _typeshed import SupportsRead -from typing import Any, Callable, Optional, Tuple +from typing import Any, Callable, Tuple from typing_extensions import final EXPAT_VERSION: str # undocumented diff --git a/stdlib/re.pyi b/stdlib/re.pyi index 7980571eea6a..e3a053e6d0ca 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -1,7 +1,7 @@ import enum import sys from sre_constants import error as error -from typing import Any, AnyStr, Callable, Iterator, Union, overload +from typing import Any, AnyStr, Callable, Iterator, overload # ----- re variables and constants ----- if sys.version_info >= (3, 7): diff --git a/stdlib/readline.pyi b/stdlib/readline.pyi index 8b7381225941..4844e30d6474 100644 --- a/stdlib/readline.pyi +++ b/stdlib/readline.pyi @@ -1,5 +1,5 @@ from _typeshed import StrOrBytesPath -from typing import Callable, Optional, Sequence +from typing import Callable, Sequence _CompleterT = Callable[[str, int], str | None] | None _CompDispT = Callable[[str, Sequence[str], int], None] | None diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index fc6a3dce8118..25aba616c3b8 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -1,7 +1,7 @@ import os import sys from _typeshed import StrOrBytesPath, StrPath, SupportsRead, SupportsWrite -from typing import Any, AnyStr, Callable, Iterable, NamedTuple, Sequence, TypeVar, Union, overload +from typing import Any, AnyStr, Callable, Iterable, NamedTuple, Sequence, TypeVar, overload _PathT = TypeVar("_PathT", str, os.PathLike[str]) # Return value of some functions that may either return a path-like object that was passed in or diff --git a/stdlib/signal.pyi b/stdlib/signal.pyi index c845c23a6459..69b518d545d8 100644 --- a/stdlib/signal.pyi +++ b/stdlib/signal.pyi @@ -1,7 +1,7 @@ import sys from enum import IntEnum from types import FrameType -from typing import Any, Callable, Iterable, Optional, Tuple, Union +from typing import Any, Callable, Iterable, Tuple, NSIG: int diff --git a/stdlib/smtplib.pyi b/stdlib/smtplib.pyi index d7e00dba87a5..082673c75060 100644 --- a/stdlib/smtplib.pyi +++ b/stdlib/smtplib.pyi @@ -4,7 +4,7 @@ from email.message import Message as _Message from socket import socket from ssl import SSLContext from types import TracebackType -from typing import Any, Dict, Pattern, Protocol, Sequence, Tuple, Type, Union, overload +from typing import Any, Dict, Pattern, Protocol, Sequence, Tuple, Type, overload _Reply = Tuple[int, bytes] _SendErrs = Dict[str, _Reply] diff --git a/stdlib/socketserver.pyi b/stdlib/socketserver.pyi index 7b3a28c72603..9cfd53f853c3 100644 --- a/stdlib/socketserver.pyi +++ b/stdlib/socketserver.pyi @@ -2,7 +2,7 @@ import sys import types from _typeshed import Self from socket import socket as _socket -from typing import Any, BinaryIO, Callable, ClassVar, Tuple, Type, TypeVar, Union +from typing import Any, BinaryIO, Callable, ClassVar, Tuple, Type, TypeVar, _T = TypeVar("_T") _RequestType = _socket | Tuple[bytes, _socket] diff --git a/stdlib/sre_parse.pyi b/stdlib/sre_parse.pyi index 4f1038854f06..0871e440e9f8 100644 --- a/stdlib/sre_parse.pyi +++ b/stdlib/sre_parse.pyi @@ -1,6 +1,6 @@ import sys from sre_constants import _NamedIntConstant as _NIC, error as _Error -from typing import Any, Iterable, List, Match, Optional, Pattern as _Pattern, Tuple, Union, overload +from typing import Any, Iterable, List, Match, Pattern as _Pattern, Tuple, overload SPECIAL_CHARS: str REPEAT_CHARS: str diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index d8530599cf41..cbb62d95a0b2 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -2,7 +2,7 @@ import enum import socket import sys from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer -from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Optional, Set, Tuple, Type, Union, overload +from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Set, Tuple, Type, overload from typing_extensions import Literal, TypedDict _PCTRTT = Tuple[Tuple[str, str], ...] diff --git a/stdlib/statistics.pyi b/stdlib/statistics.pyi index 04bdcc676d01..f1a1f449e491 100644 --- a/stdlib/statistics.pyi +++ b/stdlib/statistics.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsRichComparisonT from decimal import Decimal from fractions import Fraction -from typing import Any, Hashable, Iterable, NamedTuple, Sequence, SupportsFloat, Type, TypeVar, Union +from typing import Any, Hashable, Iterable, NamedTuple, Sequence, SupportsFloat, Type, TypeVar, _T = TypeVar("_T") # Most functions in this module accept homogeneous collections of one of these types diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index 8c9f91c6941a..f9f8bef7cfa1 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Self, StrOrBytesPath from types import TracebackType -from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, Union, overload +from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, overload from typing_extensions import Literal if sys.version_info >= (3, 9): diff --git a/stdlib/sunau.pyi b/stdlib/sunau.pyi index f6479939f0c8..81fcd1649a4f 100644 --- a/stdlib/sunau.pyi +++ b/stdlib/sunau.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import Self -from typing import IO, Any, NamedTuple, NoReturn, Union +from typing import IO, Any, NamedTuple, NoReturn, _File = str | IO[bytes] diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index 8603040941bd..b290d3f94218 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -9,14 +9,14 @@ from typing import ( AsyncGenerator, Callable, NoReturn, - Optional, + Protocol, Sequence, TextIO, Tuple, Type, TypeVar, - Union, + overload, ) from typing_extensions import Literal diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index 21f75784a746..2f8045f3200d 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -2,7 +2,7 @@ import os import sys from _typeshed import Self from types import TracebackType -from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, Union, overload +from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, overload from typing_extensions import Literal if sys.version_info >= (3, 9): diff --git a/stdlib/termios.pyi b/stdlib/termios.pyi index 80e378c5ecb2..39fecd4c5fe8 100644 --- a/stdlib/termios.pyi +++ b/stdlib/termios.pyi @@ -1,5 +1,5 @@ from _typeshed import FileDescriptorLike -from typing import Any, List, Union +from typing import Any, List, _Attr = List[int | List[bytes | int]] diff --git a/stdlib/threading.pyi b/stdlib/threading.pyi index 9a8d26fee48e..5c22c8b18b2c 100644 --- a/stdlib/threading.pyi +++ b/stdlib/threading.pyi @@ -1,6 +1,6 @@ import sys from types import FrameType, TracebackType -from typing import Any, Callable, Iterable, Mapping, Optional, Type, TypeVar +from typing import Any, Callable, Iterable, Mapping, Type, TypeVar # TODO recursive type _TF = Callable[[FrameType, str, Any], Callable[..., Any] | None] diff --git a/stdlib/timeit.pyi b/stdlib/timeit.pyi index c3c6fd6bed0a..9e3a0f293731 100644 --- a/stdlib/timeit.pyi +++ b/stdlib/timeit.pyi @@ -1,4 +1,4 @@ -from typing import IO, Any, Callable, Sequence, Union +from typing import IO, Any, Callable, Sequence, _Timer = Callable[[], float] _Stmt = str | Callable[[], Any] diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index e7dfaae88407..7685f47ab2ea 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -5,7 +5,7 @@ from enum import Enum from tkinter.constants import * # comment this out to find undefined identifier names with flake8 from tkinter.font import _FontDescription from types import TracebackType -from typing import Any, Callable, Generic, List, Mapping, Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union, overload +from typing import Any, Callable, Generic, List, Mapping, Protocol, Sequence, Tuple, Type, TypeVar, overload from typing_extensions import Literal, TypedDict # Using anything from tkinter.font in this file means that 'import tkinter' diff --git a/stdlib/tkinter/font.pyi b/stdlib/tkinter/font.pyi index 3b3765ece3b2..eaf05001cd9a 100644 --- a/stdlib/tkinter/font.pyi +++ b/stdlib/tkinter/font.pyi @@ -1,7 +1,7 @@ import _tkinter import sys import tkinter -from typing import Any, List, Tuple, Union, overload +from typing import Any, List, Tuple, overload from typing_extensions import Literal, TypedDict NORMAL: Literal["normal"] diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 2c1f8d75a9f8..26c28a9c587a 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -2,7 +2,7 @@ import _tkinter import sys import tkinter from tkinter.font import _FontDescription -from typing import Any, Callable, Tuple, Union, overload +from typing import Any, Callable, Tuple, overload from typing_extensions import Literal, TypedDict def tclobjs_to_py(adict): ... diff --git a/stdlib/tokenize.pyi b/stdlib/tokenize.pyi index 512fd6c85e73..10ad5dda930e 100644 --- a/stdlib/tokenize.pyi +++ b/stdlib/tokenize.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import StrOrBytesPath from builtins import open as _builtin_open from token import * # noqa: F403 -from typing import Any, Callable, Generator, Iterable, NamedTuple, Pattern, Sequence, TextIO, Tuple, Union +from typing import Any, Callable, Generator, Iterable, NamedTuple, Pattern, Sequence, TextIO, Tuple, if sys.version_info < (3, 7): COMMENT: int diff --git a/stdlib/trace.pyi b/stdlib/trace.pyi index 53891a7a931a..9489b547bdbd 100644 --- a/stdlib/trace.pyi +++ b/stdlib/trace.pyi @@ -1,7 +1,7 @@ import sys import types from _typeshed import StrPath -from typing import Any, Callable, Mapping, Optional, Sequence, Tuple, TypeVar +from typing import Any, Callable, Mapping, Sequence, Tuple, TypeVar from typing_extensions import ParamSpec _T = TypeVar("_T") diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index ff4b5b4d4a9e..4cc0611135fd 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import SupportsWrite from types import FrameType, TracebackType -from typing import IO, Any, Generator, Iterable, Iterator, List, Mapping, Optional, Tuple, Type, overload +from typing import IO, Any, Generator, Iterable, Iterator, List, Mapping, Tuple, Type, overload _PT = Tuple[str, int, str, str | None] diff --git a/stdlib/tracemalloc.pyi b/stdlib/tracemalloc.pyi index e425a864c1aa..d7242619d8a0 100644 --- a/stdlib/tracemalloc.pyi +++ b/stdlib/tracemalloc.pyi @@ -1,6 +1,6 @@ import sys from _tracemalloc import * -from typing import Optional, Sequence, Tuple, Union, overload +from typing import Sequence, Tuple, overload from typing_extensions import SupportsIndex def get_object_traceback(obj: object) -> Traceback | None: ... diff --git a/stdlib/tty.pyi b/stdlib/tty.pyi index 47132006edeb..d3c1e7786b5b 100644 --- a/stdlib/tty.pyi +++ b/stdlib/tty.pyi @@ -1,4 +1,4 @@ -from typing import IO, Union +from typing import IO, _FD = int | IO[str] diff --git a/stdlib/turtle.pyi b/stdlib/turtle.pyi index 3df64e911662..e67d587e6b57 100644 --- a/stdlib/turtle.pyi +++ b/stdlib/turtle.pyi @@ -1,5 +1,5 @@ from tkinter import Canvas, Frame, PhotoImage -from typing import Any, Callable, ClassVar, Dict, Sequence, Tuple, TypeVar, Union, overload +from typing import Any, Callable, ClassVar, Dict, Sequence, Tuple, TypeVar, overload # Note: '_Color' is the alias we use for arguments and _AnyColor is the # alias we use for return types. Really, these two aliases should be the diff --git a/stdlib/unittest/result.pyi b/stdlib/unittest/result.pyi index fe7ac36d205f..d56e6a42c8c9 100644 --- a/stdlib/unittest/result.pyi +++ b/stdlib/unittest/result.pyi @@ -1,6 +1,6 @@ import unittest.case from types import TracebackType -from typing import Any, Callable, TextIO, Tuple, Type, TypeVar, Union +from typing import Any, Callable, TextIO, Tuple, Type, TypeVar, _SysExcInfoType = Tuple[Type[BaseException], BaseException, TracebackType] | Tuple[None, None, None] diff --git a/stdlib/unittest/suite.pyi b/stdlib/unittest/suite.pyi index 1a925e6d9753..7dd16b54cbc0 100644 --- a/stdlib/unittest/suite.pyi +++ b/stdlib/unittest/suite.pyi @@ -1,6 +1,6 @@ import unittest.case import unittest.result -from typing import Iterable, Iterator, Union +from typing import Iterable, Iterator, _TestType = unittest.case.TestCase | TestSuite diff --git a/stdlib/urllib/parse.pyi b/stdlib/urllib/parse.pyi index e974215e9eb7..19baf136c3cc 100644 --- a/stdlib/urllib/parse.pyi +++ b/stdlib/urllib/parse.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, AnyStr, Callable, Generic, Mapping, NamedTuple, Sequence, Tuple, Union, overload +from typing import Any, AnyStr, Callable, Generic, Mapping, NamedTuple, Sequence, Tuple, overload if sys.version_info >= (3, 9): from types import GenericAlias diff --git a/stdlib/uu.pyi b/stdlib/uu.pyi index fd7e83dc0f6a..207c27356aa1 100644 --- a/stdlib/uu.pyi +++ b/stdlib/uu.pyi @@ -1,5 +1,5 @@ import sys -from typing import BinaryIO, Union +from typing import BinaryIO, _File = str | BinaryIO diff --git a/stdlib/wave.pyi b/stdlib/wave.pyi index edd9e1042043..e650b73eaf83 100644 --- a/stdlib/wave.pyi +++ b/stdlib/wave.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import Self -from typing import IO, Any, BinaryIO, NamedTuple, NoReturn, Union +from typing import IO, Any, BinaryIO, NamedTuple, NoReturn, _File = str | IO[bytes] diff --git a/stdlib/winreg.pyi b/stdlib/winreg.pyi index b449062c2f78..e724a6cbf315 100644 --- a/stdlib/winreg.pyi +++ b/stdlib/winreg.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Any, Type, Union +from typing import Any, Type, from typing_extensions import final _KeyType = HKEYType | int diff --git a/stdlib/wsgiref/handlers.pyi b/stdlib/wsgiref/handlers.pyi index 26b268dcc242..4b1e3e20d032 100644 --- a/stdlib/wsgiref/handlers.pyi +++ b/stdlib/wsgiref/handlers.pyi @@ -1,6 +1,6 @@ from abc import abstractmethod from types import TracebackType -from typing import IO, Callable, MutableMapping, Optional, Tuple, Type +from typing import IO, Callable, MutableMapping, Tuple, Type from .headers import Headers from .types import ErrorStream, InputStream, StartResponse, WSGIApplication, WSGIEnvironment diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index 69125f1796c4..b465736dfb70 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -1,5 +1,5 @@ import sys -from typing import IO, Any, Sequence, Tuple, Union +from typing import IO, Any, Sequence, Tuple, from typing_extensions import Literal from xml.dom.minidom import Document, DOMImplementation, Element, Text from xml.sax.handler import ContentHandler diff --git a/stdlib/xml/dom/xmlbuilder.pyi b/stdlib/xml/dom/xmlbuilder.pyi index 49d72ba6dc1a..93c2eb1d56ee 100644 --- a/stdlib/xml/dom/xmlbuilder.pyi +++ b/stdlib/xml/dom/xmlbuilder.pyi @@ -1,4 +1,4 @@ -from typing import Any, NoReturn, Optional +from typing import Any, NoReturn, from typing_extensions import Literal from urllib.request import OpenerDirector from xml.dom.expatbuilder import ExpatBuilder, ExpatBuilderNS diff --git a/stdlib/xml/etree/ElementTree.pyi b/stdlib/xml/etree/ElementTree.pyi index f9b073176437..8d753a0fa3fa 100644 --- a/stdlib/xml/etree/ElementTree.pyi +++ b/stdlib/xml/etree/ElementTree.pyi @@ -14,7 +14,7 @@ from typing import ( MutableSequence, Sequence, TypeVar, - Union, + overload, ) from typing_extensions import Literal, SupportsIndex diff --git a/stdlib/xmlrpc/client.pyi b/stdlib/xmlrpc/client.pyi index ab84bc546582..601a7312002c 100644 --- a/stdlib/xmlrpc/client.pyi +++ b/stdlib/xmlrpc/client.pyi @@ -6,7 +6,7 @@ from _typeshed import Self, SupportsRead, SupportsWrite from datetime import datetime from io import BytesIO from types import TracebackType -from typing import Any, Callable, Dict, Iterable, List, Mapping, Protocol, Tuple, Type, Union, overload +from typing import Any, Callable, Dict, Iterable, List, Mapping, Protocol, Tuple, Type, overload from typing_extensions import Literal class _SupportsTimeTuple(Protocol): diff --git a/stdlib/xmlrpc/server.pyi b/stdlib/xmlrpc/server.pyi index 50af0f90dff0..182f66ca150a 100644 --- a/stdlib/xmlrpc/server.pyi +++ b/stdlib/xmlrpc/server.pyi @@ -3,7 +3,7 @@ import pydoc import socketserver import sys from datetime import datetime -from typing import Any, Callable, Dict, Iterable, List, Mapping, Pattern, Protocol, Tuple, Type, Union +from typing import Any, Callable, Dict, Iterable, List, Mapping, Pattern, Protocol, Tuple, Type, from xmlrpc.client import Fault # TODO: Recursive type on tuple, list, dict diff --git a/stdlib/zipapp.pyi b/stdlib/zipapp.pyi index 2376dd697494..377e7b36f4ba 100644 --- a/stdlib/zipapp.pyi +++ b/stdlib/zipapp.pyi @@ -1,6 +1,6 @@ import sys from pathlib import Path -from typing import BinaryIO, Callable, Union +from typing import BinaryIO, Callable, _Path = str | Path | BinaryIO diff --git a/stubs/Pillow/PIL/Image.pyi b/stubs/Pillow/PIL/Image.pyi index 5af6714842b2..c2d9bca3436f 100644 --- a/stubs/Pillow/PIL/Image.pyi +++ b/stubs/Pillow/PIL/Image.pyi @@ -1,7 +1,7 @@ from _typeshed import SupportsRead, SupportsWrite from collections.abc import Iterable, Iterator, MutableMapping from pathlib import Path -from typing import Any, Callable, Dict, Protocol, Sequence, SupportsBytes, Tuple, Union +from typing import Any, Callable, Dict, Protocol, Sequence, SupportsBytes, Tuple, from typing_extensions import Literal from ._imaging import ( diff --git a/stubs/Pillow/PIL/ImageColor.pyi b/stubs/Pillow/PIL/ImageColor.pyi index 172376697712..28ae51d81061 100644 --- a/stubs/Pillow/PIL/ImageColor.pyi +++ b/stubs/Pillow/PIL/ImageColor.pyi @@ -1,4 +1,4 @@ -from typing import Tuple, Union +from typing import Tuple, _RGB = Tuple[int, int, int] | Tuple[int, int, int, int] _Ink = str | int | _RGB diff --git a/stubs/Pillow/PIL/ImageDraw.pyi b/stubs/Pillow/PIL/ImageDraw.pyi index 8e3ae38494c3..0fd02ec3c4ed 100644 --- a/stubs/Pillow/PIL/ImageDraw.pyi +++ b/stubs/Pillow/PIL/ImageDraw.pyi @@ -1,5 +1,5 @@ from collections.abc import Container -from typing import Any, Sequence, Tuple, Union, overload +from typing import Any, Sequence, Tuple, overload from typing_extensions import Literal from .Image import Image diff --git a/stubs/Pillow/PIL/TiffTags.pyi b/stubs/Pillow/PIL/TiffTags.pyi index a9ee9ddb95bb..f0a8c2b4753d 100644 --- a/stubs/Pillow/PIL/TiffTags.pyi +++ b/stubs/Pillow/PIL/TiffTags.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, NamedTuple, Tuple, Union +from typing import Any, Dict, NamedTuple, Tuple, from typing_extensions import Literal class _TagInfo(NamedTuple): diff --git a/stubs/PyMySQL/pymysql/converters.pyi b/stubs/PyMySQL/pymysql/converters.pyi index 0076660e1573..72f508bd874c 100644 --- a/stubs/PyMySQL/pymysql/converters.pyi +++ b/stubs/PyMySQL/pymysql/converters.pyi @@ -2,7 +2,7 @@ import datetime import time from collections.abc import Callable, Mapping, Sequence from decimal import Decimal -from typing import Any, Optional, Type, TypeVar +from typing import Any, Type, TypeVar _EscaperMapping = Mapping[Type[object], Callable[..., str]] | None _T = TypeVar("_T") diff --git a/stubs/PyYAML/yaml/constructor.pyi b/stubs/PyYAML/yaml/constructor.pyi index 7050dda1b1df..e0f029c216a8 100644 --- a/stubs/PyYAML/yaml/constructor.pyi +++ b/stubs/PyYAML/yaml/constructor.pyi @@ -1,4 +1,4 @@ -from typing import Any, Pattern, Union +from typing import Any, Pattern, from yaml.error import MarkedYAMLError from yaml.nodes import ScalarNode diff --git a/stubs/PyYAML/yaml/cyaml.pyi b/stubs/PyYAML/yaml/cyaml.pyi index 38e62d4c3592..536a6a5cb393 100644 --- a/stubs/PyYAML/yaml/cyaml.pyi +++ b/stubs/PyYAML/yaml/cyaml.pyi @@ -1,6 +1,6 @@ from _typeshed import SupportsRead from collections.abc import Mapping, Sequence -from typing import IO, Any, Union +from typing import IO, Any, from ._yaml import CEmitter, CParser from .constructor import BaseConstructor, FullConstructor, SafeConstructor, UnsafeConstructor diff --git a/stubs/Pygments/pygments/lexers/__init__.pyi b/stubs/Pygments/pygments/lexers/__init__.pyi index 97da2632b798..f4fa127a0853 100644 --- a/stubs/Pygments/pygments/lexers/__init__.pyi +++ b/stubs/Pygments/pygments/lexers/__init__.pyi @@ -1,6 +1,6 @@ from _typeshed import StrOrBytesPath, StrPath from collections.abc import Iterator -from typing import Any, Tuple, Union +from typing import Any, Tuple, from pygments.lexer import Lexer, LexerMeta diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index 85b1256e6e61..988fb721dc97 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import StrOrBytesPath from os import stat_result -from typing import Sequence, Union, overload +from typing import Sequence, overload _FdOrAnyPath = int | StrOrBytesPath diff --git a/stubs/aiofiles/aiofiles/threadpool/__init__.pyi b/stubs/aiofiles/aiofiles/threadpool/__init__.pyi index 27e451dd44f2..d81c1a2585b0 100644 --- a/stubs/aiofiles/aiofiles/threadpool/__init__.pyi +++ b/stubs/aiofiles/aiofiles/threadpool/__init__.pyi @@ -7,7 +7,7 @@ from _typeshed import ( StrOrBytesPath, ) from asyncio import AbstractEventLoop -from typing import Any, Callable, Union, overload +from typing import Any, Callable, overload from typing_extensions import Literal from ..base import AiofilesContextManager diff --git a/stubs/beautifulsoup4/bs4/element.pyi b/stubs/beautifulsoup4/bs4/element.pyi index 7d88ddc1e1c3..8ea1c6ee2bfe 100644 --- a/stubs/beautifulsoup4/bs4/element.pyi +++ b/stubs/beautifulsoup4/bs4/element.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from collections.abc import Iterator -from typing import Any, Callable, Generic, Iterable, List, Mapping, Pattern, Tuple, Type, TypeVar, Union, overload +from typing import Any, Callable, Generic, Iterable, List, Mapping, Pattern, Tuple, Type, TypeVar, overload from . import BeautifulSoup from .builder import TreeBuilder diff --git a/stubs/bleach/bleach/sanitizer.pyi b/stubs/bleach/bleach/sanitizer.pyi index 96ae5a93eb1d..06a752a59e69 100644 --- a/stubs/bleach/bleach/sanitizer.pyi +++ b/stubs/bleach/bleach/sanitizer.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable, Container, Iterable -from typing import Any, Dict, List, Pattern, Union +from typing import Any, Dict, List, Pattern, from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter diff --git a/stubs/colorama/colorama/ansitowin32.pyi b/stubs/colorama/colorama/ansitowin32.pyi index 36839ec8a6e7..20c7edc49df6 100644 --- a/stubs/colorama/colorama/ansitowin32.pyi +++ b/stubs/colorama/colorama/ansitowin32.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import SupportsWrite -from typing import Any, Callable, Dict, Optional, Pattern, Sequence, TextIO, Tuple, Union +from typing import Any, Callable, Dict, Pattern, Sequence, TextIO, Tuple, if sys.platform == "win32": from .winterm import WinTerm diff --git a/stubs/croniter/croniter.pyi b/stubs/croniter/croniter.pyi index 18768c4ddb7c..1c6520d8e180 100644 --- a/stubs/croniter/croniter.pyi +++ b/stubs/croniter/croniter.pyi @@ -1,5 +1,5 @@ import datetime -from typing import Any, Iterator, Text, Tuple, Type, TypeVar, Union +from typing import Any, Iterator, Text, Tuple, Type, TypeVar, from typing_extensions import Literal _RetType = Type[float] | Type[datetime.datetime] diff --git a/stubs/docopt/docopt.pyi b/stubs/docopt/docopt.pyi index f4f4b9025be5..44139cff44b5 100644 --- a/stubs/docopt/docopt.pyi +++ b/stubs/docopt/docopt.pyi @@ -1,4 +1,4 @@ -from typing import Any, Iterable, Union +from typing import Any, Iterable, __version__: str diff --git a/stubs/freezegun/freezegun/api.pyi b/stubs/freezegun/freezegun/api.pyi index 56084228479a..d2524444be45 100644 --- a/stubs/freezegun/freezegun/api.pyi +++ b/stubs/freezegun/freezegun/api.pyi @@ -1,7 +1,7 @@ from collections.abc import Awaitable, Callable, Iterator, Sequence from datetime import date, datetime, timedelta from numbers import Real -from typing import Any, Type, TypeVar, Union, overload +from typing import Any, Type, TypeVar, overload _T = TypeVar("_T") _Freezable = str | datetime | date | timedelta diff --git a/stubs/paramiko/paramiko/common.pyi b/stubs/paramiko/paramiko/common.pyi index a4678986d8ee..7dba37326b82 100644 --- a/stubs/paramiko/paramiko/common.pyi +++ b/stubs/paramiko/paramiko/common.pyi @@ -1,5 +1,5 @@ import sys -from typing import Protocol, Text, Union +from typing import Protocol, Text, MSG_DISCONNECT: int MSG_IGNORE: int diff --git a/stubs/pyOpenSSL/OpenSSL/crypto.pyi b/stubs/pyOpenSSL/OpenSSL/crypto.pyi index 81bd0606aef4..293423393b17 100644 --- a/stubs/pyOpenSSL/OpenSSL/crypto.pyi +++ b/stubs/pyOpenSSL/OpenSSL/crypto.pyi @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Any, Callable, Iterable, Sequence, Text, Tuple, Union +from typing import Any, Callable, Iterable, Sequence, Text, Tuple, from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPublicKey from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index ec13cc385bd8..dbdbd76143f7 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -1,4 +1,4 @@ -from typing import Callable, Mapping, Optional, Sequence, Tuple, Union +from typing import Callable, Mapping, Sequence, Tuple, from typing_extensions import Final paFloat32: Final[int] = ... diff --git a/stubs/pysftp/pysftp/__init__.pyi b/stubs/pysftp/pysftp/__init__.pyi index 91809756f840..c11477bdbbee 100644 --- a/stubs/pysftp/pysftp/__init__.pyi +++ b/stubs/pysftp/pysftp/__init__.pyi @@ -1,6 +1,6 @@ from stat import S_IMODE as S_IMODE from types import TracebackType -from typing import IO, Any, Callable, ContextManager, Sequence, Text, Type, Union +from typing import IO, Any, Callable, ContextManager, Sequence, Text, Type, from typing_extensions import Literal import paramiko diff --git a/stubs/python-dateutil/dateutil/parser/__init__.pyi b/stubs/python-dateutil/dateutil/parser/__init__.pyi index bfb7f1f2779e..ae6d93b59410 100644 --- a/stubs/python-dateutil/dateutil/parser/__init__.pyi +++ b/stubs/python-dateutil/dateutil/parser/__init__.pyi @@ -1,5 +1,5 @@ from datetime import datetime, tzinfo -from typing import IO, Any, Mapping, Text, Union +from typing import IO, Any, Mapping, Text, from .isoparser import isoparse as isoparse, isoparser as isoparser diff --git a/stubs/python-dateutil/dateutil/parser/isoparser.pyi b/stubs/python-dateutil/dateutil/parser/isoparser.pyi index 18614065ffdc..636a5577759f 100644 --- a/stubs/python-dateutil/dateutil/parser/isoparser.pyi +++ b/stubs/python-dateutil/dateutil/parser/isoparser.pyi @@ -1,6 +1,6 @@ from _typeshed import SupportsRead from datetime import date, datetime, time, tzinfo -from typing import Text, Union +from typing import Text, _Readable = SupportsRead[Text | bytes] _TakesAscii = Text | bytes | _Readable diff --git a/stubs/python-dateutil/dateutil/tz/tz.pyi b/stubs/python-dateutil/dateutil/tz/tz.pyi index e58f580f551e..53e0fa7e8fdd 100644 --- a/stubs/python-dateutil/dateutil/tz/tz.pyi +++ b/stubs/python-dateutil/dateutil/tz/tz.pyi @@ -1,5 +1,5 @@ import datetime -from typing import IO, Any, Text, TypeVar, Union +from typing import IO, Any, Text, TypeVar, from ..relativedelta import relativedelta from ._common import _tzinfo as _tzinfo, enfold as enfold, tzname_in_python2 as tzname_in_python2, tzrangebase as tzrangebase diff --git a/stubs/redis/redis/client.pyi b/stubs/redis/redis/client.pyi index 916eed1f24a0..adcc9db9f3ec 100644 --- a/stubs/redis/redis/client.pyi +++ b/stubs/redis/redis/client.pyi @@ -15,7 +15,7 @@ from typing import ( Sequence, Type, TypeVar, - Union, + overload, ) from typing_extensions import Literal diff --git a/stubs/redis/redis/commands/core.pyi b/stubs/redis/redis/commands/core.pyi index 2ef6e8a3b3f2..7671560013f3 100644 --- a/stubs/redis/redis/commands/core.pyi +++ b/stubs/redis/redis/commands/core.pyi @@ -1,6 +1,6 @@ from collections.abc import Callable, Iterable, Mapping, Sequence from datetime import timedelta -from typing import Any, Generic, TypeVar, Union, overload +from typing import Any, Generic, TypeVar, overload from typing_extensions import Literal from ..client import _Key, _Value diff --git a/stubs/requests/requests/sessions.pyi b/stubs/requests/requests/sessions.pyi index 74d66ffe5183..a12cc60284bb 100644 --- a/stubs/requests/requests/sessions.pyi +++ b/stubs/requests/requests/sessions.pyi @@ -1,5 +1,5 @@ from _typeshed import SupportsItems -from typing import IO, Any, Callable, Iterable, List, Mapping, MutableMapping, Optional, Text, Tuple, TypeVar, Union +from typing import IO, Any, Callable, Iterable, List, Mapping, MutableMapping, Text, Tuple, TypeVar, from . import adapters, auth as _auth, compat, cookies, exceptions, hooks, models, status_codes, structures, utils from .models import Response diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index 16cfdce4aea1..3e12b7313996 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -2,7 +2,7 @@ import importlib.abc import types import zipimport from abc import ABCMeta -from typing import IO, Any, Callable, Generator, Iterable, Optional, Sequence, Tuple, TypeVar, Union, overload +from typing import IO, Any, Callable, Generator, Iterable, Sequence, Tuple, TypeVar, overload LegacyVersion = Any # from packaging.version Version = Any # from packaging.version diff --git a/stubs/simplejson/simplejson/__init__.pyi b/stubs/simplejson/simplejson/__init__.pyi index d374f70dc3f4..13ec9e3f2513 100644 --- a/stubs/simplejson/simplejson/__init__.pyi +++ b/stubs/simplejson/simplejson/__init__.pyi @@ -1,4 +1,4 @@ -from typing import IO, Any, Text, Union +from typing import IO, Any, Text, from simplejson.decoder import JSONDecoder as JSONDecoder from simplejson.encoder import JSONEncoder as JSONEncoder, JSONEncoderForHTML as JSONEncoderForHTML diff --git a/stubs/tabulate/tabulate.pyi b/stubs/tabulate/tabulate.pyi index eafcfb352c06..ae1b94b3f2c0 100644 --- a/stubs/tabulate/tabulate.pyi +++ b/stubs/tabulate/tabulate.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Container, Iterable, List, Mapping, NamedTuple, Sequence, Union +from typing import Any, Callable, Container, Iterable, List, Mapping, NamedTuple, Sequence, LATEX_ESCAPE_RULES: dict[str, str] MIN_PADDING: int diff --git a/stubs/toml/toml.pyi b/stubs/toml/toml.pyi index 3c672e648228..96786ac96c86 100644 --- a/stubs/toml/toml.pyi +++ b/stubs/toml/toml.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import StrPath, SupportsWrite -from typing import IO, Any, Mapping, MutableMapping, Text, Type, Union +from typing import IO, Any, Mapping, MutableMapping, Text, Type, if sys.version_info >= (3, 6): _PathLike = StrPath From 4a859fdcbe03119c2ff606937e11539740421750 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 16 Dec 2021 20:01:25 +0200 Subject: [PATCH 05/11] fix syntax errors --- stdlib/_codecs.pyi | 2 +- stdlib/_csv.pyi | 2 +- stdlib/_typeshed/__init__.pyi | 2 +- stdlib/asyncio/base_subprocess.pyi | 2 +- stdlib/asyncio/streams.pyi | 2 +- stdlib/asyncio/subprocess.pyi | 2 +- stdlib/binhex.pyi | 2 +- stdlib/cmath.pyi | 2 +- stdlib/copyreg.pyi | 2 +- stdlib/dbm/__init__.pyi | 2 +- stdlib/dbm/dumb.pyi | 2 +- stdlib/dis.pyi | 2 +- stdlib/distutils/ccompiler.pyi | 2 +- stdlib/email/_header_value_parser.pyi | 2 +- stdlib/email/message.pyi | 2 +- stdlib/email/mime/application.pyi | 2 +- stdlib/email/mime/audio.pyi | 2 +- stdlib/email/mime/base.pyi | 2 +- stdlib/email/mime/image.pyi | 2 +- stdlib/email/mime/multipart.pyi | 2 +- stdlib/imaplib.pyi | 2 +- stdlib/importlib/resources.pyi | 2 +- stdlib/inspect.pyi | 2 +- stdlib/lib2to3/pytree.pyi | 2 +- stdlib/mailcap.pyi | 2 +- stdlib/multiprocessing/connection.pyi | 2 +- stdlib/multiprocessing/dummy/connection.pyi | 2 +- stdlib/multiprocessing/synchronize.pyi | 2 +- stdlib/nntplib.pyi | 2 +- stdlib/pickle.pyi | 2 +- stdlib/signal.pyi | 2 +- stdlib/socketserver.pyi | 2 +- stdlib/statistics.pyi | 2 +- stdlib/sunau.pyi | 2 +- stdlib/termios.pyi | 2 +- stdlib/timeit.pyi | 2 +- stdlib/tokenize.pyi | 2 +- stdlib/tty.pyi | 2 +- stdlib/unittest/result.pyi | 2 +- stdlib/unittest/suite.pyi | 2 +- stdlib/uu.pyi | 2 +- stdlib/wave.pyi | 2 +- stdlib/winreg.pyi | 2 +- stdlib/xml/dom/pulldom.pyi | 2 +- stdlib/xml/dom/xmlbuilder.pyi | 2 +- stdlib/xmlrpc/server.pyi | 2 +- stdlib/zipapp.pyi | 2 +- stubs/Pillow/PIL/Image.pyi | 2 +- stubs/Pillow/PIL/ImageColor.pyi | 2 +- stubs/Pillow/PIL/TiffTags.pyi | 2 +- stubs/PyYAML/yaml/constructor.pyi | 2 +- stubs/PyYAML/yaml/cyaml.pyi | 2 +- stubs/Pygments/pygments/lexers/__init__.pyi | 2 +- stubs/bleach/bleach/sanitizer.pyi | 2 +- stubs/colorama/colorama/ansitowin32.pyi | 2 +- stubs/croniter/croniter.pyi | 2 +- stubs/docopt/docopt.pyi | 2 +- stubs/paramiko/paramiko/common.pyi | 2 +- stubs/pyOpenSSL/OpenSSL/crypto.pyi | 2 +- stubs/pyaudio/pyaudio.pyi | 2 +- stubs/pysftp/pysftp/__init__.pyi | 2 +- stubs/python-dateutil/dateutil/parser/__init__.pyi | 2 +- stubs/python-dateutil/dateutil/parser/isoparser.pyi | 2 +- stubs/python-dateutil/dateutil/tz/tz.pyi | 2 +- stubs/requests/requests/sessions.pyi | 2 +- stubs/simplejson/simplejson/__init__.pyi | 2 +- stubs/tabulate/tabulate.pyi | 2 +- stubs/toml/toml.pyi | 2 +- 68 files changed, 68 insertions(+), 68 deletions(-) diff --git a/stdlib/_codecs.pyi b/stdlib/_codecs.pyi index 7a098a949269..6bc3951188ba 100644 --- a/stdlib/_codecs.pyi +++ b/stdlib/_codecs.pyi @@ -1,6 +1,6 @@ import codecs import sys -from typing import Any, Callable, Dict, Tuple, +from typing import Any, Callable, Dict, Tuple # This type is not exposed; it is defined in unicodeobject.c class _EncodingMap: diff --git a/stdlib/_csv.pyi b/stdlib/_csv.pyi index c06d74616161..c6d720e02c93 100644 --- a/stdlib/_csv.pyi +++ b/stdlib/_csv.pyi @@ -1,4 +1,4 @@ -from typing import Any, Iterable, Iterator, List, Protocol, Type, +from typing import Any, Iterable, Iterator, List, Protocol, Type QUOTE_ALL: int QUOTE_MINIMAL: int diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 4fb46f6d97ff..8fbe512d75ca 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -7,7 +7,7 @@ import ctypes import mmap import sys from os import PathLike -from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, TypeVar, +from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, TypeVar from typing_extensions import Literal, final _KT = TypeVar("_KT") diff --git a/stdlib/asyncio/base_subprocess.pyi b/stdlib/asyncio/base_subprocess.pyi index 724a287ca158..6501a3eef86b 100644 --- a/stdlib/asyncio/base_subprocess.pyi +++ b/stdlib/asyncio/base_subprocess.pyi @@ -1,6 +1,6 @@ import subprocess from collections import deque -from typing import IO, Any, Callable, Sequence, Tuple, +from typing import IO, Any, Callable, Sequence, Tuple from . import events, futures, protocols, transports diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 51f10efcff17..c4649f8c0a62 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import StrPath -from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, +from typing import Any, AsyncIterator, Awaitable, Callable, Iterable from . import events, protocols, transports from .base_events import Server diff --git a/stdlib/asyncio/subprocess.pyi b/stdlib/asyncio/subprocess.pyi index 7752d42ba501..4a3d155899f9 100644 --- a/stdlib/asyncio/subprocess.pyi +++ b/stdlib/asyncio/subprocess.pyi @@ -2,7 +2,7 @@ import subprocess import sys from _typeshed import StrOrBytesPath from asyncio import events, protocols, streams, transports -from typing import IO, Any, Callable, +from typing import IO, Any, Callable from typing_extensions import Literal if sys.version_info >= (3, 8): diff --git a/stdlib/binhex.pyi b/stdlib/binhex.pyi index 7ebb1c2b1957..8383a028a6cd 100644 --- a/stdlib/binhex.pyi +++ b/stdlib/binhex.pyi @@ -1,4 +1,4 @@ -from typing import IO, Any, Tuple, +from typing import IO, Any, Tuple class Error(Exception): ... diff --git a/stdlib/cmath.pyi b/stdlib/cmath.pyi index f97161e7dcb3..ee51861fdaa0 100644 --- a/stdlib/cmath.pyi +++ b/stdlib/cmath.pyi @@ -1,5 +1,5 @@ import sys -from typing import SupportsComplex, SupportsFloat, +from typing import SupportsComplex, SupportsFloat if sys.version_info >= (3, 8): from typing import SupportsIndex diff --git a/stdlib/copyreg.pyi b/stdlib/copyreg.pyi index 8c83a3bbb49b..8700ccf6265a 100644 --- a/stdlib/copyreg.pyi +++ b/stdlib/copyreg.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Hashable, SupportsInt, Tuple, TypeVar, +from typing import Any, Callable, Hashable, SupportsInt, Tuple, TypeVar _TypeT = TypeVar("_TypeT", bound=type) _Reduce = Tuple[Callable[..., _TypeT], Tuple[Any, ...]] | Tuple[Callable[..., _TypeT], Tuple[Any, ...], Any | None] diff --git a/stdlib/dbm/__init__.pyi b/stdlib/dbm/__init__.pyi index 39653fbf78e5..80826851d933 100644 --- a/stdlib/dbm/__init__.pyi +++ b/stdlib/dbm/__init__.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Iterator, MutableMapping, Type, +from typing import Iterator, MutableMapping, Type from typing_extensions import Literal _KeyType = str | bytes diff --git a/stdlib/dbm/dumb.pyi b/stdlib/dbm/dumb.pyi index 8d63d4f85124..16c2cc826ef1 100644 --- a/stdlib/dbm/dumb.pyi +++ b/stdlib/dbm/dumb.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Iterator, MutableMapping, Type, +from typing import Iterator, MutableMapping, Type _KeyType = str | bytes _ValueType = str | bytes diff --git a/stdlib/dis.pyi b/stdlib/dis.pyi index a98f5c11fc17..b29f4810d1f9 100644 --- a/stdlib/dis.pyi +++ b/stdlib/dis.pyi @@ -16,7 +16,7 @@ from opcode import ( opname as opname, stack_effect as stack_effect, ) -from typing import IO, Any, Callable, Iterator, NamedTuple, +from typing import IO, Any, Callable, Iterator, NamedTuple # Strictly this should not have to include Callable, but mypy doesn't use FunctionType # for functions (python/mypy#3171) diff --git a/stdlib/distutils/ccompiler.pyi b/stdlib/distutils/ccompiler.pyi index be3cb80b54d3..f20f1b344e96 100644 --- a/stdlib/distutils/ccompiler.pyi +++ b/stdlib/distutils/ccompiler.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Tuple, +from typing import Any, Callable, Tuple _Macro = Tuple[str] | Tuple[str, str | None] diff --git a/stdlib/email/_header_value_parser.pyi b/stdlib/email/_header_value_parser.pyi index e8bff4435ea0..993413482ef2 100644 --- a/stdlib/email/_header_value_parser.pyi +++ b/stdlib/email/_header_value_parser.pyi @@ -1,7 +1,7 @@ import sys from email.errors import HeaderParseError, MessageDefect from email.policy import Policy -from typing import Any, Iterable, Iterator, List, Pattern, Type, TypeVar, +from typing import Any, Iterable, Iterator, List, Pattern, Type, TypeVar from typing_extensions import Final _T = TypeVar("_T") diff --git a/stdlib/email/message.pyi b/stdlib/email/message.pyi index 793b986c3250..9724b1c0aca3 100644 --- a/stdlib/email/message.pyi +++ b/stdlib/email/message.pyi @@ -2,7 +2,7 @@ from email.charset import Charset from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy -from typing import Any, Generator, Iterator, List, Sequence, Tuple, TypeVar, +from typing import Any, Generator, Iterator, List, Sequence, Tuple, TypeVar _T = TypeVar("_T") diff --git a/stdlib/email/mime/application.pyi b/stdlib/email/mime/application.pyi index 9ba62fb84da9..4aaf41dc5ff8 100644 --- a/stdlib/email/mime/application.pyi +++ b/stdlib/email/mime/application.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple, +from typing import Callable, Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/audio.pyi b/stdlib/email/mime/audio.pyi index 8d82b82eb345..24cefbf797cf 100644 --- a/stdlib/email/mime/audio.pyi +++ b/stdlib/email/mime/audio.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple, +from typing import Callable, Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/base.pyi b/stdlib/email/mime/base.pyi index c870eea780ec..a334fa4869c4 100644 --- a/stdlib/email/mime/base.pyi +++ b/stdlib/email/mime/base.pyi @@ -1,6 +1,6 @@ import email.message from email.policy import Policy -from typing import Tuple, +from typing import Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/image.pyi b/stdlib/email/mime/image.pyi index daa1f3be3643..4c8ec4f24494 100644 --- a/stdlib/email/mime/image.pyi +++ b/stdlib/email/mime/image.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple, +from typing import Callable, Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/multipart.pyi b/stdlib/email/mime/multipart.pyi index 5dcdaadd7b83..75796dfc4305 100644 --- a/stdlib/email/mime/multipart.pyi +++ b/stdlib/email/mime/multipart.pyi @@ -1,7 +1,7 @@ from email.message import Message from email.mime.base import MIMEBase from email.policy import Policy -from typing import Sequence, Tuple, +from typing import Sequence, Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/imaplib.pyi b/stdlib/imaplib.pyi index d86ee35f0a05..5e0b1bb05dd0 100644 --- a/stdlib/imaplib.pyi +++ b/stdlib/imaplib.pyi @@ -5,7 +5,7 @@ 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, List, Pattern, Tuple, Type, +from typing import IO, Any, Callable, List, Pattern, Tuple, Type from typing_extensions import Literal # TODO: Commands should use their actual return types, not this type alias. diff --git a/stdlib/importlib/resources.pyi b/stdlib/importlib/resources.pyi index 6b4ec55839ea..f832e063e927 100644 --- a/stdlib/importlib/resources.pyi +++ b/stdlib/importlib/resources.pyi @@ -7,7 +7,7 @@ if sys.version_info >= (3, 7): from contextlib import AbstractContextManager from pathlib import Path from types import ModuleType - from typing import BinaryIO, Iterator, TextIO, + from typing import BinaryIO, Iterator, TextIO Package = str | ModuleType Resource = str | os.PathLike[Any] diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index d8a276a2b5b9..07b4fbfaa80f 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -23,7 +23,7 @@ from types import ( if sys.version_info >= (3, 7): from types import ClassMethodDescriptorType, WrapperDescriptorType, MemberDescriptorType, MethodDescriptorType -from typing import Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar, +from typing import Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar from typing_extensions import Literal, TypeGuard # diff --git a/stdlib/lib2to3/pytree.pyi b/stdlib/lib2to3/pytree.pyi index 2c534fc4761a..8f9a246f8f64 100644 --- a/stdlib/lib2to3/pytree.pyi +++ b/stdlib/lib2to3/pytree.pyi @@ -1,5 +1,5 @@ from lib2to3.pgen2.grammar import Grammar -from typing import Any, Callable, Dict, Iterator, List, Tuple, TypeVar, +from typing import Any, Callable, Dict, Iterator, List, Tuple, TypeVar _P = TypeVar("_P") _NL = Node | Leaf diff --git a/stdlib/mailcap.pyi b/stdlib/mailcap.pyi index 84620c438728..f72d819576a4 100644 --- a/stdlib/mailcap.pyi +++ b/stdlib/mailcap.pyi @@ -1,4 +1,4 @@ -from typing import Dict, Mapping, Sequence, +from typing import Dict, Mapping, Sequence _Cap = Dict[str, str | int] diff --git a/stdlib/multiprocessing/connection.pyi b/stdlib/multiprocessing/connection.pyi index af13c6f8b74c..0d5b521b0f2a 100644 --- a/stdlib/multiprocessing/connection.pyi +++ b/stdlib/multiprocessing/connection.pyi @@ -2,7 +2,7 @@ import socket import sys import types from _typeshed import Self -from typing import Any, Iterable, Tuple, Type, +from typing import Any, Iterable, Tuple, Type if sys.version_info >= (3, 8): from typing import SupportsIndex diff --git a/stdlib/multiprocessing/dummy/connection.pyi b/stdlib/multiprocessing/dummy/connection.pyi index 13688de53aea..2b43fcfd6248 100644 --- a/stdlib/multiprocessing/dummy/connection.pyi +++ b/stdlib/multiprocessing/dummy/connection.pyi @@ -1,7 +1,7 @@ from _typeshed import Self from queue import Queue from types import TracebackType -from typing import Any, Tuple, Type, +from typing import Any, Tuple, Type families: list[None] diff --git a/stdlib/multiprocessing/synchronize.pyi b/stdlib/multiprocessing/synchronize.pyi index 61de45a4216c..685bbd1bcabb 100644 --- a/stdlib/multiprocessing/synchronize.pyi +++ b/stdlib/multiprocessing/synchronize.pyi @@ -2,7 +2,7 @@ import sys import threading from contextlib import AbstractContextManager from multiprocessing.context import BaseContext -from typing import Any, Callable, +from typing import Any, Callable _LockLike = Lock | RLock diff --git a/stdlib/nntplib.pyi b/stdlib/nntplib.pyi index 23cddd033484..3f308e2a2dd7 100644 --- a/stdlib/nntplib.pyi +++ b/stdlib/nntplib.pyi @@ -3,7 +3,7 @@ import socket import ssl import sys from _typeshed import Self -from typing import IO, Any, Iterable, NamedTuple, Tuple, +from typing import IO, Any, Iterable, NamedTuple, Tuple _File = IO[bytes] | bytes | str | None diff --git a/stdlib/pickle.pyi b/stdlib/pickle.pyi index e5212ed485ff..c3859f681881 100644 --- a/stdlib/pickle.pyi +++ b/stdlib/pickle.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Protocol, Tuple, Type, +from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Protocol, Tuple, Type from typing_extensions import final HIGHEST_PROTOCOL: int diff --git a/stdlib/signal.pyi b/stdlib/signal.pyi index 69b518d545d8..e033ee6a911e 100644 --- a/stdlib/signal.pyi +++ b/stdlib/signal.pyi @@ -1,7 +1,7 @@ import sys from enum import IntEnum from types import FrameType -from typing import Any, Callable, Iterable, Tuple, +from typing import Any, Callable, Iterable, Tuple NSIG: int diff --git a/stdlib/socketserver.pyi b/stdlib/socketserver.pyi index 9cfd53f853c3..a3c9c9a25fce 100644 --- a/stdlib/socketserver.pyi +++ b/stdlib/socketserver.pyi @@ -2,7 +2,7 @@ import sys import types from _typeshed import Self from socket import socket as _socket -from typing import Any, BinaryIO, Callable, ClassVar, Tuple, Type, TypeVar, +from typing import Any, BinaryIO, Callable, ClassVar, Tuple, Type, TypeVar _T = TypeVar("_T") _RequestType = _socket | Tuple[bytes, _socket] diff --git a/stdlib/statistics.pyi b/stdlib/statistics.pyi index f1a1f449e491..5a549c75cc2e 100644 --- a/stdlib/statistics.pyi +++ b/stdlib/statistics.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsRichComparisonT from decimal import Decimal from fractions import Fraction -from typing import Any, Hashable, Iterable, NamedTuple, Sequence, SupportsFloat, Type, TypeVar, +from typing import Any, Hashable, Iterable, NamedTuple, Sequence, SupportsFloat, Type, TypeVar _T = TypeVar("_T") # Most functions in this module accept homogeneous collections of one of these types diff --git a/stdlib/sunau.pyi b/stdlib/sunau.pyi index 81fcd1649a4f..9673ab473421 100644 --- a/stdlib/sunau.pyi +++ b/stdlib/sunau.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import Self -from typing import IO, Any, NamedTuple, NoReturn, +from typing import IO, Any, NamedTuple, NoReturn _File = str | IO[bytes] diff --git a/stdlib/termios.pyi b/stdlib/termios.pyi index 39fecd4c5fe8..d9c7fb8cd697 100644 --- a/stdlib/termios.pyi +++ b/stdlib/termios.pyi @@ -1,5 +1,5 @@ from _typeshed import FileDescriptorLike -from typing import Any, List, +from typing import Any, List _Attr = List[int | List[bytes | int]] diff --git a/stdlib/timeit.pyi b/stdlib/timeit.pyi index 9e3a0f293731..7d85942ddd37 100644 --- a/stdlib/timeit.pyi +++ b/stdlib/timeit.pyi @@ -1,4 +1,4 @@ -from typing import IO, Any, Callable, Sequence, +from typing import IO, Any, Callable, Sequence _Timer = Callable[[], float] _Stmt = str | Callable[[], Any] diff --git a/stdlib/tokenize.pyi b/stdlib/tokenize.pyi index 10ad5dda930e..91e661912908 100644 --- a/stdlib/tokenize.pyi +++ b/stdlib/tokenize.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import StrOrBytesPath from builtins import open as _builtin_open from token import * # noqa: F403 -from typing import Any, Callable, Generator, Iterable, NamedTuple, Pattern, Sequence, TextIO, Tuple, +from typing import Any, Callable, Generator, Iterable, NamedTuple, Pattern, Sequence, TextIO, Tuple if sys.version_info < (3, 7): COMMENT: int diff --git a/stdlib/tty.pyi b/stdlib/tty.pyi index d3c1e7786b5b..c25f22a5a4ff 100644 --- a/stdlib/tty.pyi +++ b/stdlib/tty.pyi @@ -1,4 +1,4 @@ -from typing import IO, +from typing import IO _FD = int | IO[str] diff --git a/stdlib/unittest/result.pyi b/stdlib/unittest/result.pyi index d56e6a42c8c9..427b059f0c7d 100644 --- a/stdlib/unittest/result.pyi +++ b/stdlib/unittest/result.pyi @@ -1,6 +1,6 @@ import unittest.case from types import TracebackType -from typing import Any, Callable, TextIO, Tuple, Type, TypeVar, +from typing import Any, Callable, TextIO, Tuple, Type, TypeVar _SysExcInfoType = Tuple[Type[BaseException], BaseException, TracebackType] | Tuple[None, None, None] diff --git a/stdlib/unittest/suite.pyi b/stdlib/unittest/suite.pyi index 7dd16b54cbc0..3d7f87c9b20f 100644 --- a/stdlib/unittest/suite.pyi +++ b/stdlib/unittest/suite.pyi @@ -1,6 +1,6 @@ import unittest.case import unittest.result -from typing import Iterable, Iterator, +from typing import Iterable, Iterator _TestType = unittest.case.TestCase | TestSuite diff --git a/stdlib/uu.pyi b/stdlib/uu.pyi index 207c27356aa1..3687a843d39d 100644 --- a/stdlib/uu.pyi +++ b/stdlib/uu.pyi @@ -1,5 +1,5 @@ import sys -from typing import BinaryIO, +from typing import BinaryIO _File = str | BinaryIO diff --git a/stdlib/wave.pyi b/stdlib/wave.pyi index e650b73eaf83..aef20986572a 100644 --- a/stdlib/wave.pyi +++ b/stdlib/wave.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import Self -from typing import IO, Any, BinaryIO, NamedTuple, NoReturn, +from typing import IO, Any, BinaryIO, NamedTuple, NoReturn _File = str | IO[bytes] diff --git a/stdlib/winreg.pyi b/stdlib/winreg.pyi index e724a6cbf315..13f784111554 100644 --- a/stdlib/winreg.pyi +++ b/stdlib/winreg.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Any, Type, +from typing import Any, Type from typing_extensions import final _KeyType = HKEYType | int diff --git a/stdlib/xml/dom/pulldom.pyi b/stdlib/xml/dom/pulldom.pyi index b465736dfb70..72399ff261b0 100644 --- a/stdlib/xml/dom/pulldom.pyi +++ b/stdlib/xml/dom/pulldom.pyi @@ -1,5 +1,5 @@ import sys -from typing import IO, Any, Sequence, Tuple, +from typing import IO, Any, Sequence, Tuple from typing_extensions import Literal from xml.dom.minidom import Document, DOMImplementation, Element, Text from xml.sax.handler import ContentHandler diff --git a/stdlib/xml/dom/xmlbuilder.pyi b/stdlib/xml/dom/xmlbuilder.pyi index 93c2eb1d56ee..5792842eaf9d 100644 --- a/stdlib/xml/dom/xmlbuilder.pyi +++ b/stdlib/xml/dom/xmlbuilder.pyi @@ -1,4 +1,4 @@ -from typing import Any, NoReturn, +from typing import Any, NoReturn from typing_extensions import Literal from urllib.request import OpenerDirector from xml.dom.expatbuilder import ExpatBuilder, ExpatBuilderNS diff --git a/stdlib/xmlrpc/server.pyi b/stdlib/xmlrpc/server.pyi index 182f66ca150a..9b16196d887f 100644 --- a/stdlib/xmlrpc/server.pyi +++ b/stdlib/xmlrpc/server.pyi @@ -3,7 +3,7 @@ import pydoc import socketserver import sys from datetime import datetime -from typing import Any, Callable, Dict, Iterable, List, Mapping, Pattern, Protocol, Tuple, Type, +from typing import Any, Callable, Dict, Iterable, List, Mapping, Pattern, Protocol, Tuple, Type from xmlrpc.client import Fault # TODO: Recursive type on tuple, list, dict diff --git a/stdlib/zipapp.pyi b/stdlib/zipapp.pyi index 377e7b36f4ba..4ed6cf5d0a0a 100644 --- a/stdlib/zipapp.pyi +++ b/stdlib/zipapp.pyi @@ -1,6 +1,6 @@ import sys from pathlib import Path -from typing import BinaryIO, Callable, +from typing import BinaryIO, Callable _Path = str | Path | BinaryIO diff --git a/stubs/Pillow/PIL/Image.pyi b/stubs/Pillow/PIL/Image.pyi index c2d9bca3436f..ed750b4fba9b 100644 --- a/stubs/Pillow/PIL/Image.pyi +++ b/stubs/Pillow/PIL/Image.pyi @@ -1,7 +1,7 @@ from _typeshed import SupportsRead, SupportsWrite from collections.abc import Iterable, Iterator, MutableMapping from pathlib import Path -from typing import Any, Callable, Dict, Protocol, Sequence, SupportsBytes, Tuple, +from typing import Any, Callable, Dict, Protocol, Sequence, SupportsBytes, Tuple from typing_extensions import Literal from ._imaging import ( diff --git a/stubs/Pillow/PIL/ImageColor.pyi b/stubs/Pillow/PIL/ImageColor.pyi index 28ae51d81061..59a5dc8505d8 100644 --- a/stubs/Pillow/PIL/ImageColor.pyi +++ b/stubs/Pillow/PIL/ImageColor.pyi @@ -1,4 +1,4 @@ -from typing import Tuple, +from typing import Tuple _RGB = Tuple[int, int, int] | Tuple[int, int, int, int] _Ink = str | int | _RGB diff --git a/stubs/Pillow/PIL/TiffTags.pyi b/stubs/Pillow/PIL/TiffTags.pyi index f0a8c2b4753d..57ef38add890 100644 --- a/stubs/Pillow/PIL/TiffTags.pyi +++ b/stubs/Pillow/PIL/TiffTags.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, NamedTuple, Tuple, +from typing import Any, Dict, NamedTuple, Tuple from typing_extensions import Literal class _TagInfo(NamedTuple): diff --git a/stubs/PyYAML/yaml/constructor.pyi b/stubs/PyYAML/yaml/constructor.pyi index e0f029c216a8..c030cd23a2bb 100644 --- a/stubs/PyYAML/yaml/constructor.pyi +++ b/stubs/PyYAML/yaml/constructor.pyi @@ -1,4 +1,4 @@ -from typing import Any, Pattern, +from typing import Any, Pattern from yaml.error import MarkedYAMLError from yaml.nodes import ScalarNode diff --git a/stubs/PyYAML/yaml/cyaml.pyi b/stubs/PyYAML/yaml/cyaml.pyi index 536a6a5cb393..74946311ec94 100644 --- a/stubs/PyYAML/yaml/cyaml.pyi +++ b/stubs/PyYAML/yaml/cyaml.pyi @@ -1,6 +1,6 @@ from _typeshed import SupportsRead from collections.abc import Mapping, Sequence -from typing import IO, Any, +from typing import IO, Any from ._yaml import CEmitter, CParser from .constructor import BaseConstructor, FullConstructor, SafeConstructor, UnsafeConstructor diff --git a/stubs/Pygments/pygments/lexers/__init__.pyi b/stubs/Pygments/pygments/lexers/__init__.pyi index f4fa127a0853..7f53a1b9ff79 100644 --- a/stubs/Pygments/pygments/lexers/__init__.pyi +++ b/stubs/Pygments/pygments/lexers/__init__.pyi @@ -1,6 +1,6 @@ from _typeshed import StrOrBytesPath, StrPath from collections.abc import Iterator -from typing import Any, Tuple, +from typing import Any, Tuple from pygments.lexer import Lexer, LexerMeta diff --git a/stubs/bleach/bleach/sanitizer.pyi b/stubs/bleach/bleach/sanitizer.pyi index 06a752a59e69..c6b5d1be7ad7 100644 --- a/stubs/bleach/bleach/sanitizer.pyi +++ b/stubs/bleach/bleach/sanitizer.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable, Container, Iterable -from typing import Any, Dict, List, Pattern, +from typing import Any, Dict, List, Pattern from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter diff --git a/stubs/colorama/colorama/ansitowin32.pyi b/stubs/colorama/colorama/ansitowin32.pyi index 20c7edc49df6..606e0f0acf9a 100644 --- a/stubs/colorama/colorama/ansitowin32.pyi +++ b/stubs/colorama/colorama/ansitowin32.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import SupportsWrite -from typing import Any, Callable, Dict, Pattern, Sequence, TextIO, Tuple, +from typing import Any, Callable, Dict, Pattern, Sequence, TextIO, Tuple if sys.platform == "win32": from .winterm import WinTerm diff --git a/stubs/croniter/croniter.pyi b/stubs/croniter/croniter.pyi index 1c6520d8e180..68d0969f9123 100644 --- a/stubs/croniter/croniter.pyi +++ b/stubs/croniter/croniter.pyi @@ -1,5 +1,5 @@ import datetime -from typing import Any, Iterator, Text, Tuple, Type, TypeVar, +from typing import Any, Iterator, Text, Tuple, Type, TypeVar from typing_extensions import Literal _RetType = Type[float] | Type[datetime.datetime] diff --git a/stubs/docopt/docopt.pyi b/stubs/docopt/docopt.pyi index 44139cff44b5..d3774d4c558c 100644 --- a/stubs/docopt/docopt.pyi +++ b/stubs/docopt/docopt.pyi @@ -1,4 +1,4 @@ -from typing import Any, Iterable, +from typing import Any, Iterable __version__: str diff --git a/stubs/paramiko/paramiko/common.pyi b/stubs/paramiko/paramiko/common.pyi index 7dba37326b82..e5e6da5a99c4 100644 --- a/stubs/paramiko/paramiko/common.pyi +++ b/stubs/paramiko/paramiko/common.pyi @@ -1,5 +1,5 @@ import sys -from typing import Protocol, Text, +from typing import Protocol, Text MSG_DISCONNECT: int MSG_IGNORE: int diff --git a/stubs/pyOpenSSL/OpenSSL/crypto.pyi b/stubs/pyOpenSSL/OpenSSL/crypto.pyi index 293423393b17..adad55c91c68 100644 --- a/stubs/pyOpenSSL/OpenSSL/crypto.pyi +++ b/stubs/pyOpenSSL/OpenSSL/crypto.pyi @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Any, Callable, Iterable, Sequence, Text, Tuple, +from typing import Any, Callable, Iterable, Sequence, Text, Tuple from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPublicKey from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index dbdbd76143f7..0c77e07d388b 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -1,4 +1,4 @@ -from typing import Callable, Mapping, Sequence, Tuple, +from typing import Callable, Mapping, Sequence, Tuple from typing_extensions import Final paFloat32: Final[int] = ... diff --git a/stubs/pysftp/pysftp/__init__.pyi b/stubs/pysftp/pysftp/__init__.pyi index c11477bdbbee..16cab1a30ddf 100644 --- a/stubs/pysftp/pysftp/__init__.pyi +++ b/stubs/pysftp/pysftp/__init__.pyi @@ -1,6 +1,6 @@ from stat import S_IMODE as S_IMODE from types import TracebackType -from typing import IO, Any, Callable, ContextManager, Sequence, Text, Type, +from typing import IO, Any, Callable, ContextManager, Sequence, Text, Type from typing_extensions import Literal import paramiko diff --git a/stubs/python-dateutil/dateutil/parser/__init__.pyi b/stubs/python-dateutil/dateutil/parser/__init__.pyi index ae6d93b59410..a3c5282a3ebc 100644 --- a/stubs/python-dateutil/dateutil/parser/__init__.pyi +++ b/stubs/python-dateutil/dateutil/parser/__init__.pyi @@ -1,5 +1,5 @@ from datetime import datetime, tzinfo -from typing import IO, Any, Mapping, Text, +from typing import IO, Any, Mapping, Text from .isoparser import isoparse as isoparse, isoparser as isoparser diff --git a/stubs/python-dateutil/dateutil/parser/isoparser.pyi b/stubs/python-dateutil/dateutil/parser/isoparser.pyi index 636a5577759f..69d983ae71fb 100644 --- a/stubs/python-dateutil/dateutil/parser/isoparser.pyi +++ b/stubs/python-dateutil/dateutil/parser/isoparser.pyi @@ -1,6 +1,6 @@ from _typeshed import SupportsRead from datetime import date, datetime, time, tzinfo -from typing import Text, +from typing import Text _Readable = SupportsRead[Text | bytes] _TakesAscii = Text | bytes | _Readable diff --git a/stubs/python-dateutil/dateutil/tz/tz.pyi b/stubs/python-dateutil/dateutil/tz/tz.pyi index 53e0fa7e8fdd..296d4418e128 100644 --- a/stubs/python-dateutil/dateutil/tz/tz.pyi +++ b/stubs/python-dateutil/dateutil/tz/tz.pyi @@ -1,5 +1,5 @@ import datetime -from typing import IO, Any, Text, TypeVar, +from typing import IO, Any, Text, TypeVar from ..relativedelta import relativedelta from ._common import _tzinfo as _tzinfo, enfold as enfold, tzname_in_python2 as tzname_in_python2, tzrangebase as tzrangebase diff --git a/stubs/requests/requests/sessions.pyi b/stubs/requests/requests/sessions.pyi index a12cc60284bb..0c7a788b4e60 100644 --- a/stubs/requests/requests/sessions.pyi +++ b/stubs/requests/requests/sessions.pyi @@ -1,5 +1,5 @@ from _typeshed import SupportsItems -from typing import IO, Any, Callable, Iterable, List, Mapping, MutableMapping, Text, Tuple, TypeVar, +from typing import IO, Any, Callable, Iterable, List, Mapping, MutableMapping, Text, Tuple, TypeVar from . import adapters, auth as _auth, compat, cookies, exceptions, hooks, models, status_codes, structures, utils from .models import Response diff --git a/stubs/simplejson/simplejson/__init__.pyi b/stubs/simplejson/simplejson/__init__.pyi index 13ec9e3f2513..9e3401e78bb1 100644 --- a/stubs/simplejson/simplejson/__init__.pyi +++ b/stubs/simplejson/simplejson/__init__.pyi @@ -1,4 +1,4 @@ -from typing import IO, Any, Text, +from typing import IO, Any, Text from simplejson.decoder import JSONDecoder as JSONDecoder from simplejson.encoder import JSONEncoder as JSONEncoder, JSONEncoderForHTML as JSONEncoderForHTML diff --git a/stubs/tabulate/tabulate.pyi b/stubs/tabulate/tabulate.pyi index ae1b94b3f2c0..16dc3a28c80c 100644 --- a/stubs/tabulate/tabulate.pyi +++ b/stubs/tabulate/tabulate.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Container, Iterable, List, Mapping, NamedTuple, Sequence, +from typing import Any, Callable, Container, Iterable, List, Mapping, NamedTuple, Sequence LATEX_ESCAPE_RULES: dict[str, str] MIN_PADDING: int diff --git a/stubs/toml/toml.pyi b/stubs/toml/toml.pyi index 96786ac96c86..2bb7d57a07aa 100644 --- a/stubs/toml/toml.pyi +++ b/stubs/toml/toml.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import StrPath, SupportsWrite -from typing import IO, Any, Mapping, MutableMapping, Text, Type, +from typing import IO, Any, Mapping, MutableMapping, Text, Type if sys.version_info >= (3, 6): _PathLike = StrPath From a51e3da60c02b6175103a069732d3bb7909cd791 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Dec 2021 18:02:29 +0000 Subject: [PATCH 06/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_curses.pyi | 2 +- stdlib/_dummy_threading.pyi | 2 +- stdlib/_socket.pyi | 2 +- stdlib/_thread.pyi | 2 +- stdlib/aifc.pyi | 2 +- stdlib/array.pyi | 2 +- stdlib/asyncio/base_events.pyi | 2 +- stdlib/asyncio/base_subprocess.pyi | 2 +- stdlib/asyncio/events.pyi | 2 +- stdlib/asyncio/format_helpers.pyi | 2 +- stdlib/asyncio/tasks.pyi | 2 +- stdlib/asyncio/trsock.pyi | 2 +- stdlib/builtins.pyi | 1 - stdlib/calendar.pyi | 2 +- stdlib/cgitb.pyi | 2 +- stdlib/configparser.pyi | 2 +- stdlib/contextlib.pyi | 15 +-------------- stdlib/copyreg.pyi | 2 +- stdlib/ctypes/__init__.pyi | 1 - stdlib/dbm/gnu.pyi | 2 +- stdlib/dbm/ndbm.pyi | 2 +- stdlib/decimal.pyi | 2 +- stdlib/difflib.pyi | 2 +- stdlib/distutils/ccompiler.pyi | 2 +- stdlib/distutils/fancy_getopt.pyi | 2 +- stdlib/email/message.pyi | 2 +- stdlib/email/mime/application.pyi | 2 +- stdlib/email/mime/audio.pyi | 2 +- stdlib/email/mime/base.pyi | 2 +- stdlib/email/mime/image.pyi | 2 +- stdlib/email/mime/multipart.pyi | 2 +- stdlib/email/utils.pyi | 2 +- stdlib/enum.pyi | 2 +- stdlib/fractions.pyi | 2 +- stdlib/hmac.pyi | 2 +- stdlib/http/client.pyi | 2 +- stdlib/http/cookies.pyi | 2 +- stdlib/importlib/abc.pyi | 2 +- stdlib/itertools.pyi | 1 - stdlib/lib2to3/pgen2/grammar.pyi | 2 +- stdlib/lib2to3/pytree.pyi | 2 +- stdlib/logging/__init__.pyi | 2 +- stdlib/lzma.pyi | 2 +- stdlib/mailbox.pyi | 17 +---------------- stdlib/math.pyi | 2 +- stdlib/msilib/sequence.pyi | 2 +- stdlib/multiprocessing/__init__.pyi | 2 +- stdlib/multiprocessing/context.pyi | 2 +- stdlib/netrc.pyi | 2 +- stdlib/os/__init__.pyi | 12 ++++++++++-- stdlib/pickle.pyi | 10 ++++++++-- stdlib/pstats.pyi | 2 +- stdlib/pydoc.pyi | 2 +- stdlib/pyexpat/__init__.pyi | 2 +- stdlib/re.pyi | 2 +- stdlib/readline.pyi | 2 +- stdlib/shutil.pyi | 2 +- stdlib/signal.pyi | 2 +- stdlib/smtplib.pyi | 2 +- stdlib/sre_parse.pyi | 2 +- stdlib/ssl.pyi | 2 +- stdlib/subprocess.pyi | 2 +- stdlib/sys.pyi | 16 +--------------- stdlib/tempfile.pyi | 2 +- stdlib/threading.pyi | 2 +- stdlib/tkinter/__init__.pyi | 14 +++++++------- stdlib/tkinter/font.pyi | 2 +- stdlib/tkinter/ttk.pyi | 2 +- stdlib/trace.pyi | 2 +- stdlib/traceback.pyi | 2 +- stdlib/tracemalloc.pyi | 2 +- stdlib/turtle.pyi | 2 +- stdlib/urllib/parse.pyi | 2 +- stdlib/wsgiref/handlers.pyi | 2 +- stdlib/xml/etree/ElementTree.pyi | 1 - stdlib/xmlrpc/client.pyi | 6 ++++-- stubs/Pillow/PIL/Image.pyi | 4 +++- stubs/Pillow/PIL/ImageDraw.pyi | 2 +- stubs/PyMySQL/pymysql/converters.pyi | 2 +- stubs/aiofiles/aiofiles/os.pyi | 2 +- stubs/aiofiles/aiofiles/threadpool/__init__.pyi | 2 +- stubs/beautifulsoup4/bs4/element.pyi | 2 +- stubs/colorama/colorama/ansitowin32.pyi | 2 +- stubs/freezegun/freezegun/api.pyi | 2 +- stubs/pyaudio/pyaudio.pyi | 2 +- stubs/redis/redis/client.pyi | 17 +---------------- stubs/redis/redis/commands/core.pyi | 2 +- stubs/requests/requests/sessions.pyi | 10 ++++++++-- stubs/setuptools/pkg_resources/__init__.pyi | 2 +- 89 files changed, 119 insertions(+), 156 deletions(-) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 00293874903e..64a316354acb 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,5 +1,5 @@ import sys -from typing import IO, Any, BinaryIO, NamedTuple, overload +from typing import IO, Any, BinaryIO, NamedTuple, overload _chtype = str | bytes | int diff --git a/stdlib/_dummy_threading.pyi b/stdlib/_dummy_threading.pyi index c41e86569f40..fdcfa1e5fb84 100644 --- a/stdlib/_dummy_threading.pyi +++ b/stdlib/_dummy_threading.pyi @@ -1,6 +1,6 @@ import sys from types import FrameType, TracebackType -from typing import Any, Callable, Iterable, Mapping, Type, TypeVar +from typing import Any, Callable, Iterable, Mapping, Type, TypeVar # TODO recursive type _TF = Callable[[FrameType, str, Any], Callable[..., Any] | None] diff --git a/stdlib/_socket.pyi b/stdlib/_socket.pyi index b18011797e0c..a5c1d18c12d8 100644 --- a/stdlib/_socket.pyi +++ b/stdlib/_socket.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import ReadableBuffer, WriteableBuffer from collections.abc import Iterable -from typing import Any, SupportsInt, Tuple, overload +from typing import Any, SupportsInt, Tuple, overload if sys.version_info >= (3, 8): from typing import SupportsIndex diff --git a/stdlib/_thread.pyi b/stdlib/_thread.pyi index 75459aa10c93..a9c24e9abb79 100644 --- a/stdlib/_thread.pyi +++ b/stdlib/_thread.pyi @@ -1,7 +1,7 @@ import sys from threading import Thread from types import TracebackType -from typing import Any, Callable, NoReturn, Tuple, Type +from typing import Any, Callable, NoReturn, Tuple, Type from typing_extensions import final error = RuntimeError diff --git a/stdlib/aifc.pyi b/stdlib/aifc.pyi index 1d5db932b181..fd3ea65cb720 100644 --- a/stdlib/aifc.pyi +++ b/stdlib/aifc.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Self from types import TracebackType -from typing import IO, Any, NamedTuple, Tuple, Type, overload +from typing import IO, Any, NamedTuple, Tuple, Type, overload from typing_extensions import Literal class Error(Exception): ... diff --git a/stdlib/array.pyi b/stdlib/array.pyi index 001be0bbd617..12c2070fb4bc 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, TypeVar, overload +from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, TypeVar, overload from typing_extensions import Literal, SupportsIndex _IntTypeCode = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 382e07d4b67e..8c4479c75783 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -9,7 +9,7 @@ from asyncio.tasks import Task from asyncio.transports import BaseTransport from collections.abc import Iterable from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket -from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, overload +from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, overload from typing_extensions import Literal if sys.version_info >= (3, 7): diff --git a/stdlib/asyncio/base_subprocess.pyi b/stdlib/asyncio/base_subprocess.pyi index 6501a3eef86b..fe9f096bb54c 100644 --- a/stdlib/asyncio/base_subprocess.pyi +++ b/stdlib/asyncio/base_subprocess.pyi @@ -1,6 +1,6 @@ import subprocess from collections import deque -from typing import IO, Any, Callable, Sequence, Tuple +from typing import IO, Any, Callable, Sequence, Tuple from . import events, futures, protocols, transports diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 41b2fe89cd2c..8d94381932b2 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -3,7 +3,7 @@ import sys 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, Dict, Generator, Sequence, Tuple, TypeVar, overload +from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, overload from typing_extensions import Literal from .base_events import Server diff --git a/stdlib/asyncio/format_helpers.pyi b/stdlib/asyncio/format_helpers.pyi index fd04ce7897d5..ae197000cc50 100644 --- a/stdlib/asyncio/format_helpers.pyi +++ b/stdlib/asyncio/format_helpers.pyi @@ -2,7 +2,7 @@ import functools import sys import traceback from types import FrameType, FunctionType -from typing import Any, Iterable, overload +from typing import Any, Iterable, overload class _HasWrapper: __wrapper__: _HasWrapper | FunctionType diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index c8935fc49b3f..e1c0c71aa923 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -2,7 +2,7 @@ import concurrent.futures import sys from collections.abc import Awaitable, Generator, Iterable, Iterator from types import FrameType -from typing import Any, Generic, TextIO, TypeVar, overload +from typing import Any, Generic, TextIO, TypeVar, overload from typing_extensions import Literal from .events import AbstractEventLoop diff --git a/stdlib/asyncio/trsock.pyi b/stdlib/asyncio/trsock.pyi index 12253950d4f5..1514f01afca0 100644 --- a/stdlib/asyncio/trsock.pyi +++ b/stdlib/asyncio/trsock.pyi @@ -1,7 +1,7 @@ import socket import sys from types import TracebackType -from typing import Any, BinaryIO, Iterable, NoReturn, Tuple, Type, overload +from typing import Any, BinaryIO, Iterable, NoReturn, Tuple, Type, overload if sys.version_info >= (3, 8): # These are based in socket, maybe move them out into _typeshed.pyi or such diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 82af307bfb98..77e1d82e73f0 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -54,7 +54,6 @@ from typing import ( Tuple, Type, TypeVar, - overload, ) from typing_extensions import Literal, SupportsIndex, TypeGuard, final diff --git a/stdlib/calendar.pyi b/stdlib/calendar.pyi index e9945141f97f..af38401609d3 100644 --- a/stdlib/calendar.pyi +++ b/stdlib/calendar.pyi @@ -1,7 +1,7 @@ import datetime import sys from time import struct_time -from typing import Any, Iterable, Sequence, Tuple +from typing import Any, Iterable, Sequence, Tuple _LocaleType = Tuple[str | None, str | None] diff --git a/stdlib/cgitb.pyi b/stdlib/cgitb.pyi index f773867d679c..4800bb4a87fc 100644 --- a/stdlib/cgitb.pyi +++ b/stdlib/cgitb.pyi @@ -1,6 +1,6 @@ from _typeshed import StrOrBytesPath from types import FrameType, TracebackType -from typing import IO, Any, Callable, Tuple, Type +from typing import IO, Any, Callable, Tuple, Type _ExcInfo = Tuple[Type[BaseException] | None, BaseException | None, TracebackType | None] diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index df7a4438bda1..2aa696183827 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -1,7 +1,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, Dict, Pattern, Type, TypeVar, overload +from typing import Any, ClassVar, Dict, Pattern, Type, TypeVar, overload from typing_extensions import Literal # Internal type aliases diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 8d2495e27ab4..9c8fd8737b07 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -1,20 +1,7 @@ import sys from _typeshed import Self, StrOrBytesPath from types import TracebackType -from typing import ( - IO, - Any, - AsyncIterator, - Awaitable, - Callable, - ContextManager, - Generic, - Iterator, - - Type, - TypeVar, - overload, -) +from typing import IO, Any, AsyncIterator, Awaitable, Callable, ContextManager, Generic, Iterator, Type, TypeVar, overload from typing_extensions import ParamSpec, Protocol AbstractContextManager = ContextManager diff --git a/stdlib/copyreg.pyi b/stdlib/copyreg.pyi index 8700ccf6265a..e23ae406ca9e 100644 --- a/stdlib/copyreg.pyi +++ b/stdlib/copyreg.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Hashable, SupportsInt, Tuple, TypeVar +from typing import Any, Callable, Hashable, SupportsInt, Tuple, TypeVar _TypeT = TypeVar("_TypeT", bound=type) _Reduce = Tuple[Callable[..., _TypeT], Tuple[Any, ...]] | Tuple[Callable[..., _TypeT], Tuple[Any, ...], Any | None] diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 2cf28297d9a8..023f4f947fa6 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -9,7 +9,6 @@ from typing import ( Iterable, Iterator, Mapping, - Sequence, Tuple, Type, diff --git a/stdlib/dbm/gnu.pyi b/stdlib/dbm/gnu.pyi index 167f7aedee1a..a971c900e072 100644 --- a/stdlib/dbm/gnu.pyi +++ b/stdlib/dbm/gnu.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Type, TypeVar, overload +from typing import Type, TypeVar, overload _T = TypeVar("_T") _KeyType = str | bytes diff --git a/stdlib/dbm/ndbm.pyi b/stdlib/dbm/ndbm.pyi index 3690db77ca09..d9bf5699db00 100644 --- a/stdlib/dbm/ndbm.pyi +++ b/stdlib/dbm/ndbm.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from types import TracebackType -from typing import Type, TypeVar, overload +from typing import Type, TypeVar, overload _T = TypeVar("_T") _KeyType = str | bytes diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index 2ee4c67437ce..24ef49190075 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -1,6 +1,6 @@ import numbers from types import TracebackType -from typing import Any, Container, NamedTuple, Sequence, Tuple, Type, TypeVar, overload +from typing import Any, Container, NamedTuple, Sequence, Tuple, Type, TypeVar, overload _Decimal = Decimal | int _DecimalNew = Decimal | float | str | Tuple[int, Sequence[int], int] diff --git a/stdlib/difflib.pyi b/stdlib/difflib.pyi index 41ec0865dab1..502f78921928 100644 --- a/stdlib/difflib.pyi +++ b/stdlib/difflib.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, AnyStr, Callable, Generic, Iterable, Iterator, NamedTuple, Sequence, TypeVar, overload +from typing import Any, AnyStr, Callable, Generic, Iterable, Iterator, NamedTuple, Sequence, TypeVar, overload if sys.version_info >= (3, 9): from types import GenericAlias diff --git a/stdlib/distutils/ccompiler.pyi b/stdlib/distutils/ccompiler.pyi index f20f1b344e96..13cb423cbbea 100644 --- a/stdlib/distutils/ccompiler.pyi +++ b/stdlib/distutils/ccompiler.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Tuple +from typing import Any, Callable, Tuple _Macro = Tuple[str] | Tuple[str, str | None] diff --git a/stdlib/distutils/fancy_getopt.pyi b/stdlib/distutils/fancy_getopt.pyi index 081f377b693a..4ede4a8a175e 100644 --- a/stdlib/distutils/fancy_getopt.pyi +++ b/stdlib/distutils/fancy_getopt.pyi @@ -1,4 +1,4 @@ -from typing import Any, Iterable, List, Mapping, Tuple, overload +from typing import Any, Iterable, List, Mapping, Tuple, overload _Option = Tuple[str, str | None, str] _GR = Tuple[List[str], OptionDummy] diff --git a/stdlib/email/message.pyi b/stdlib/email/message.pyi index 9724b1c0aca3..61c67d20d2ab 100644 --- a/stdlib/email/message.pyi +++ b/stdlib/email/message.pyi @@ -2,7 +2,7 @@ from email.charset import Charset from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy -from typing import Any, Generator, Iterator, List, Sequence, Tuple, TypeVar +from typing import Any, Generator, Iterator, List, Sequence, Tuple, TypeVar _T = TypeVar("_T") diff --git a/stdlib/email/mime/application.pyi b/stdlib/email/mime/application.pyi index 4aaf41dc5ff8..266a639aef45 100644 --- a/stdlib/email/mime/application.pyi +++ b/stdlib/email/mime/application.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple +from typing import Callable, Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/audio.pyi b/stdlib/email/mime/audio.pyi index 24cefbf797cf..357306e5a3b2 100644 --- a/stdlib/email/mime/audio.pyi +++ b/stdlib/email/mime/audio.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple +from typing import Callable, Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/base.pyi b/stdlib/email/mime/base.pyi index a334fa4869c4..d2116bcb989b 100644 --- a/stdlib/email/mime/base.pyi +++ b/stdlib/email/mime/base.pyi @@ -1,6 +1,6 @@ import email.message from email.policy import Policy -from typing import Tuple +from typing import Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/image.pyi b/stdlib/email/mime/image.pyi index 4c8ec4f24494..79fb83e5ac17 100644 --- a/stdlib/email/mime/image.pyi +++ b/stdlib/email/mime/image.pyi @@ -1,6 +1,6 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple +from typing import Callable, Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/mime/multipart.pyi b/stdlib/email/mime/multipart.pyi index 75796dfc4305..e80375252557 100644 --- a/stdlib/email/mime/multipart.pyi +++ b/stdlib/email/mime/multipart.pyi @@ -1,7 +1,7 @@ from email.message import Message from email.mime.base import MIMEBase from email.policy import Policy -from typing import Sequence, Tuple +from typing import Sequence, Tuple _ParamsType = str | None | Tuple[str, str | None, str] diff --git a/stdlib/email/utils.pyi b/stdlib/email/utils.pyi index 6239718b5548..6045169fc01b 100644 --- a/stdlib/email/utils.pyi +++ b/stdlib/email/utils.pyi @@ -1,7 +1,7 @@ import datetime import sys from email.charset import Charset -from typing import Tuple, overload +from typing import Tuple, overload _ParamType = str | Tuple[str | None, str | None, str] _PDTZ = Tuple[int, int, int, int, int, int, int, int, int, int | None] diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 3beb99b86c56..b6dd951b6316 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -3,7 +3,7 @@ import types from abc import ABCMeta from builtins import property as _builtins_property from collections.abc import Iterable, Iterator, Mapping -from typing import Any, Dict, Tuple, Type, TypeVar, overload +from typing import Any, Dict, Tuple, Type, TypeVar, overload _T = TypeVar("_T") _S = TypeVar("_S", bound=Type[Enum]) diff --git a/stdlib/fractions.pyi b/stdlib/fractions.pyi index 42cad19b4f03..be7fa2274542 100644 --- a/stdlib/fractions.pyi +++ b/stdlib/fractions.pyi @@ -1,7 +1,7 @@ import sys from decimal import Decimal from numbers import Integral, Rational, Real -from typing import Type, TypeVar, overload +from typing import Type, TypeVar, overload from typing_extensions import Literal _ComparableNum = int | float | Decimal | Real diff --git a/stdlib/hmac.pyi b/stdlib/hmac.pyi index 93360e8aed7e..9ce029490223 100644 --- a/stdlib/hmac.pyi +++ b/stdlib/hmac.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import ReadableBuffer from types import ModuleType -from typing import Any, AnyStr, Callable, overload +from typing import Any, AnyStr, Callable, overload # TODO more precise type for object of hashlib _Hash = Any diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index 50ae39786e17..5f55277a5a7a 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -5,7 +5,7 @@ import sys import types from _typeshed import Self, WriteableBuffer from socket import socket -from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, Mapping, Protocol, Type, TypeVar, overload +from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, Mapping, Protocol, Type, TypeVar, overload _DataType = bytes | IO[Any] | Iterable[bytes] | str _T = TypeVar("_T") diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index e3490e7b8826..e872e338c1e6 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Dict, Generic, Iterable, Mapping, TypeVar, overload +from typing import Any, Dict, Generic, Iterable, Mapping, TypeVar, overload if sys.version_info >= (3, 9): from types import GenericAlias diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index 97af6718d122..8ac4ffea385e 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -12,7 +12,7 @@ from _typeshed import ( 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 +from typing import IO, Any, BinaryIO, Iterator, Mapping, NoReturn, Protocol, Sequence, overload from typing_extensions import Literal, runtime_checkable _Path = bytes | str diff --git a/stdlib/itertools.pyi b/stdlib/itertools.pyi index 55836af38a27..d9204bfc0a67 100644 --- a/stdlib/itertools.pyi +++ b/stdlib/itertools.pyi @@ -12,7 +12,6 @@ from typing import ( Tuple, Type, TypeVar, - overload, ) from typing_extensions import Literal, SupportsIndex diff --git a/stdlib/lib2to3/pgen2/grammar.pyi b/stdlib/lib2to3/pgen2/grammar.pyi index a9676bb5b15e..5fa48b3d935a 100644 --- a/stdlib/lib2to3/pgen2/grammar.pyi +++ b/stdlib/lib2to3/pgen2/grammar.pyi @@ -1,5 +1,5 @@ from _typeshed import StrPath -from typing import Dict, List, Tuple, TypeVar +from typing import Dict, List, Tuple, TypeVar _P = TypeVar("_P") _Label = Tuple[int, str | None] diff --git a/stdlib/lib2to3/pytree.pyi b/stdlib/lib2to3/pytree.pyi index 8f9a246f8f64..aa0fc71395d1 100644 --- a/stdlib/lib2to3/pytree.pyi +++ b/stdlib/lib2to3/pytree.pyi @@ -1,5 +1,5 @@ from lib2to3.pgen2.grammar import Grammar -from typing import Any, Callable, Dict, Iterator, List, Tuple, TypeVar +from typing import Any, Callable, Dict, Iterator, List, Tuple, TypeVar _P = TypeVar("_P") _NL = Node | Leaf diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 7758c8db0fd2..90d2894ce91b 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -6,7 +6,7 @@ from io import TextIOWrapper from string import Template from time import struct_time from types import FrameType, TracebackType -from typing import Any, ClassVar, Generic, Pattern, TextIO, Tuple, Type, TypeVar, overload +from typing import Any, ClassVar, Generic, Pattern, TextIO, Tuple, Type, TypeVar, overload from typing_extensions import Literal _SysExcInfoType = Tuple[Type[BaseException], BaseException, TracebackType | None] | Tuple[None, None, None] diff --git a/stdlib/lzma.pyi b/stdlib/lzma.pyi index 5f0318d8e865..bee09c86ca58 100644 --- a/stdlib/lzma.pyi +++ b/stdlib/lzma.pyi @@ -1,6 +1,6 @@ import io from _typeshed import ReadableBuffer, Self, StrOrBytesPath -from typing import IO, Any, Mapping, Sequence, TextIO, overload +from typing import IO, Any, Mapping, Sequence, TextIO, overload from typing_extensions import Literal, final _OpenBinaryWritingMode = Literal["w", "wb", "x", "xb", "a", "ab"] diff --git a/stdlib/mailbox.pyi b/stdlib/mailbox.pyi index c9350357c2fa..ba5977ac079c 100644 --- a/stdlib/mailbox.pyi +++ b/stdlib/mailbox.pyi @@ -2,22 +2,7 @@ import email.message import sys from _typeshed import Self, StrOrBytesPath from types import TracebackType -from typing import ( - IO, - Any, - AnyStr, - Callable, - Generic, - Iterable, - Iterator, - Mapping, - Protocol, - Sequence, - Type, - TypeVar, - - overload, -) +from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Mapping, Protocol, Sequence, Type, TypeVar, overload from typing_extensions import Literal if sys.version_info >= (3, 9): diff --git a/stdlib/math.pyi b/stdlib/math.pyi index 9b0b15055c72..bc679339e876 100644 --- a/stdlib/math.pyi +++ b/stdlib/math.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import SupportsTrunc -from typing import Iterable, SupportsFloat, overload +from typing import Iterable, SupportsFloat, overload from typing_extensions import SupportsIndex if sys.version_info >= (3, 8): diff --git a/stdlib/msilib/sequence.pyi b/stdlib/msilib/sequence.pyi index 2f807325dbce..f9622bb73a78 100644 --- a/stdlib/msilib/sequence.pyi +++ b/stdlib/msilib/sequence.pyi @@ -1,5 +1,5 @@ import sys -from typing import List, Tuple +from typing import List, Tuple if sys.platform == "win32": diff --git a/stdlib/multiprocessing/__init__.pyi b/stdlib/multiprocessing/__init__.pyi index b7aff1601887..d66e2a4c3a09 100644 --- a/stdlib/multiprocessing/__init__.pyi +++ b/stdlib/multiprocessing/__init__.pyi @@ -20,7 +20,7 @@ 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 import Any, overload from typing_extensions import Literal if sys.version_info >= (3, 8): diff --git a/stdlib/multiprocessing/context.pyi b/stdlib/multiprocessing/context.pyi index 2e77c2b81abf..29ca25c4bc04 100644 --- a/stdlib/multiprocessing/context.pyi +++ b/stdlib/multiprocessing/context.pyi @@ -8,7 +8,7 @@ from multiprocessing import queues, synchronize from multiprocessing.pool import Pool as _Pool from multiprocessing.process import BaseProcess from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase -from typing import Any, Type, TypeVar, overload +from typing import Any, Type, TypeVar, overload from typing_extensions import Literal _LockLike = synchronize.Lock | synchronize.RLock diff --git a/stdlib/netrc.pyi b/stdlib/netrc.pyi index 139b151ccb6a..5b0c68d52622 100644 --- a/stdlib/netrc.pyi +++ b/stdlib/netrc.pyi @@ -1,5 +1,5 @@ from _typeshed import StrOrBytesPath -from typing import Tuple +from typing import Tuple class NetrcParseError(Exception): filename: str | None diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index cee8edd11b83..238d02a429d9 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -32,7 +32,6 @@ from typing import ( Sequence, Tuple, TypeVar, - overload, runtime_checkable, ) @@ -773,7 +772,16 @@ 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 = Tuple[StrOrBytesPath, ...]| List[bytes]| List[str]| List[PathLike[Any]]| List[bytes | str]| List[bytes | PathLike[Any]]| List[str | PathLike[Any]]| List[bytes | str | PathLike[Any]] +_ExecVArgs = ( + Tuple[StrOrBytesPath, ...] + | List[bytes] + | List[str] + | List[PathLike[Any]] + | List[bytes | str] + | List[bytes | PathLike[Any]] + | List[str | PathLike[Any]] + | List[bytes | str | PathLike[Any]] +) _ExecEnv = Mapping[bytes, bytes | str] | Mapping[str, bytes | str] def execv(__path: StrOrBytesPath, __argv: _ExecVArgs) -> NoReturn: ... diff --git a/stdlib/pickle.pyi b/stdlib/pickle.pyi index c3859f681881..bcc1a8d8e16d 100644 --- a/stdlib/pickle.pyi +++ b/stdlib/pickle.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Protocol, Tuple, Type +from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Protocol, Tuple, Type from typing_extensions import final HIGHEST_PROTOCOL: int @@ -56,7 +56,13 @@ class PickleError(Exception): ... class PicklingError(PickleError): ... class UnpicklingError(PickleError): ... -_reducedtype = str | Tuple[Callable[..., Any], Tuple[Any, ...]] | Tuple[Callable[..., Any], Tuple[Any, ...], Any] | Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None]| Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None] +_reducedtype = ( + str + | Tuple[Callable[..., Any], Tuple[Any, ...]] + | Tuple[Callable[..., Any], Tuple[Any, ...], Any] + | Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None] + | Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None] +) class Pickler: fast: bool diff --git a/stdlib/pstats.pyi b/stdlib/pstats.pyi index c8308901ad5c..51e89c320146 100644 --- a/stdlib/pstats.pyi +++ b/stdlib/pstats.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import StrOrBytesPath from cProfile import Profile as _cProfile from profile import Profile -from typing import IO, Any, Iterable, Tuple, TypeVar, overload +from typing import IO, Any, Iterable, Tuple, TypeVar, overload _Selector = str | float | int _T = TypeVar("_T", bound=Stats) diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index 9c6b94ba1791..835f3872e6f6 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -1,7 +1,7 @@ from _typeshed import SupportsWrite from reprlib import Repr from types import MethodType, ModuleType, TracebackType -from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, Tuple, Type +from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, Tuple, Type # the return type of sys.exc_info(), used by ErrorDuringImport.__init__ _Exc_Info = Tuple[Type[BaseException] | None, BaseException | None, TracebackType | None] diff --git a/stdlib/pyexpat/__init__.pyi b/stdlib/pyexpat/__init__.pyi index e80c9ea2b4ea..26cc3374fb2e 100644 --- a/stdlib/pyexpat/__init__.pyi +++ b/stdlib/pyexpat/__init__.pyi @@ -1,7 +1,7 @@ import pyexpat.errors as errors import pyexpat.model as model from _typeshed import SupportsRead -from typing import Any, Callable, Tuple +from typing import Any, Callable, Tuple from typing_extensions import final EXPAT_VERSION: str # undocumented diff --git a/stdlib/re.pyi b/stdlib/re.pyi index e3a053e6d0ca..30105797d8c3 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -1,7 +1,7 @@ import enum import sys from sre_constants import error as error -from typing import Any, AnyStr, Callable, Iterator, overload +from typing import Any, AnyStr, Callable, Iterator, overload # ----- re variables and constants ----- if sys.version_info >= (3, 7): diff --git a/stdlib/readline.pyi b/stdlib/readline.pyi index 4844e30d6474..718ec6981283 100644 --- a/stdlib/readline.pyi +++ b/stdlib/readline.pyi @@ -1,5 +1,5 @@ from _typeshed import StrOrBytesPath -from typing import Callable, Sequence +from typing import Callable, Sequence _CompleterT = Callable[[str, int], str | None] | None _CompDispT = Callable[[str, Sequence[str], int], None] | None diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index 25aba616c3b8..4c2517c2ab7f 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -1,7 +1,7 @@ import os import sys from _typeshed import StrOrBytesPath, StrPath, SupportsRead, SupportsWrite -from typing import Any, AnyStr, Callable, Iterable, NamedTuple, Sequence, TypeVar, overload +from typing import Any, AnyStr, Callable, Iterable, NamedTuple, Sequence, TypeVar, overload _PathT = TypeVar("_PathT", str, os.PathLike[str]) # Return value of some functions that may either return a path-like object that was passed in or diff --git a/stdlib/signal.pyi b/stdlib/signal.pyi index e033ee6a911e..88deb08993bd 100644 --- a/stdlib/signal.pyi +++ b/stdlib/signal.pyi @@ -1,7 +1,7 @@ import sys from enum import IntEnum from types import FrameType -from typing import Any, Callable, Iterable, Tuple +from typing import Any, Callable, Iterable, Tuple NSIG: int diff --git a/stdlib/smtplib.pyi b/stdlib/smtplib.pyi index 082673c75060..31e769982f0f 100644 --- a/stdlib/smtplib.pyi +++ b/stdlib/smtplib.pyi @@ -4,7 +4,7 @@ from email.message import Message as _Message from socket import socket from ssl import SSLContext from types import TracebackType -from typing import Any, Dict, Pattern, Protocol, Sequence, Tuple, Type, overload +from typing import Any, Dict, Pattern, Protocol, Sequence, Tuple, Type, overload _Reply = Tuple[int, bytes] _SendErrs = Dict[str, _Reply] diff --git a/stdlib/sre_parse.pyi b/stdlib/sre_parse.pyi index 0871e440e9f8..e788980e4512 100644 --- a/stdlib/sre_parse.pyi +++ b/stdlib/sre_parse.pyi @@ -1,6 +1,6 @@ import sys from sre_constants import _NamedIntConstant as _NIC, error as _Error -from typing import Any, Iterable, List, Match, Pattern as _Pattern, Tuple, overload +from typing import Any, Iterable, List, Match, Pattern as _Pattern, Tuple, overload SPECIAL_CHARS: str REPEAT_CHARS: str diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index cbb62d95a0b2..9277ecfacf4a 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -2,7 +2,7 @@ import enum import socket import sys from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer -from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Set, Tuple, Type, overload +from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Set, Tuple, Type, overload from typing_extensions import Literal, TypedDict _PCTRTT = Tuple[Tuple[str, str], ...] diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index f9f8bef7cfa1..93a1fa1382a0 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Self, StrOrBytesPath from types import TracebackType -from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, overload +from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, overload from typing_extensions import Literal if sys.version_info >= (3, 9): diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index b290d3f94218..d060375467fe 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -4,21 +4,7 @@ from importlib.abc import PathEntryFinder from importlib.machinery import ModuleSpec from io import TextIOWrapper from types import FrameType, ModuleType, TracebackType -from typing import ( - Any, - AsyncGenerator, - Callable, - NoReturn, - - Protocol, - Sequence, - TextIO, - Tuple, - Type, - TypeVar, - - overload, -) +from typing import Any, AsyncGenerator, Callable, NoReturn, Protocol, Sequence, TextIO, Tuple, Type, TypeVar, overload from typing_extensions import Literal _T = TypeVar("_T") diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index 2f8045f3200d..596b1f073ee6 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -2,7 +2,7 @@ import os import sys from _typeshed import Self from types import TracebackType -from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, overload +from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, overload from typing_extensions import Literal if sys.version_info >= (3, 9): diff --git a/stdlib/threading.pyi b/stdlib/threading.pyi index 5c22c8b18b2c..63f33e0518cb 100644 --- a/stdlib/threading.pyi +++ b/stdlib/threading.pyi @@ -1,6 +1,6 @@ import sys from types import FrameType, TracebackType -from typing import Any, Callable, Iterable, Mapping, Type, TypeVar +from typing import Any, Callable, Iterable, Mapping, Type, TypeVar # TODO recursive type _TF = Callable[[FrameType, str, Any], Callable[..., Any] | None] diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 7685f47ab2ea..4ca5ebf274aa 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -5,7 +5,7 @@ from enum import Enum from tkinter.constants import * # comment this out to find undefined identifier names with flake8 from tkinter.font import _FontDescription from types import TracebackType -from typing import Any, Callable, Generic, List, Mapping, Protocol, Sequence, Tuple, Type, TypeVar, overload +from typing import Any, Callable, Generic, List, Mapping, Protocol, Sequence, Tuple, Type, TypeVar, overload from typing_extensions import Literal, TypedDict # Using anything from tkinter.font in this file means that 'import tkinter' @@ -92,15 +92,15 @@ _Color = str # typically '#rrggbb', '#rgb' or color names. _Compound = Literal["top", "left", "center", "right", "bottom", "none"] # -compound in manual page named 'options' _Cursor = str | Tuple[str] | Tuple[str, str] | Tuple[str, str, str] | Tuple[str, str, str, str] # manual page: Tk_GetCursor # Example: entry['invalidcommand'] = [entry.register(print), '%P'] -_EntryValidateCommand = Callable[[], bool]| str| List[str]| Tuple[str, ...] -_GridIndex = int | str| Literal["all"] +_EntryValidateCommand = Callable[[], bool] | str | List[str] | Tuple[str, ...] +_GridIndex = int | str | Literal["all"] _ImageSpec = _Image | str # str can be from e.g. tkinter.image_names() _Padding = ( _ScreenUnits - |Tuple[_ScreenUnits] - |Tuple[_ScreenUnits, _ScreenUnits] - |Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits] - |Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _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 # manual page: Tk_GetPixels diff --git a/stdlib/tkinter/font.pyi b/stdlib/tkinter/font.pyi index eaf05001cd9a..a313b05b97e6 100644 --- a/stdlib/tkinter/font.pyi +++ b/stdlib/tkinter/font.pyi @@ -1,7 +1,7 @@ import _tkinter import sys import tkinter -from typing import Any, List, Tuple, overload +from typing import Any, List, Tuple, overload from typing_extensions import Literal, TypedDict NORMAL: Literal["normal"] diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 26c28a9c587a..a03fe5c20e1e 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -2,7 +2,7 @@ import _tkinter import sys import tkinter from tkinter.font import _FontDescription -from typing import Any, Callable, Tuple, overload +from typing import Any, Callable, Tuple, overload from typing_extensions import Literal, TypedDict def tclobjs_to_py(adict): ... diff --git a/stdlib/trace.pyi b/stdlib/trace.pyi index 9489b547bdbd..34ba0eccbbaa 100644 --- a/stdlib/trace.pyi +++ b/stdlib/trace.pyi @@ -1,7 +1,7 @@ import sys import types from _typeshed import StrPath -from typing import Any, Callable, Mapping, Sequence, Tuple, TypeVar +from typing import Any, Callable, Mapping, Sequence, Tuple, TypeVar from typing_extensions import ParamSpec _T = TypeVar("_T") diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index 4cc0611135fd..c70103eb88b1 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import SupportsWrite from types import FrameType, TracebackType -from typing import IO, Any, Generator, Iterable, Iterator, List, Mapping, Tuple, Type, overload +from typing import IO, Any, Generator, Iterable, Iterator, List, Mapping, Tuple, Type, overload _PT = Tuple[str, int, str, str | None] diff --git a/stdlib/tracemalloc.pyi b/stdlib/tracemalloc.pyi index d7242619d8a0..ddee4d002799 100644 --- a/stdlib/tracemalloc.pyi +++ b/stdlib/tracemalloc.pyi @@ -1,6 +1,6 @@ import sys from _tracemalloc import * -from typing import Sequence, Tuple, overload +from typing import Sequence, Tuple, overload from typing_extensions import SupportsIndex def get_object_traceback(obj: object) -> Traceback | None: ... diff --git a/stdlib/turtle.pyi b/stdlib/turtle.pyi index e67d587e6b57..b8919882c44d 100644 --- a/stdlib/turtle.pyi +++ b/stdlib/turtle.pyi @@ -1,5 +1,5 @@ from tkinter import Canvas, Frame, PhotoImage -from typing import Any, Callable, ClassVar, Dict, Sequence, Tuple, TypeVar, overload +from typing import Any, Callable, ClassVar, Dict, Sequence, Tuple, TypeVar, overload # Note: '_Color' is the alias we use for arguments and _AnyColor is the # alias we use for return types. Really, these two aliases should be the diff --git a/stdlib/urllib/parse.pyi b/stdlib/urllib/parse.pyi index 19baf136c3cc..43bd991eb8eb 100644 --- a/stdlib/urllib/parse.pyi +++ b/stdlib/urllib/parse.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, AnyStr, Callable, Generic, Mapping, NamedTuple, Sequence, Tuple, overload +from typing import Any, AnyStr, Callable, Generic, Mapping, NamedTuple, Sequence, Tuple, overload if sys.version_info >= (3, 9): from types import GenericAlias diff --git a/stdlib/wsgiref/handlers.pyi b/stdlib/wsgiref/handlers.pyi index 4b1e3e20d032..3e79b7b682b9 100644 --- a/stdlib/wsgiref/handlers.pyi +++ b/stdlib/wsgiref/handlers.pyi @@ -1,6 +1,6 @@ from abc import abstractmethod from types import TracebackType -from typing import IO, Callable, MutableMapping, Tuple, Type +from typing import IO, Callable, MutableMapping, Tuple, Type from .headers import Headers from .types import ErrorStream, InputStream, StartResponse, WSGIApplication, WSGIEnvironment diff --git a/stdlib/xml/etree/ElementTree.pyi b/stdlib/xml/etree/ElementTree.pyi index 8d753a0fa3fa..108654970e02 100644 --- a/stdlib/xml/etree/ElementTree.pyi +++ b/stdlib/xml/etree/ElementTree.pyi @@ -14,7 +14,6 @@ from typing import ( MutableSequence, Sequence, TypeVar, - overload, ) from typing_extensions import Literal, SupportsIndex diff --git a/stdlib/xmlrpc/client.pyi b/stdlib/xmlrpc/client.pyi index 601a7312002c..2ee08e4c4d9b 100644 --- a/stdlib/xmlrpc/client.pyi +++ b/stdlib/xmlrpc/client.pyi @@ -6,14 +6,16 @@ from _typeshed import Self, SupportsRead, SupportsWrite from datetime import datetime from io import BytesIO from types import TracebackType -from typing import Any, Callable, Dict, Iterable, List, Mapping, Protocol, Tuple, Type, overload +from typing import Any, Callable, Dict, Iterable, List, Mapping, Protocol, Tuple, Type, overload from typing_extensions import Literal class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... _DateTimeComparable = DateTime | datetime | str | _SupportsTimeTuple -_Marshallable = None | bool | int | float | str | bytes | Tuple[Any, ...] | List[Any] | Dict[Any, Any] | datetime | DateTime | Binary +_Marshallable = ( + None | bool | int | float | str | bytes | Tuple[Any, ...] | List[Any] | Dict[Any, Any] | datetime | DateTime | Binary +) _XMLDate = int | datetime | Tuple[int, ...] | time.struct_time _HostType = Tuple[str, Dict[str, str]] | str diff --git a/stubs/Pillow/PIL/Image.pyi b/stubs/Pillow/PIL/Image.pyi index ed750b4fba9b..b341034b77c9 100644 --- a/stubs/Pillow/PIL/Image.pyi +++ b/stubs/Pillow/PIL/Image.pyi @@ -19,7 +19,9 @@ _Resample = Literal[0, 1, 2, 3, 4, 5] _Size = Tuple[int, int] _Box = Tuple[int, int, int, int] -_ConversionMatrix = Tuple[float, float, float, float]| Tuple[float, float, float, float, float, float, float, float, float, float, float, float] +_ConversionMatrix = ( + Tuple[float, float, float, float] | Tuple[float, float, float, float, float, float, float, float, float, float, float, float] +) _Color = float | Tuple[float, ...] class _Writeable(SupportsWrite[bytes], Protocol): diff --git a/stubs/Pillow/PIL/ImageDraw.pyi b/stubs/Pillow/PIL/ImageDraw.pyi index 0fd02ec3c4ed..dc357db6a97a 100644 --- a/stubs/Pillow/PIL/ImageDraw.pyi +++ b/stubs/Pillow/PIL/ImageDraw.pyi @@ -1,5 +1,5 @@ from collections.abc import Container -from typing import Any, Sequence, Tuple, overload +from typing import Any, Sequence, Tuple, overload from typing_extensions import Literal from .Image import Image diff --git a/stubs/PyMySQL/pymysql/converters.pyi b/stubs/PyMySQL/pymysql/converters.pyi index 72f508bd874c..f440d8887320 100644 --- a/stubs/PyMySQL/pymysql/converters.pyi +++ b/stubs/PyMySQL/pymysql/converters.pyi @@ -2,7 +2,7 @@ import datetime import time from collections.abc import Callable, Mapping, Sequence from decimal import Decimal -from typing import Any, Type, TypeVar +from typing import Any, Type, TypeVar _EscaperMapping = Mapping[Type[object], Callable[..., str]] | None _T = TypeVar("_T") diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index 988fb721dc97..73bbaa1ab7fb 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import StrOrBytesPath from os import stat_result -from typing import Sequence, overload +from typing import Sequence, overload _FdOrAnyPath = int | StrOrBytesPath diff --git a/stubs/aiofiles/aiofiles/threadpool/__init__.pyi b/stubs/aiofiles/aiofiles/threadpool/__init__.pyi index d81c1a2585b0..47fc9a429275 100644 --- a/stubs/aiofiles/aiofiles/threadpool/__init__.pyi +++ b/stubs/aiofiles/aiofiles/threadpool/__init__.pyi @@ -7,7 +7,7 @@ from _typeshed import ( StrOrBytesPath, ) from asyncio import AbstractEventLoop -from typing import Any, Callable, overload +from typing import Any, Callable, overload from typing_extensions import Literal from ..base import AiofilesContextManager diff --git a/stubs/beautifulsoup4/bs4/element.pyi b/stubs/beautifulsoup4/bs4/element.pyi index 8ea1c6ee2bfe..eb7fe47bc5ea 100644 --- a/stubs/beautifulsoup4/bs4/element.pyi +++ b/stubs/beautifulsoup4/bs4/element.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from collections.abc import Iterator -from typing import Any, Callable, Generic, Iterable, List, Mapping, Pattern, Tuple, Type, TypeVar, overload +from typing import Any, Callable, Generic, Iterable, List, Mapping, Pattern, Tuple, Type, TypeVar, overload from . import BeautifulSoup from .builder import TreeBuilder diff --git a/stubs/colorama/colorama/ansitowin32.pyi b/stubs/colorama/colorama/ansitowin32.pyi index 606e0f0acf9a..17de1c1358d0 100644 --- a/stubs/colorama/colorama/ansitowin32.pyi +++ b/stubs/colorama/colorama/ansitowin32.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import SupportsWrite -from typing import Any, Callable, Dict, Pattern, Sequence, TextIO, Tuple +from typing import Any, Callable, Dict, Pattern, Sequence, TextIO, Tuple if sys.platform == "win32": from .winterm import WinTerm diff --git a/stubs/freezegun/freezegun/api.pyi b/stubs/freezegun/freezegun/api.pyi index d2524444be45..e1b8757fd004 100644 --- a/stubs/freezegun/freezegun/api.pyi +++ b/stubs/freezegun/freezegun/api.pyi @@ -1,7 +1,7 @@ from collections.abc import Awaitable, Callable, Iterator, Sequence from datetime import date, datetime, timedelta from numbers import Real -from typing import Any, Type, TypeVar, overload +from typing import Any, Type, TypeVar, overload _T = TypeVar("_T") _Freezable = str | datetime | date | timedelta diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 0c77e07d388b..188114f82cf2 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -1,4 +1,4 @@ -from typing import Callable, Mapping, Sequence, Tuple +from typing import Callable, Mapping, Sequence, Tuple from typing_extensions import Final paFloat32: Final[int] = ... diff --git a/stubs/redis/redis/client.pyi b/stubs/redis/redis/client.pyi index adcc9db9f3ec..bac369bcc92f 100644 --- a/stubs/redis/redis/client.pyi +++ b/stubs/redis/redis/client.pyi @@ -2,22 +2,7 @@ import builtins import threading from _typeshed import Self, SupportsItems from datetime import datetime, timedelta -from typing import ( - Any, - Callable, - ClassVar, - Dict, - Generic, - Iterable, - Iterator, - Mapping, - Pattern, - Sequence, - Type, - TypeVar, - - overload, -) +from typing import Any, Callable, ClassVar, Dict, Generic, Iterable, Iterator, Mapping, Pattern, Sequence, Type, TypeVar, overload from typing_extensions import Literal from .commands import CoreCommands, RedisModuleCommands, SentinelCommands diff --git a/stubs/redis/redis/commands/core.pyi b/stubs/redis/redis/commands/core.pyi index 7671560013f3..f6638262587d 100644 --- a/stubs/redis/redis/commands/core.pyi +++ b/stubs/redis/redis/commands/core.pyi @@ -1,6 +1,6 @@ from collections.abc import Callable, Iterable, Mapping, Sequence from datetime import timedelta -from typing import Any, Generic, TypeVar, overload +from typing import Any, Generic, TypeVar, overload from typing_extensions import Literal from ..client import _Key, _Value diff --git a/stubs/requests/requests/sessions.pyi b/stubs/requests/requests/sessions.pyi index 0c7a788b4e60..44375ee417d4 100644 --- a/stubs/requests/requests/sessions.pyi +++ b/stubs/requests/requests/sessions.pyi @@ -1,5 +1,5 @@ from _typeshed import SupportsItems -from typing import IO, Any, Callable, Iterable, List, Mapping, MutableMapping, Text, Tuple, TypeVar +from typing import IO, Any, Callable, Iterable, List, Mapping, MutableMapping, Text, Tuple, TypeVar from . import adapters, auth as _auth, compat, cookies, exceptions, hooks, models, status_codes, structures, utils from .models import Response @@ -51,7 +51,13 @@ _HooksInput = MutableMapping[Text, Iterable[_Hook] | _Hook] _ParamsMappingKeyType = Text | bytes | int | float _ParamsMappingValueType = Text | bytes | int | float | Iterable[Text | bytes | int | float] | None -_Params = SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType]| Tuple[_ParamsMappingKeyType, _ParamsMappingValueType]| Iterable[Tuple[_ParamsMappingKeyType, _ParamsMappingValueType]]| Text | bytes +_Params = ( + SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType] + | Tuple[_ParamsMappingKeyType, _ParamsMappingValueType] + | Iterable[Tuple[_ParamsMappingKeyType, _ParamsMappingValueType]] + | Text + | bytes +) _TextMapping = MutableMapping[Text, Text] _SessionT = TypeVar("_SessionT", bound=Session) diff --git a/stubs/setuptools/pkg_resources/__init__.pyi b/stubs/setuptools/pkg_resources/__init__.pyi index 3e12b7313996..9b89c5f7dfdd 100644 --- a/stubs/setuptools/pkg_resources/__init__.pyi +++ b/stubs/setuptools/pkg_resources/__init__.pyi @@ -2,7 +2,7 @@ import importlib.abc import types import zipimport from abc import ABCMeta -from typing import IO, Any, Callable, Generator, Iterable, Sequence, Tuple, TypeVar, overload +from typing import IO, Any, Callable, Generator, Iterable, Sequence, Tuple, TypeVar, overload LegacyVersion = Any # from packaging.version Version = Any # from packaging.version From d6ed9d32b78fa69606b5c2a486e54979f6ff12bb Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 16 Dec 2021 20:15:44 +0200 Subject: [PATCH 07/11] revert changes in a few files --- stdlib/logging/__init__.pyi | 4 ++-- stdlib/subprocess.pyi | 4 ++-- stdlib/tempfile.pyi | 4 ++-- stdlib/xmlrpc/client.pyi | 8 ++++---- stdlib/xmlrpc/server.pyi | 4 ++-- stubs/requests/requests/sessions.pyi | 4 ++-- stubs/tabulate/tabulate.pyi | 6 +++--- tests/check_new_syntax.py | 16 +++++++++++++--- 8 files changed, 30 insertions(+), 20 deletions(-) diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 90d2894ce91b..23cb9ecb5e2f 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -6,11 +6,11 @@ from io import TextIOWrapper from string import Template from time import struct_time from types import FrameType, TracebackType -from typing import Any, ClassVar, Generic, Pattern, TextIO, Tuple, Type, TypeVar, overload +from typing import Any, ClassVar, Generic, Pattern, TextIO, Tuple, Type, TypeVar, overload, Union from typing_extensions import Literal _SysExcInfoType = Tuple[Type[BaseException], BaseException, TracebackType | None] | Tuple[None, None, None] -_ExcInfoType = None | bool | _SysExcInfoType | BaseException +_ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException] _ArgsType = Tuple[object, ...] | Mapping[str, object] _FilterType = Filter | Callable[[LogRecord], int] _Level = int | str diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index 93a1fa1382a0..8c910e7c62a1 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Self, StrOrBytesPath from types import TracebackType -from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, overload +from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, overload, Union from typing_extensions import Literal if sys.version_info >= (3, 9): @@ -21,7 +21,7 @@ if sys.version_info >= (3, 9): # 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] +_FILE = Union[None, int, IO[Any]] _TXT = bytes | str if sys.version_info >= (3, 8): _CMD = StrOrBytesPath | Sequence[StrOrBytesPath] diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index 596b1f073ee6..10faec9943a0 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -2,7 +2,7 @@ import os import sys from _typeshed import Self from types import TracebackType -from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, overload +from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, overload, Union from typing_extensions import Literal if sys.version_info >= (3, 9): @@ -13,7 +13,7 @@ TMP_MAX: int tempdir: str | None template: str -_DirT = AnyStr | os.PathLike[AnyStr] +_DirT = Union[AnyStr, os.PathLike[AnyStr]] if sys.version_info >= (3, 8): @overload diff --git a/stdlib/xmlrpc/client.pyi b/stdlib/xmlrpc/client.pyi index 2ee08e4c4d9b..b8e824245326 100644 --- a/stdlib/xmlrpc/client.pyi +++ b/stdlib/xmlrpc/client.pyi @@ -6,16 +6,16 @@ from _typeshed import Self, SupportsRead, SupportsWrite from datetime import datetime from io import BytesIO from types import TracebackType -from typing import Any, Callable, Dict, Iterable, List, Mapping, Protocol, Tuple, Type, overload +from typing import Any, Callable, Dict, Iterable, List, Mapping, Protocol, Tuple, Type, overload, Union from typing_extensions import Literal class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... _DateTimeComparable = DateTime | datetime | str | _SupportsTimeTuple -_Marshallable = ( - None | bool | int | float | str | bytes | Tuple[Any, ...] | List[Any] | Dict[Any, Any] | datetime | DateTime | Binary -) +_Marshallable = Union[ + None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime, DateTime, Binary +] _XMLDate = int | datetime | Tuple[int, ...] | time.struct_time _HostType = Tuple[str, Dict[str, str]] | str diff --git a/stdlib/xmlrpc/server.pyi b/stdlib/xmlrpc/server.pyi index 9b16196d887f..a7a405b9e7f7 100644 --- a/stdlib/xmlrpc/server.pyi +++ b/stdlib/xmlrpc/server.pyi @@ -3,11 +3,11 @@ import pydoc import socketserver import sys from datetime import datetime -from typing import Any, Callable, Dict, Iterable, List, Mapping, Pattern, Protocol, Tuple, Type +from typing import Any, Callable, Dict, Iterable, List, Mapping, Pattern, Protocol, Tuple, Type, Union 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 = Union[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): diff --git a/stubs/requests/requests/sessions.pyi b/stubs/requests/requests/sessions.pyi index 44375ee417d4..73bca99c0e56 100644 --- a/stubs/requests/requests/sessions.pyi +++ b/stubs/requests/requests/sessions.pyi @@ -1,5 +1,5 @@ from _typeshed import SupportsItems -from typing import IO, Any, Callable, Iterable, List, Mapping, MutableMapping, Text, Tuple, TypeVar +from typing import IO, Any, Callable, Iterable, List, Mapping, MutableMapping, Text, Tuple, TypeVar, Union from . import adapters, auth as _auth, compat, cookies, exceptions, hooks, models, status_codes, structures, utils from .models import Response @@ -43,7 +43,7 @@ class SessionRedirectMixin: def rebuild_proxies(self, prepared_request, proxies): ... def should_strip_auth(self, old_url, new_url): ... -_Data = None | Text | bytes | Mapping[str, Any] | Mapping[Text, Any] | Iterable[Tuple[Text, Text | None]] | IO[Any] +_Data = Union[None, Text, bytes, Mapping[str, Any], Mapping[Text, Any], Iterable[Tuple[Text, Text | None]], IO[Any]] _Hook = Callable[[Response], Any] _Hooks = MutableMapping[Text, List[_Hook]] diff --git a/stubs/tabulate/tabulate.pyi b/stubs/tabulate/tabulate.pyi index 16dc3a28c80c..8b5efde5bf08 100644 --- a/stubs/tabulate/tabulate.pyi +++ b/stubs/tabulate/tabulate.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Container, Iterable, List, Mapping, NamedTuple, Sequence +from typing import Any, Callable, Container, Iterable, List, Mapping, NamedTuple, Sequence, Union LATEX_ESCAPE_RULES: dict[str, str] MIN_PADDING: int @@ -18,8 +18,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 = Union[None, Line, Callable[[List[int], List[str]], str]] +_TableFormatRow = Union[None, DataRow, Callable[[List[Any], List[int], List[str]], str]] class TableFormat(NamedTuple): lineabove: _TableFormatLine diff --git a/tests/check_new_syntax.py b/tests/check_new_syntax.py index 029747fdd521..cb11fdf16d91 100755 --- a/tests/check_new_syntax.py +++ b/tests/check_new_syntax.py @@ -142,12 +142,22 @@ def visit_If(self, node: ast.If) -> None: return errors +exclude_list = list(Path("stubs/protobuf/google/protobuf").rglob("*.pyi")) + [ + # TODO: figure out why new union syntax doesn't work + Path("stdlib/logging/__init__.pyi"), + Path("stdlib/subprocess.pyi"), + Path("stdlib/tempfile.pyi"), + Path("stdlib/xmlrpc/client.pyi"), + Path("stdlib/xmlrpc/server.pyi"), + Path("stubs/requests/requests/sessions.pyi"), + Path("stubs/tabulate/tabulate.pyi"), +] + + def main() -> None: errors = [] for path in chain(Path("stdlib").rglob("*.pyi"), Path("stubs").rglob("*.pyi")): - if "@python2" in path.parts: - continue - if Path("stubs/protobuf/google/protobuf") in path.parents: # TODO: fix protobuf stubs + if "@python2" in path.parts or path in exclude_list: continue with open(path) as f: From a7b0d67469346554e25764068b219d8c79b3b226 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Dec 2021 18:15:56 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/logging/__init__.pyi | 2 +- stdlib/subprocess.pyi | 2 +- stdlib/tempfile.pyi | 2 +- stdlib/xmlrpc/client.pyi | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 23cb9ecb5e2f..28c021274c8b 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -6,7 +6,7 @@ from io import TextIOWrapper from string import Template from time import struct_time from types import FrameType, TracebackType -from typing import Any, ClassVar, Generic, Pattern, TextIO, Tuple, Type, TypeVar, overload, Union +from typing import Any, ClassVar, Generic, Pattern, TextIO, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal _SysExcInfoType = Tuple[Type[BaseException], BaseException, TracebackType | None] | Tuple[None, None, None] diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index 8c910e7c62a1..6ca52d5eab18 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import Self, StrOrBytesPath from types import TracebackType -from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, overload, Union +from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Type, TypeVar, Union, overload from typing_extensions import Literal if sys.version_info >= (3, 9): diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index 10faec9943a0..119c111bc4e1 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -2,7 +2,7 @@ import os import sys from _typeshed import Self from types import TracebackType -from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, overload, Union +from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, Tuple, Type, Union, overload from typing_extensions import Literal if sys.version_info >= (3, 9): diff --git a/stdlib/xmlrpc/client.pyi b/stdlib/xmlrpc/client.pyi index b8e824245326..3fc47bed1a27 100644 --- a/stdlib/xmlrpc/client.pyi +++ b/stdlib/xmlrpc/client.pyi @@ -6,16 +6,14 @@ from _typeshed import Self, SupportsRead, SupportsWrite from datetime import datetime from io import BytesIO from types import TracebackType -from typing import Any, Callable, Dict, Iterable, List, Mapping, Protocol, Tuple, Type, overload, Union +from typing import Any, Callable, Dict, Iterable, List, Mapping, Protocol, Tuple, Type, Union, overload from typing_extensions import Literal class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... _DateTimeComparable = DateTime | datetime | str | _SupportsTimeTuple -_Marshallable = Union[ - None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime, DateTime, Binary -] +_Marshallable = Union[None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime, DateTime, Binary] _XMLDate = int | datetime | Tuple[int, ...] | time.struct_time _HostType = Tuple[str, Dict[str, str]] | str From dae33e53d218f17d8f684cf8b6957e122e7eb44d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Dec 2021 12:16:23 +0000 Subject: [PATCH 09/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/contextlib.pyi | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 46ede763384d..e6a444bdcfc7 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -1,7 +1,20 @@ import sys from _typeshed import Self, StrOrBytesPath from types import TracebackType -from typing import IO, Any, AsyncIterator, Awaitable, Callable, ContextManager, Generic, Iterator, Protocol, Type, TypeVar, overload +from typing import ( + IO, + Any, + AsyncIterator, + Awaitable, + Callable, + ContextManager, + Generic, + Iterator, + Protocol, + Type, + TypeVar, + overload, +) from typing_extensions import ParamSpec AbstractContextManager = ContextManager From 700b615a722e2d704b24909bb14b316662a09267 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 17 Dec 2021 16:42:17 +0200 Subject: [PATCH 10/11] Revert changes to many files --- stdlib/_typeshed/__init__.pyi | 22 ++++++++--------- stdlib/asyncio/tasks.pyi | 6 ++--- stdlib/builtins.pyi | 3 ++- stdlib/copyreg.pyi | 4 +-- stdlib/distutils/ccompiler.pyi | 4 +-- stdlib/email/message.pyi | 10 ++++---- stdlib/email/mime/application.pyi | 4 +-- stdlib/email/mime/audio.pyi | 4 +-- stdlib/email/mime/base.pyi | 4 +-- stdlib/email/mime/image.pyi | 4 +-- stdlib/email/mime/multipart.pyi | 4 +-- stdlib/email/utils.pyi | 6 ++--- stdlib/logging/__init__.pyi | 10 ++++---- stdlib/pickle.pyi | 18 +++++++------- stdlib/readline.pyi | 4 +-- stdlib/signal.pyi | 6 ++--- stdlib/ssl.pyi | 12 ++++----- stdlib/tkinter/__init__.pyi | 41 ++++++++++++++++--------------- stdlib/tracemalloc.pyi | 4 +-- stdlib/typing.pyi | 26 +++++++++++--------- tests/check_new_syntax.py | 19 ++++++++++++++ 21 files changed, 119 insertions(+), 96 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 8fbe512d75ca..b756a6213736 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -7,7 +7,7 @@ import ctypes import mmap import sys from os import PathLike -from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, TypeVar +from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, TypeVar, Union from typing_extensions import Literal, final _KT = TypeVar("_KT") @@ -51,9 +51,9 @@ class SupportsDunderGE(Protocol): class SupportsAllComparisons(SupportsDunderLT, SupportsDunderGT, SupportsDunderLE, SupportsDunderGE, Protocol): ... -SupportsRichComparison = SupportsDunderLT | SupportsDunderGT +SupportsRichComparison = Union[SupportsDunderLT, SupportsDunderGT] SupportsRichComparisonT = TypeVar("SupportsRichComparisonT", bound=SupportsRichComparison) # noqa: Y001 -SupportsAnyComparison = SupportsDunderLE | SupportsDunderGE | SupportsDunderGT | SupportsDunderLT +SupportsAnyComparison = Union[SupportsDunderLE, SupportsDunderGE, SupportsDunderGT, SupportsDunderLT] class SupportsDivMod(Protocol[_T_contra, _T_co]): def __divmod__(self, __other: _T_contra) -> _T_co: ... @@ -89,9 +89,9 @@ class SupportsItemAccess(SupportsGetItem[_KT_contra, _VT], Protocol[_KT_contra, def __delitem__(self, __v: _KT_contra) -> None: ... # These aliases are simple strings in Python 2. -StrPath = str | PathLike[str] # stable -BytesPath = bytes | PathLike[bytes] # stable -StrOrBytesPath = str | bytes | PathLike[str] | PathLike[bytes] # stable +StrPath = Union[str, PathLike[str]] # stable +BytesPath = Union[bytes, PathLike[bytes]] # stable +StrOrBytesPath = Union[str, bytes, PathLike[str], PathLike[bytes]] # stable OpenTextModeUpdating = Literal[ "r+", @@ -129,7 +129,7 @@ OpenTextModeUpdating = Literal[ ] OpenTextModeWriting = Literal["w", "wt", "tw", "a", "at", "ta", "x", "xt", "tx"] OpenTextModeReading = Literal["r", "rt", "tr", "U", "rU", "Ur", "rtU", "rUt", "Urt", "trU", "tUr", "Utr"] -OpenTextMode = OpenTextModeUpdating | OpenTextModeWriting | OpenTextModeReading +OpenTextMode = Union[OpenTextModeUpdating, OpenTextModeWriting, OpenTextModeReading] OpenBinaryModeUpdating = Literal[ "rb+", "r+b", @@ -158,14 +158,14 @@ OpenBinaryModeUpdating = Literal[ ] OpenBinaryModeWriting = Literal["wb", "bw", "ab", "ba", "xb", "bx"] OpenBinaryModeReading = Literal["rb", "br", "rbU", "rUb", "Urb", "brU", "bUr", "Ubr"] -OpenBinaryMode = OpenBinaryModeUpdating | OpenBinaryModeReading | OpenBinaryModeWriting +OpenBinaryMode = Union[OpenBinaryModeUpdating, OpenBinaryModeReading, OpenBinaryModeWriting] # stable class HasFileno(Protocol): def fileno(self) -> int: ... FileDescriptor = int # stable -FileDescriptorLike = int | HasFileno # stable +FileDescriptorLike = Union[int, HasFileno] # stable # stable class SupportsRead(Protocol[_T_co]): @@ -187,9 +187,9 @@ ReadOnlyBuffer = bytes # stable # Anything that implements the read-write buffer interface. # The buffer interface is defined purely on the C level, so we cannot define a normal Protocol # for it. Instead we have to list the most common stdlib buffer classes in a Union. -WriteableBuffer = bytearray | memoryview | array.array[Any] | mmap.mmap | ctypes._CData # stable +WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, ctypes._CData] # stable # Same as _WriteableBuffer, but also includes read-only buffer types (like bytes). -ReadableBuffer = ReadOnlyBuffer | WriteableBuffer # stable +ReadableBuffer = Union[ReadOnlyBuffer, WriteableBuffer] # stable # stable if sys.version_info >= (3, 10): diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index e1c0c71aa923..f12dcbcd79a8 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -2,7 +2,7 @@ import concurrent.futures import sys from collections.abc import Awaitable, Generator, Iterable, Iterator from types import FrameType -from typing import Any, Generic, TextIO, TypeVar, overload +from typing import Any, Generic, Optional, TextIO, TypeVar, Union, overload from typing_extensions import Literal from .events import AbstractEventLoop @@ -18,8 +18,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 = Union[Future[_T], Generator[Any, None, _T], Awaitable[_T]] +_TaskYieldType = Optional[Future[object]] FIRST_EXCEPTION: str FIRST_COMPLETED: str diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 77e1d82e73f0..a58f01f98140 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -54,6 +54,7 @@ from typing import ( Tuple, Type, TypeVar, + Union, overload, ) from typing_extensions import Literal, SupportsIndex, TypeGuard, final @@ -1172,7 +1173,7 @@ def next(__i: SupportsNext[_T]) -> _T: ... def next(__i: SupportsNext[_T], __default: _VT) -> _T | _VT: ... def oct(__number: int | SupportsIndex) -> str: ... -_OpenFile = StrOrBytesPath | int +_OpenFile = Union[StrOrBytesPath, int] _Opener = Callable[[str, int], int] # Text mode: always returns a TextIOWrapper diff --git a/stdlib/copyreg.pyi b/stdlib/copyreg.pyi index e23ae406ca9e..320097b3a204 100644 --- a/stdlib/copyreg.pyi +++ b/stdlib/copyreg.pyi @@ -1,7 +1,7 @@ -from typing import Any, Callable, Hashable, SupportsInt, Tuple, TypeVar +from typing import Any, Callable, Hashable, Optional, SupportsInt, Tuple, TypeVar, Union _TypeT = TypeVar("_TypeT", bound=type) -_Reduce = Tuple[Callable[..., _TypeT], Tuple[Any, ...]] | Tuple[Callable[..., _TypeT], Tuple[Any, ...], Any | None] +_Reduce = Union[Tuple[Callable[..., _TypeT], Tuple[Any, ...]], Tuple[Callable[..., _TypeT], Tuple[Any, ...], Optional[Any]]] __all__: list[str] diff --git a/stdlib/distutils/ccompiler.pyi b/stdlib/distutils/ccompiler.pyi index 13cb423cbbea..23ecd516ec11 100644 --- a/stdlib/distutils/ccompiler.pyi +++ b/stdlib/distutils/ccompiler.pyi @@ -1,6 +1,6 @@ -from typing import Any, Callable, Tuple +from typing import Any, Callable, Optional, Tuple -_Macro = Tuple[str] | Tuple[str, str | None] +_Macro = Tuple[str] | Tuple[str, Optional[str]] def gen_lib_options( compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str] diff --git a/stdlib/email/message.pyi b/stdlib/email/message.pyi index 61c67d20d2ab..a1749a4cfc2e 100644 --- a/stdlib/email/message.pyi +++ b/stdlib/email/message.pyi @@ -2,14 +2,14 @@ from email.charset import Charset from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy -from typing import Any, Generator, Iterator, List, Sequence, Tuple, TypeVar +from typing import Any, Generator, Iterator, List, Optional, Sequence, Tuple, TypeVar, Union _T = TypeVar("_T") -_PayloadType = List[Message] | str | bytes -_CharsetType = Charset | str | None -_ParamsType = str | None | Tuple[str, str | None, str] -_ParamType = str | Tuple[str | None, str | None, str] +_PayloadType = Union[List[Message], str, bytes] +_CharsetType = Union[Charset, str, None] +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] +_ParamType = Union[str, Tuple[Optional[str], Optional[str], str]] _HeaderType = Any class Message: diff --git a/stdlib/email/mime/application.pyi b/stdlib/email/mime/application.pyi index 266a639aef45..11fc470e9dd1 100644 --- a/stdlib/email/mime/application.pyi +++ b/stdlib/email/mime/application.pyi @@ -1,8 +1,8 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple +from typing import Callable, Optional, Tuple, Union -_ParamsType = str | None | Tuple[str, str | None, str] +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] class MIMEApplication(MIMENonMultipart): def __init__( diff --git a/stdlib/email/mime/audio.pyi b/stdlib/email/mime/audio.pyi index 357306e5a3b2..ee6de410bf53 100644 --- a/stdlib/email/mime/audio.pyi +++ b/stdlib/email/mime/audio.pyi @@ -1,8 +1,8 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple +from typing import Callable, Optional, Tuple, Union -_ParamsType = str | None | Tuple[str, str | None, str] +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] class MIMEAudio(MIMENonMultipart): def __init__( diff --git a/stdlib/email/mime/base.pyi b/stdlib/email/mime/base.pyi index d2116bcb989b..b88dfd492554 100644 --- a/stdlib/email/mime/base.pyi +++ b/stdlib/email/mime/base.pyi @@ -1,8 +1,8 @@ import email.message from email.policy import Policy -from typing import Tuple +from typing import Optional, Tuple, Union -_ParamsType = str | None | Tuple[str, str | None, str] +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] class MIMEBase(email.message.Message): def __init__(self, _maintype: str, _subtype: str, *, policy: Policy | None = ..., **_params: _ParamsType) -> None: ... diff --git a/stdlib/email/mime/image.pyi b/stdlib/email/mime/image.pyi index 79fb83e5ac17..886aa74d5fe5 100644 --- a/stdlib/email/mime/image.pyi +++ b/stdlib/email/mime/image.pyi @@ -1,8 +1,8 @@ from email.mime.nonmultipart import MIMENonMultipart from email.policy import Policy -from typing import Callable, Tuple +from typing import Callable, Optional, Tuple, Union -_ParamsType = str | None | Tuple[str, str | None, str] +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] class MIMEImage(MIMENonMultipart): def __init__( diff --git a/stdlib/email/mime/multipart.pyi b/stdlib/email/mime/multipart.pyi index e80375252557..6259ddf5ab8f 100644 --- a/stdlib/email/mime/multipart.pyi +++ b/stdlib/email/mime/multipart.pyi @@ -1,9 +1,9 @@ from email.message import Message from email.mime.base import MIMEBase from email.policy import Policy -from typing import Sequence, Tuple +from typing import Optional, Sequence, Tuple, Union -_ParamsType = str | None | Tuple[str, str | None, str] +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] class MIMEMultipart(MIMEBase): def __init__( diff --git a/stdlib/email/utils.pyi b/stdlib/email/utils.pyi index 6045169fc01b..3c07e98079fc 100644 --- a/stdlib/email/utils.pyi +++ b/stdlib/email/utils.pyi @@ -1,10 +1,10 @@ import datetime import sys from email.charset import Charset -from typing import Tuple, overload +from typing import Optional, Tuple, Union, overload -_ParamType = str | Tuple[str | None, str | None, str] -_PDTZ = Tuple[int, int, int, int, int, int, int, int, int, int | None] +_ParamType = Union[str, Tuple[Optional[str], Optional[str], str]] +_PDTZ = Tuple[int, int, int, int, int, int, int, int, int, Optional[int]] def quote(str: str) -> str: ... def unquote(str: str) -> str: ... diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 28c021274c8b..70d6a1fda2fc 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -6,14 +6,14 @@ from io import TextIOWrapper from string import Template from time import struct_time from types import FrameType, TracebackType -from typing import Any, ClassVar, Generic, Pattern, TextIO, Tuple, Type, TypeVar, Union, overload +from typing import Any, ClassVar, Generic, Optional, Pattern, TextIO, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal -_SysExcInfoType = Tuple[Type[BaseException], BaseException, TracebackType | None] | Tuple[None, None, None] +_SysExcInfoType = Union[Tuple[Type[BaseException], BaseException, Optional[TracebackType]], Tuple[None, None, None]] _ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException] -_ArgsType = Tuple[object, ...] | Mapping[str, object] -_FilterType = Filter | Callable[[LogRecord], int] -_Level = int | str +_ArgsType = Union[Tuple[object, ...], Mapping[str, object]] +_FilterType = Union[Filter, Callable[[LogRecord], int]] +_Level = Union[int, str] _FormatStyle = Literal["%", "{", "$"] raiseExceptions: bool diff --git a/stdlib/pickle.pyi b/stdlib/pickle.pyi index bcc1a8d8e16d..cef1ffe9eb9b 100644 --- a/stdlib/pickle.pyi +++ b/stdlib/pickle.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Protocol, Tuple, Type +from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Optional, Protocol, Tuple, Type, Union from typing_extensions import final HIGHEST_PROTOCOL: int @@ -22,7 +22,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 = Optional[Callable[[PickleBuffer], Any]] def dump( obj: Any, file: _WritableFileobj, @@ -56,13 +56,13 @@ class PickleError(Exception): ... class PicklingError(PickleError): ... class UnpicklingError(PickleError): ... -_reducedtype = ( - str - | Tuple[Callable[..., Any], Tuple[Any, ...]] - | Tuple[Callable[..., Any], Tuple[Any, ...], Any] - | Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None] - | Tuple[Callable[..., Any], Tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None] -) +_reducedtype = Union[ + str, + Tuple[Callable[..., Any], Tuple[Any, ...]], + Tuple[Callable[..., Any], Tuple[Any, ...], Any], + Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator[Any]]], + Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator[Any]], Optional[Iterator[Any]]], +] class Pickler: fast: bool diff --git a/stdlib/readline.pyi b/stdlib/readline.pyi index 718ec6981283..f8bb00cbb83e 100644 --- a/stdlib/readline.pyi +++ b/stdlib/readline.pyi @@ -1,7 +1,7 @@ from _typeshed import StrOrBytesPath -from typing import Callable, Sequence +from typing import Callable, Optional, Sequence -_CompleterT = Callable[[str, int], str | None] | None +_CompleterT = Callable[[str, int], Optional[str]] | None _CompDispT = Callable[[str, Sequence[str], int], None] | None def parse_and_bind(__string: str) -> None: ... diff --git a/stdlib/signal.pyi b/stdlib/signal.pyi index 88deb08993bd..80fe5cac268e 100644 --- a/stdlib/signal.pyi +++ b/stdlib/signal.pyi @@ -1,7 +1,7 @@ import sys from enum import IntEnum from types import FrameType -from typing import Any, Callable, Iterable, Tuple +from typing import Any, Callable, Iterable, Optional, Tuple, Union NSIG: int @@ -58,8 +58,8 @@ class Handlers(IntEnum): SIG_DFL: Handlers SIG_IGN: Handlers -_SIGNUM = int | Signals -_HANDLER = Callable[[int, FrameType | None], Any] | int | Handlers | None +_SIGNUM = Union[int, Signals] +_HANDLER = Union[Callable[[int, Optional[FrameType]], Any], int, Handlers, None] def default_int_handler(signum: int, frame: FrameType | None) -> None: ... def getsignal(__signalnum: _SIGNUM) -> _HANDLER: ... diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 9277ecfacf4a..489327fd4406 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -2,17 +2,17 @@ import enum import socket import sys from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer -from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Set, Tuple, Type, overload +from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Optional, Set, Tuple, Type, Union, overload from typing_extensions import Literal, TypedDict _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 = Callable[[], str | bytes] | str | bytes +_PeerCertRetDictType = Dict[str, Union[str, _PCTRTTT, _PCTRTT]] +_PeerCertRetType = Union[_PeerCertRetDictType, bytes, None] +_EnumRetType = List[Tuple[bytes, str, Union[Set[str], bool]]] +_PasswordType = Union[Callable[[], Union[str, bytes]], str, bytes] -_SrvnmeCbType = Callable[[SSLSocket | SSLObject, str | None, SSLSocket], int | None] +_SrvnmeCbType = Callable[[Union[SSLSocket, SSLObject], Optional[str], SSLSocket], Optional[int]] class _Cipher(TypedDict): aead: bool diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 4ca5ebf274aa..fd21aaa1cc6e 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -5,7 +5,7 @@ from enum import Enum from tkinter.constants import * # comment this out to find undefined identifier names with flake8 from tkinter.font import _FontDescription from types import TracebackType -from typing import Any, Callable, Generic, List, Mapping, Protocol, Sequence, Tuple, Type, TypeVar, overload +from typing import Any, Callable, Generic, List, Mapping, Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal, TypedDict # Using anything from tkinter.font in this file means that 'import tkinter' @@ -86,26 +86,27 @@ EXCEPTION = _tkinter.EXCEPTION # 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] # return value is returned from Button.invoke() +_ButtonCommand = Union[str, Callable[[], Any]] # 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 = str | Tuple[str] | Tuple[str, str] | Tuple[str, str, str] | Tuple[str, str, str, str] # manual page: Tk_GetCursor -# Example: entry['invalidcommand'] = [entry.register(print), '%P'] -_EntryValidateCommand = Callable[[], bool] | str | List[str] | Tuple[str, ...] -_GridIndex = int | str | Literal["all"] -_ImageSpec = _Image | str # str can be from e.g. tkinter.image_names() -_Padding = ( - _ScreenUnits - | Tuple[_ScreenUnits] - | Tuple[_ScreenUnits, _ScreenUnits] - | Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits] - | Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits] -) +_Cursor = Union[str, Tuple[str], Tuple[str, str], Tuple[str, str, str], Tuple[str, str, str, str]] # manual page: Tk_GetCursor +_EntryValidateCommand = Union[ + Callable[[], bool], str, List[str], Tuple[str, ...] +] # example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P'] +_GridIndex = Union[int, str, Literal["all"]] +_ImageSpec = Union[_Image, str] # str can be from e.g. tkinter.image_names() +_Padding = 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 # manual page: Tk_GetPixels -_XYScrollCommand = str | Callable[[float, float], Any] # -xscrollcommand and -yscrollcommand in 'options' manual page -_TakeFocusValue = int | Literal[""] | Callable[[str], bool | None] # -takefocus in manual page named 'options' +_ScreenUnits = Union[str, float] # manual page: Tk_GetPixels +_XYScrollCommand = Union[str, Callable[[float, float], Any]] # -xscrollcommand and -yscrollcommand in 'options' manual page +_TakeFocusValue = Union[int, Literal[""], Callable[[str], Optional[bool]]] # -takefocus in manual page named 'options' class EventType(str, Enum): Activate: str @@ -1605,7 +1606,7 @@ class Checkbutton(Widget): def select(self): ... def toggle(self): ... -_EntryIndex = str | int # "INDICES" in manual page +_EntryIndex = Union[str, int] # "INDICES" in manual page class Entry(Widget, XView): def __init__( @@ -1963,7 +1964,7 @@ class Listbox(Widget, XView, YView): def itemconfigure(self, index, cnf: Any | None = ..., **kw): ... itemconfig: Any -_MenuIndex = str | int +_MenuIndex = Union[str, int] class Menu(Widget): def __init__( @@ -2649,7 +2650,7 @@ class Scrollbar(Widget): def get(self): ... def set(self, first, last): ... -_TextIndex = _tkinter.Tcl_Obj | str | float | Misc +_TextIndex = Union[_tkinter.Tcl_Obj, str, float, Misc] class Text(Widget, XView, YView): def __init__( diff --git a/stdlib/tracemalloc.pyi b/stdlib/tracemalloc.pyi index ddee4d002799..3a0c02e21dec 100644 --- a/stdlib/tracemalloc.pyi +++ b/stdlib/tracemalloc.pyi @@ -1,6 +1,6 @@ import sys from _tracemalloc import * -from typing import Sequence, Tuple, overload +from typing import Optional, Sequence, Tuple, overload from typing_extensions import SupportsIndex def get_object_traceback(obj: object) -> Traceback | None: ... @@ -43,7 +43,7 @@ class Frame: def __init__(self, frame: _FrameTupleT) -> None: ... if sys.version_info >= (3, 9): - _TraceTupleT = Tuple[int, int, Sequence[_FrameTupleT], int | None] | Tuple[int, int, Sequence[_FrameTupleT]] + _TraceTupleT = Tuple[int, int, Sequence[_FrameTupleT], Optional[int]] | Tuple[int, int, Sequence[_FrameTupleT]] else: _TraceTupleT = Tuple[int, int, Sequence[_FrameTupleT]] diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 81f03ca2d64b..8c2d3157bdb3 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -638,19 +638,21 @@ class Pattern(Generic[AnyStr]): # Functions if sys.version_info >= (3, 7): - _get_type_hints_obj_allowed_types = ( - object - | Callable[..., Any] - | FunctionType - | BuiltinFunctionType - | MethodType - | ModuleType - | WrapperDescriptorType - | MethodWrapperType - | MethodDescriptorType - ) + _get_type_hints_obj_allowed_types = Union[ + object, + Callable[..., Any], + FunctionType, + BuiltinFunctionType, + MethodType, + ModuleType, + WrapperDescriptorType, + MethodWrapperType, + MethodDescriptorType, + ] else: - _get_type_hints_obj_allowed_types = object | Callable[..., Any] | FunctionType | BuiltinFunctionType | MethodType | ModuleType + _get_type_hints_obj_allowed_types = Union[ + object, Callable[..., Any], FunctionType, BuiltinFunctionType, MethodType, ModuleType, + ] if sys.version_info >= (3, 9): def get_type_hints( diff --git a/tests/check_new_syntax.py b/tests/check_new_syntax.py index cb11fdf16d91..6036a05a95f3 100755 --- a/tests/check_new_syntax.py +++ b/tests/check_new_syntax.py @@ -144,9 +144,28 @@ def visit_If(self, node: ast.If) -> None: exclude_list = list(Path("stubs/protobuf/google/protobuf").rglob("*.pyi")) + [ # TODO: figure out why new union syntax doesn't work + Path("stdlib/_typeshed/__init__.pyi"), + Path("stdlib/asyncio/tasks.pyi"), + Path("stdlib/builtins.pyi"), + Path("stdlib/copyreg.pyi"), + Path("stdlib/distutils/ccompiler.pyi"), + Path("stdlib/email/message.pyi"), + Path("stdlib/email/mime/application.pyi"), + Path("stdlib/email/mime/audio.pyi"), + Path("stdlib/email/mime/base.pyi"), + Path("stdlib/email/mime/image.pyi"), + Path("stdlib/email/mime/multipart.pyi"), + Path("stdlib/email/utils.pyi"), Path("stdlib/logging/__init__.pyi"), + Path("stdlib/pickle.pyi"), + Path("stdlib/readline.pyi"), + Path("stdlib/signal.pyi"), + Path("stdlib/ssl.pyi"), Path("stdlib/subprocess.pyi"), Path("stdlib/tempfile.pyi"), + Path("stdlib/tkinter/__init__.pyi"), + Path("stdlib/tracemalloc.pyi"), + Path("stdlib/typing.pyi"), Path("stdlib/xmlrpc/client.pyi"), Path("stdlib/xmlrpc/server.pyi"), Path("stubs/requests/requests/sessions.pyi"), From e8d6b0ef50c40ea8e18b66c0114ed50b93666255 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 17 Dec 2021 16:53:21 +0200 Subject: [PATCH 11/11] make exclude list more specific --- tests/check_new_syntax.py | 65 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/tests/check_new_syntax.py b/tests/check_new_syntax.py index 6036a05a95f3..5b1f7dab1517 100755 --- a/tests/check_new_syntax.py +++ b/tests/check_new_syntax.py @@ -12,6 +12,36 @@ CONTEXT_MANAGER_ALIASES = {"ContextManager": "AbstractContextManager", "AsyncContextManager": "AbstractAsyncContextManager"} CONTEXTLIB_ALIAS_ALLOWLIST = frozenset({Path("stdlib/contextlib.pyi"), Path("stdlib/typing_extensions.pyi")}) +union_exclude_list = [ + # TODO: figure out why new union syntax doesn't work + Path("stdlib/_typeshed/__init__.pyi"), + Path("stdlib/asyncio/tasks.pyi"), + Path("stdlib/builtins.pyi"), + Path("stdlib/copyreg.pyi"), + Path("stdlib/distutils/ccompiler.pyi"), + Path("stdlib/email/message.pyi"), + Path("stdlib/email/mime/application.pyi"), + Path("stdlib/email/mime/audio.pyi"), + Path("stdlib/email/mime/base.pyi"), + Path("stdlib/email/mime/image.pyi"), + Path("stdlib/email/mime/multipart.pyi"), + Path("stdlib/email/utils.pyi"), + Path("stdlib/logging/__init__.pyi"), + Path("stdlib/pickle.pyi"), + Path("stdlib/readline.pyi"), + Path("stdlib/signal.pyi"), + Path("stdlib/ssl.pyi"), + Path("stdlib/subprocess.pyi"), + Path("stdlib/tempfile.pyi"), + Path("stdlib/tkinter/__init__.pyi"), + Path("stdlib/tracemalloc.pyi"), + Path("stdlib/typing.pyi"), + Path("stdlib/xmlrpc/client.pyi"), + Path("stdlib/xmlrpc/server.pyi"), + Path("stubs/requests/requests/sessions.pyi"), + Path("stubs/tabulate/tabulate.pyi"), +] + def check_new_syntax(tree: ast.AST, path: Path) -> list[str]: errors = [] @@ -78,7 +108,7 @@ def old_syntax_finder(self) -> OldSyntaxFinder: return OldSyntaxFinder(set_from_collections_abc=self.set_from_collections_abc) def visit_Subscript(self, node: ast.Subscript) -> None: - if isinstance(node.value, ast.Name): + if path not in union_exclude_list and isinstance(node.value, ast.Name): if node.value.id == "Union" and isinstance(node.slice, ast.Tuple): new_syntax = " | ".join(ast.unparse(x) for x in node.slice.elts) errors.append(f"{path}:{node.lineno}: Use PEP 604 syntax for Union, e.g. `{new_syntax}`") @@ -142,41 +172,10 @@ def visit_If(self, node: ast.If) -> None: return errors -exclude_list = list(Path("stubs/protobuf/google/protobuf").rglob("*.pyi")) + [ - # TODO: figure out why new union syntax doesn't work - Path("stdlib/_typeshed/__init__.pyi"), - Path("stdlib/asyncio/tasks.pyi"), - Path("stdlib/builtins.pyi"), - Path("stdlib/copyreg.pyi"), - Path("stdlib/distutils/ccompiler.pyi"), - Path("stdlib/email/message.pyi"), - Path("stdlib/email/mime/application.pyi"), - Path("stdlib/email/mime/audio.pyi"), - Path("stdlib/email/mime/base.pyi"), - Path("stdlib/email/mime/image.pyi"), - Path("stdlib/email/mime/multipart.pyi"), - Path("stdlib/email/utils.pyi"), - Path("stdlib/logging/__init__.pyi"), - Path("stdlib/pickle.pyi"), - Path("stdlib/readline.pyi"), - Path("stdlib/signal.pyi"), - Path("stdlib/ssl.pyi"), - Path("stdlib/subprocess.pyi"), - Path("stdlib/tempfile.pyi"), - Path("stdlib/tkinter/__init__.pyi"), - Path("stdlib/tracemalloc.pyi"), - Path("stdlib/typing.pyi"), - Path("stdlib/xmlrpc/client.pyi"), - Path("stdlib/xmlrpc/server.pyi"), - Path("stubs/requests/requests/sessions.pyi"), - Path("stubs/tabulate/tabulate.pyi"), -] - - def main() -> None: errors = [] for path in chain(Path("stdlib").rglob("*.pyi"), Path("stubs").rglob("*.pyi")): - if "@python2" in path.parts or path in exclude_list: + if "@python2" in path.parts or Path("stubs/protobuf/google/protobuf") in path.parents: continue with open(path) as f: