Use PEP 604 syntax wherever possible (#7493)

This commit is contained in:
Alex Waygood
2022-03-16 15:01:33 +00:00
committed by GitHub
parent 15e21a8dc1
commit 3ab250eec8
174 changed files with 472 additions and 490 deletions

View File

@@ -1,7 +1,7 @@
from typing import Union
_RGB = Union[tuple[int, int, int], tuple[int, int, int, int]]
_Ink = Union[str, int, _RGB]
_Ink = str | int | _RGB
_GreyScale = tuple[int, int]
def getrgb(color: _Ink) -> _RGB: ...

View File

@@ -2,9 +2,9 @@ import datetime
import time
from collections.abc import Callable, Mapping, Sequence
from decimal import Decimal
from typing import Any, Optional, TypeVar
from typing import Any, 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: ...

View File

@@ -1,9 +1,9 @@
from typing import Any, Pattern, Union
from typing import Any, Pattern
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): ...

View File

@@ -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
@@ -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: ...

View File

@@ -1,10 +1,10 @@
from _typeshed import StrOrBytesPath, StrPath
from collections.abc import Iterator
from typing import Any, Union
from typing import Any
from pygments.lexer import Lexer, LexerMeta
_OpenFile = Union[StrOrBytesPath, int] # copy/pasted from builtins.pyi
_OpenFile = StrOrBytesPath | int # copy/pasted from builtins.pyi
def get_all_lexers() -> Iterator[tuple[str, tuple[str, ...], tuple[str, ...], tuple[str, ...]]]: ...
def find_lexer_class(name: str) -> LexerMeta | None: ...

View File

@@ -2,11 +2,11 @@ import sys
from _typeshed import StrOrBytesPath
from asyncio.events import AbstractEventLoop
from os import stat_result
from typing import Any, Sequence, Union, overload
from typing import Any, Sequence, overload
from . import ospath as path
_FdOrAnyPath = Union[int, StrOrBytesPath]
_FdOrAnyPath = int | StrOrBytesPath
async def stat(
path: _FdOrAnyPath, # noqa: F811

View File

@@ -7,14 +7,14 @@ 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
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

View File

@@ -1,6 +1,6 @@
from _typeshed import Self
from collections.abc import Iterator
from typing import Any, Callable, Generic, Iterable, Pattern, TypeVar, Union, overload
from typing import Any, Callable, Generic, Iterable, Pattern, TypeVar, overload
from . import BeautifulSoup
from .builder import TreeBuilder
@@ -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

View File

@@ -1,5 +1,5 @@
from collections.abc import Callable, Container, Iterable
from typing import Any, Pattern, Union
from typing import Any, Pattern
from .html5lib_shim import BleachHTMLParser, BleachHTMLSerializer, SanitizerFilter
@@ -39,8 +39,8 @@ class Cleaner:
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: ...

View File

@@ -1,6 +1,6 @@
import sys
from _typeshed import SupportsWrite
from typing import Any, Callable, Optional, Pattern, Sequence, TextIO, Union
from typing import Any, Callable, Pattern, Sequence, TextIO, Union
if sys.platform == "win32":
from .winterm import WinTerm
@@ -19,7 +19,7 @@ class StreamWrapper:
@property
def closed(self) -> bool: ...
_WinTermCall = Callable[[Optional[int], bool, bool], None]
_WinTermCall = Callable[[int | None, bool, bool], None]
_WinTermCallDict = dict[int, Union[tuple[_WinTermCall], tuple[_WinTermCall, int], tuple[_WinTermCall, int, bool]]]
class AnsiToWin32:

View File

@@ -1,9 +1,9 @@
import datetime
from _typeshed import Self
from typing import Any, Iterator, Text, Union
from typing import Any, Iterator, Text
from typing_extensions import Literal
_RetType = Union[type[float], type[datetime.datetime]]
_RetType = type[float | datetime.datetime]
class CroniterError(ValueError): ...
class CroniterBadCronError(CroniterError): ...

View File

@@ -1,8 +1,8 @@
from typing import Any, Iterable, Union
from typing import Any, Iterable
__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 = ...

View File

@@ -1,10 +1,10 @@
from collections.abc import Awaitable, Callable, Iterator, Sequence
from datetime import date, datetime, timedelta
from numbers import Real
from typing import Any, TypeVar, Union, overload
from typing import Any, TypeVar, overload
_T = TypeVar("_T")
_Freezable = Union[str, datetime, date, timedelta]
_Freezable = str | datetime | date | timedelta
class TickingDateTimeFactory:
def __init__(self, time_to_freeze: datetime, start: datetime) -> None: ...

View File

@@ -1,5 +1,5 @@
import sys
from typing import Protocol, Union
from typing import Protocol
MSG_DISCONNECT: int
MSG_IGNORE: int
@@ -109,7 +109,7 @@ else:
class _SupportsAsBytes(Protocol):
def asbytes(self) -> bytes: ...
_LikeBytes = Union[bytes, str, _SupportsAsBytes]
_LikeBytes = bytes | str | _SupportsAsBytes
def asbytes(s: _LikeBytes) -> bytes: ...

View File

@@ -2,7 +2,7 @@ from logging import Logger
from socket import socket
from threading import Condition, Event, Lock, Thread
from types import ModuleType
from typing import Any, Callable, Iterable, Protocol, Sequence, Union
from typing import Any, Callable, Iterable, Protocol, Sequence
from paramiko.auth_handler import AuthHandler, _InteractiveCallback
from paramiko.channel import Channel
@@ -15,7 +15,7 @@ from paramiko.ssh_gss import _SSH_GSSAuth
from paramiko.util import ClosingContextManager
_Addr = tuple[str, int]
_SocketLike = Union[str, _Addr, socket, Channel]
_SocketLike = str | _Addr | socket | Channel
class _KexEngine(Protocol):
def start_kex(self) -> None: ...

View File

@@ -1,12 +1,12 @@
from _typeshed import StrOrBytesPath
from datetime import datetime
from typing import Any, Callable, Iterable, Sequence, Union
from typing import Any, Callable, Iterable, Sequence
from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPublicKey
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey
from cryptography.x509 import Certificate, CertificateRevocationList, CertificateSigningRequest
_Key = Union[DSAPrivateKey, DSAPublicKey, RSAPrivateKey, RSAPublicKey]
_Key = DSAPrivateKey | DSAPublicKey | RSAPrivateKey | RSAPublicKey
FILETYPE_PEM: int
FILETYPE_ASN1: int

View File

@@ -1,4 +1,4 @@
from typing import Callable, Mapping, Optional, Sequence, Union
from typing import Callable, Mapping, Optional, Sequence
from typing_extensions import Final
paFloat32: Final[int]
@@ -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: ...

View File

@@ -2,7 +2,7 @@ from _typeshed import Self
from contextlib import AbstractContextManager
from stat import S_IMODE as S_IMODE
from types import TracebackType
from typing import IO, Any, Callable, Sequence, Union
from typing import IO, Any, Callable, Sequence
from typing_extensions import Literal
import paramiko
@@ -33,7 +33,7 @@ class CnOpts:
def get_hostkey(self, host: str) -> paramiko.PKey: ...
_Callback = Callable[[int, int], Any]
_Path = Union[str, bytes]
_Path = str | bytes
class Connection:
def __init__(

View File

@@ -1,9 +1,9 @@
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
_FileOrStr = Union[bytes, Text, IO[str], IO[Any]]
_FileOrStr = bytes | Text | IO[str] | IO[Any]
class parserinfo(object):
JUMP: list[str]

View File

@@ -1,9 +1,9 @@
from _typeshed import SupportsRead
from datetime import date, datetime, time, tzinfo
from typing import Text, Union
from typing import Text
_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 = ...): ...

View File

@@ -1,10 +1,10 @@
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
_FileObj = Union[str, Text, IO[str], IO[Text]]
_FileObj = str | Text | IO[str] | IO[Text]
_DT = TypeVar("_DT", bound=datetime.datetime)
ZERO: datetime.timedelta

View File

@@ -1,7 +1,7 @@
import threading
from _typeshed import Self, SupportsItems
from datetime import datetime, timedelta
from typing import Any, Callable, ClassVar, Generic, Iterable, Iterator, Mapping, Pattern, Sequence, TypeVar, Union, overload
from typing import Any, Callable, ClassVar, Generic, Iterable, Iterator, Mapping, Pattern, Sequence, TypeVar, overload
from typing_extensions import Literal
from .commands import CoreCommands, RedisModuleCommands, SentinelCommands
@@ -9,11 +9,11 @@ from .connection import ConnectionPool, _ConnectionPoolOptions
from .lock import Lock
from .retry import Retry
_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")

View File

@@ -1,13 +1,13 @@
import builtins
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from datetime import datetime, timedelta
from typing import Any, Generic, TypeVar, Union, overload
from typing import Any, Generic, TypeVar, overload
from typing_extensions import Literal
from ..client import _CommandOptions, _Key, _Value
_ScoreCastFuncReturn = TypeVar("_ScoreCastFuncReturn")
_StrType = TypeVar("_StrType", bound=Union[str, bytes])
_StrType = TypeVar("_StrType", bound=str | bytes)
class ACLCommands(Generic[_StrType]):
def acl_cat(self, category: str | None = ..., **kwargs: _CommandOptions) -> list[str]: ...

View File

@@ -51,15 +51,15 @@ _Data = Union[None, Text, bytes, Mapping[str, Any], Mapping[Text, Any], Iterable
_Hook = Callable[[Response], Any]
_Hooks = MutableMapping[Text, _Hook | 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]

View File

@@ -3,17 +3,17 @@ import types
import zipimport
from _typeshed import Self
from abc import ABCMeta
from typing import IO, Any, Callable, Generator, Iterable, Optional, Sequence, TypeVar, Union, overload
from typing import IO, Any, Callable, Generator, Iterable, Sequence, TypeVar, overload
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]

View File

@@ -1,11 +1,11 @@
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
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: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, Container, Iterable, Mapping, NamedTuple, Sequence, Union
from typing import Any, Callable, Container, Iterable, Mapping, NamedTuple, Sequence
LATEX_ESCAPE_RULES: dict[str, str]
MIN_PADDING: int
@@ -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