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,6 +1,6 @@
import sys
from socket import SocketType
from typing import Any, BinaryIO, Callable, ClassVar, Text, Union
from typing import Any, BinaryIO, Callable, ClassVar, Text
class BaseServer:
address_family: int

View File

@@ -1,19 +1,19 @@
import codecs
import sys
from typing import Any, Callable, Text, Union
from typing import Any, Callable, Text
# For convenience:
_Handler = Callable[[Exception], tuple[Text, int]]
_String = Union[bytes, str]
_Errors = Union[str, Text, None]
_Decodable = Union[bytes, Text]
_Encodable = Union[bytes, Text]
_String = bytes | str
_Errors = str | Text | None
_Decodable = bytes | Text
_Encodable = bytes | Text
# This type is not exposed; it is defined in unicodeobject.c
class _EncodingMap(object):
def size(self) -> int: ...
_MapT = Union[dict[int, int], _EncodingMap]
_MapT = dict[int, int] | _EncodingMap
def register(__search_function: Callable[[str], Any]) -> None: ...
def register_error(__errors: str | Text, __handler: _Handler) -> None: ...

View File

@@ -1,6 +1,6 @@
from typing import IO, Any, BinaryIO, Union, overload
from typing import IO, Any, BinaryIO, overload
_chtype = Union[str, bytes, int]
_chtype = str | bytes | int
# ACS codes are only initialized after initscr is called
ACS_BBSS: int

View File

@@ -1,8 +1,8 @@
from types import FrameType, TracebackType
from typing import Any, Callable, Iterable, Mapping, Optional, Text
from typing import Any, Callable, Iterable, Mapping, Text
# 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]

View File

@@ -1,8 +1,8 @@
from _typeshed import Self
from mmap import mmap
from typing import IO, Any, BinaryIO, Iterable, Text, TextIO, Union
from typing import IO, Any, BinaryIO, Iterable, Text, TextIO
_bytearray_like = Union[bytearray, mmap]
_bytearray_like = bytearray | mmap
DEFAULT_BUFFER_SIZE: int

View File

@@ -14,7 +14,7 @@
import array
import mmap
from typing import Any, Container, Iterable, Protocol, Text, TypeVar, Union
from typing import Any, Container, Iterable, Protocol, Text, TypeVar
from typing_extensions import Literal, final
_KT = TypeVar("_KT")
@@ -104,7 +104,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",
@@ -133,13 +133,13 @@ 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
class HasFileno(Protocol):
def fileno(self) -> int: ...
FileDescriptor = int
FileDescriptorLike = Union[int, HasFileno]
FileDescriptorLike = int | HasFileno
class SupportsRead(Protocol[_T_co]):
def read(self, __length: int = ...) -> _T_co: ...
@@ -153,8 +153,8 @@ class SupportsNoArgReadline(Protocol[_T_co]):
class SupportsWrite(Protocol[_T_contra]):
def write(self, __s: _T_contra) -> Any: ...
ReadableBuffer = Union[bytes, bytearray, memoryview, array.array[Any], mmap.mmap, buffer]
WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, buffer]
ReadableBuffer = bytes | bytearray | memoryview | array.array[Any] | mmap.mmap | buffer
WriteableBuffer = bytearray | memoryview | array.array[Any] | mmap.mmap | buffer
# Used by type checkers for checks involving None (does not exist at runtime)
@final

View File

@@ -4,7 +4,7 @@
# file. They are provided for type checking purposes.
from sys import _OptExcInfo
from typing import Any, Callable, Iterable, Optional, Protocol, Text
from typing import Any, Callable, Iterable, Protocol, Text
class StartResponse(Protocol):
def __call__(

View File

@@ -1,10 +1,10 @@
import sys
from _typeshed import Self
from types import TracebackType
from typing import Any, Union
from typing import Any
if sys.platform == "win32":
_KeyType = Union[HKEYType, int]
_KeyType = HKEYType | int
def CloseKey(__hkey: _KeyType) -> None: ...
def ConnectRegistry(__computer_name: str | None, __key: _KeyType) -> HKEYType: ...
def CreateKey(__key: _KeyType, __sub_key: str | None) -> HKEYType: ...

View File

@@ -1,4 +1,4 @@
from typing import IO, Any, NamedTuple, Text, Union, overload
from typing import IO, Any, NamedTuple, Text, overload
from typing_extensions import Literal
class Error(Exception): ...
@@ -11,7 +11,7 @@ class _aifc_params(NamedTuple):
comptype: bytes
compname: bytes
_File = Union[Text, IO[bytes]]
_File = Text | IO[bytes]
_Marker = tuple[int, int, bytes]
class Aifc_read:

View File

@@ -1,10 +1,10 @@
from typing import IO, Any, Callable, Generator, Iterable, NoReturn, Pattern, Protocol, Sequence, Text, TypeVar, Union, overload
from typing import IO, Any, Callable, Generator, Iterable, NoReturn, Pattern, Protocol, Sequence, Text, TypeVar, overload
_T = TypeVar("_T")
_ActionT = TypeVar("_ActionT", bound=Action)
_N = TypeVar("_N")
_Text = Union[str, unicode]
_Text = str | unicode
ONE_OR_MORE: str
OPTIONAL: str

View File

@@ -1,11 +1,11 @@
from _typeshed import Self
from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, Text, TypeVar, Union, overload
from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, Text, TypeVar, overload
from typing_extensions import Literal
_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, Text)

View File

@@ -1,7 +1,7 @@
import sys
from _typeshed import FileDescriptorLike
from socket import SocketType
from typing import Any, Optional, overload
from typing import Any, overload
# cyclic dependence with asynchat
_maptype = dict[int, Any]

View File

@@ -1,7 +1,7 @@
from typing import IO, Union
from typing import IO
_encodable = Union[bytes, unicode]
_decodable = Union[bytes, unicode]
_encodable = bytes | unicode
_decodable = bytes | unicode
def b64encode(s: _encodable, altchars: bytes | None = ...) -> bytes: ...
def b64decode(s: _decodable, altchars: bytes | None = ..., validate: bool = ...) -> bytes: ...

View File

@@ -1,4 +1,4 @@
from typing import IO, Any, Union
from typing import IO, Any
class Error(Exception): ...
@@ -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: ...

View File

@@ -1,9 +1,9 @@
import io
from _typeshed import ReadableBuffer, Self, WriteableBuffer
from typing import IO, Any, Iterable, Text, Union
from typing import IO, Any, Iterable, Text
from typing_extensions import SupportsIndex
_PathOrFile = Union[Text, IO[bytes]]
_PathOrFile = Text | IO[bytes]
def compress(data: bytes, compresslevel: int = ...) -> bytes: ...
def decompress(data: bytes) -> bytes: ...

View File

@@ -1,8 +1,8 @@
from typing import SupportsComplex, SupportsFloat, Union
from typing import SupportsComplex, SupportsFloat
e: float
pi: float
_C = Union[SupportsFloat, SupportsComplex, complex]
_C = SupportsFloat | SupportsComplex | complex
def acos(__z: _C) -> complex: ...
def acosh(__z: _C) -> complex: ...

View File

@@ -1,7 +1,7 @@
import types
from _typeshed import Self
from abc import abstractmethod
from typing import IO, Any, BinaryIO, Callable, Generator, Iterable, Iterator, Protocol, Text, TextIO, Union, overload
from typing import IO, Any, BinaryIO, Callable, Generator, Iterable, Iterator, Protocol, Text, TextIO, overload
from typing_extensions import Literal
# TODO: this only satisfies the most common interface, where

View File

@@ -1,5 +1,5 @@
from types import TracebackType
from typing import IO, Any, Callable, ContextManager, Iterable, Iterator, Optional, Protocol, TypeVar
from typing import IO, Any, Callable, ContextManager, Iterable, Iterator, Protocol, TypeVar
from typing_extensions import ParamSpec
_T = TypeVar("_T")
@@ -7,7 +7,7 @@ _T_co = TypeVar("_T_co", covariant=True)
_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]
class GeneratorContextManager(ContextManager[_T_co]):
def __call__(self, func: _F) -> _F: ...

View File

@@ -59,9 +59,9 @@ pythonapi: PyDLL
# 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.
_WritableBuffer = _UnionT[bytearray, memoryview, array[Any], _CData]
_WritableBuffer = bytearray | memoryview | array[Any] | _CData
# Same as _WritableBuffer, but also includes read-only buffer types (like bytes).
_ReadOnlyBuffer = _UnionT[_WritableBuffer, bytes]
_ReadOnlyBuffer = _WritableBuffer | bytes
class _CDataMeta(type):
# By default mypy complains about the following two methods, because strictly speaking cls
@@ -81,7 +81,7 @@ class _CData(metaclass=_CDataMeta):
@classmethod
def from_address(cls: type[Self], address: int) -> Self: ...
@classmethod
def from_param(cls: type[_CT], obj: Any) -> _UnionT[_CT, _CArgObject]: ...
def from_param(cls: type[_CT], obj: Any) -> _CT | _CArgObject: ...
@classmethod
def in_dll(cls: type[Self], library: CDLL, name: str) -> Self: ...
@@ -92,7 +92,7 @@ _ECT = Callable[[Optional[type[_CData]], _FuncPointer, tuple[_CData, ...]], _CDa
_PF = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]]
class _FuncPointer(_PointerLike, _CData):
restype: _UnionT[type[_CData], Callable[[int], Any], None] = ...
restype: type[_CData] | Callable[[int], Any] | None = ...
argtypes: Sequence[type[_CData]] = ...
errcheck: _ECT = ...
@overload
@@ -125,25 +125,25 @@ class _CArgObject: ...
# Any type that can be implicitly converted to c_void_p when passed as a C function argument.
# (bytes is not included here, see below.)
_CVoidPLike = _UnionT[_PointerLike, Array[Any], _CArgObject, int]
_CVoidPLike = _PointerLike | Array[Any] | _CArgObject | int
# Same as above, but including types known to be read-only (i. e. bytes).
# This distinction is not strictly necessary (ctypes doesn't differentiate between const
# and non-const pointers), but it catches errors like memmove(b'foo', buf, 4)
# when memmove(buf, b'foo', 4) was intended.
_CVoidConstPLike = _UnionT[_CVoidPLike, bytes]
_CVoidConstPLike = _CVoidPLike | bytes
def addressof(obj: _CData) -> int: ...
def alignment(obj_or_type: _UnionT[_CData, type[_CData]]) -> int: ...
def alignment(obj_or_type: _CData | type[_CData]) -> int: ...
def byref(obj: _CData, offset: int = ...) -> _CArgObject: ...
_CastT = TypeVar("_CastT", bound=_CanCastTo)
def cast(obj: _UnionT[_CData, _CArgObject, int], typ: type[_CastT]) -> _CastT: ...
def create_string_buffer(init: _UnionT[int, bytes], size: int | None = ...) -> Array[c_char]: ...
def cast(obj: _CData | _CArgObject | int, typ: type[_CastT]) -> _CastT: ...
def create_string_buffer(init: int | bytes, size: int | None = ...) -> Array[c_char]: ...
c_buffer = create_string_buffer
def create_unicode_buffer(init: _UnionT[int, Text], size: int | None = ...) -> Array[c_wchar]: ...
def create_unicode_buffer(init: int | Text, size: int | None = ...) -> Array[c_wchar]: ...
if sys.platform == "win32":
def DllCanUnloadNow() -> int: ...
@@ -183,7 +183,7 @@ def set_errno(value: int) -> int: ...
if sys.platform == "win32":
def set_last_error(value: int) -> int: ...
def sizeof(obj_or_type: _UnionT[_CData, type[_CData]]) -> int: ...
def sizeof(obj_or_type: _CData | type[_CData]) -> int: ...
def string_at(address: _CVoidConstPLike, size: int = ...) -> bytes: ...
if sys.platform == "win32":
@@ -198,10 +198,10 @@ class _SimpleCData(Generic[_T], _CData):
class c_byte(_SimpleCData[int]): ...
class c_char(_SimpleCData[bytes]):
def __init__(self, value: _UnionT[int, bytes] = ...) -> None: ...
def __init__(self, value: int | bytes = ...) -> None: ...
class c_char_p(_PointerLike, _SimpleCData[Optional[bytes]]):
def __init__(self, value: _UnionT[int, bytes] | None = ...) -> None: ...
class c_char_p(_PointerLike, _SimpleCData[bytes | None]):
def __init__(self, value: int | bytes | None = ...) -> None: ...
class c_double(_SimpleCData[float]): ...
class c_longdouble(_SimpleCData[float]): ...
@@ -225,11 +225,11 @@ 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[Text]): ...
class c_wchar_p(_PointerLike, _SimpleCData[Optional[Text]]):
def __init__(self, value: _UnionT[int, Text] | None = ...) -> None: ...
class c_wchar_p(_PointerLike, _SimpleCData[Text | None]):
def __init__(self, value: int | Text | None = ...) -> None: ...
class c_bool(_SimpleCData[bool]):
def __init__(self, value: bool = ...) -> None: ...

View File

@@ -1,8 +1,8 @@
from _typeshed import Self
from time import struct_time
from typing import AnyStr, ClassVar, SupportsAbs, Union, overload
from typing import AnyStr, ClassVar, SupportsAbs, overload
_Text = Union[str, unicode]
_Text = str | unicode
MINYEAR: int
MAXYEAR: int

View File

@@ -1,10 +1,10 @@
from _typeshed import Self
from types import TracebackType
from typing import Iterator, MutableMapping, Union
from typing import Iterator, MutableMapping
from typing_extensions import Literal
_KeyType = Union[str, bytes]
_ValueType = Union[str, bytes]
_KeyType = str | bytes
_ValueType = str | bytes
class _Database(MutableMapping[_KeyType, bytes]):
def close(self) -> None: ...

View File

@@ -1,9 +1,9 @@
from _typeshed import Self
from types import TracebackType
from typing import Iterator, MutableMapping, Union
from typing import Iterator, MutableMapping
_KeyType = Union[str, bytes]
_ValueType = Union[str, bytes]
_KeyType = str | bytes
_ValueType = str | bytes
error = OSError

View File

@@ -1,10 +1,10 @@
from _typeshed import Self
from types import TracebackType
from typing import TypeVar, Union, overload
from typing import TypeVar, overload
_T = TypeVar("_T")
_KeyType = Union[str, bytes]
_ValueType = Union[str, bytes]
_KeyType = str | bytes
_ValueType = str | bytes
class error(OSError): ...

View File

@@ -1,10 +1,10 @@
from _typeshed import Self
from types import TracebackType
from typing import TypeVar, Union, overload
from typing import TypeVar, overload
_T = TypeVar("_T")
_KeyType = Union[str, bytes]
_ValueType = Union[str, bytes]
_KeyType = str | bytes
_ValueType = str | bytes
class error(OSError): ...

View File

@@ -2,9 +2,9 @@ from _typeshed import Self
from types import TracebackType
from typing import Any, Container, NamedTuple, Sequence, Text, Union
_Decimal = Union[Decimal, int]
_Decimal = Decimal | int
_DecimalNew = Union[Decimal, float, Text, tuple[int, Sequence[int], int]]
_ComparableNum = Union[Decimal, float]
_ComparableNum = Decimal | float
class DecimalTuple(NamedTuple):
sign: int

View File

@@ -1,11 +1,11 @@
from typing import Any, AnyStr, Callable, Generic, Iterable, Iterator, NamedTuple, Sequence, Text, TypeVar, Union, overload
from typing import Any, AnyStr, Callable, Generic, Iterable, Iterator, NamedTuple, Sequence, Text, TypeVar, overload
_T = TypeVar("_T")
# Aliases can't point to type vars, so we need to redeclare AnyStr
_StrType = TypeVar("_StrType", Text, bytes)
_JunkCallback = Union[Callable[[Text], bool], Callable[[str], bool]]
_JunkCallback = Callable[[Text], bool] | Callable[[str], bool]
class Match(NamedTuple):
a: int

View File

@@ -13,12 +13,12 @@ from opcode import (
opmap as opmap,
opname as opname,
)
from typing import Any, Callable, Iterator, Union
from typing import Any, Callable, Iterator
# Strictly this should not have to include Callable, but mypy doesn't use FunctionType
# for functions (python/mypy#3171)
_have_code = Union[types.MethodType, types.FunctionType, types.CodeType, type, Callable[..., Any]]
_have_code_or_string = Union[_have_code, str, bytes]
_have_code = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any]
_have_code_or_string = _have_code | str | bytes
COMPILER_FLAG_NAMES: dict[int, str]

View File

@@ -1,6 +1,6 @@
from typing import AnyStr, Iterable, Union
from typing import AnyStr, Iterable
_EitherStr = Union[str, unicode]
_EitherStr = str | unicode
def fnmatch(filename: _EitherStr, pattern: _EitherStr) -> bool: ...
def fnmatchcase(filename: _EitherStr, pattern: _EitherStr) -> bool: ...

View File

@@ -1,10 +1,10 @@
from _typeshed import Self
from decimal import Decimal
from numbers import Integral, Rational, Real
from typing import Union, overload
from typing import overload
from typing_extensions import Literal
_ComparableNum = Union[int, float, Decimal, Real]
_ComparableNum = int | float | Decimal | Real
@overload
def gcd(a: int, b: int) -> int: ...

View File

@@ -1,10 +1,10 @@
from _typeshed import SupportsRead, SupportsReadline
from socket import socket
from ssl import SSLContext
from typing import Any, BinaryIO, Callable, Text, Union
from typing import Any, BinaryIO, Callable, Text
from typing_extensions import Literal
_IntOrStr = Union[int, Text]
_IntOrStr = int | Text
MSG_OOB: int
FTP_PORT: int

View File

@@ -1,5 +1,5 @@
from _typeshed import SupportsLessThanT
from typing import Sequence, Text, Union, overload
from typing import Sequence, Text, overload
from typing_extensions import Literal
# All overloads can return empty string. Ideally, Literal[""] would be a valid

View File

@@ -1,6 +1,4 @@
from typing import Union
_DataType = Union[str, unicode, bytearray, buffer, memoryview]
_DataType = str | unicode | bytearray | buffer | memoryview
class _hash(object): # This is not actually in the module namespace.
@property

View File

@@ -1,10 +1,10 @@
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
_DigestMod = Union[str, Callable[[], _Hash], ModuleType]
_DigestMod = str | Callable[[], _Hash] | ModuleType
digest_size: None

View File

@@ -1,11 +1,11 @@
from typing import Any, BinaryIO, Callable, Protocol, Text, Union, overload
from typing import Any, BinaryIO, Callable, Protocol, Text, overload
class _ReadableBinary(Protocol):
def tell(self) -> int: ...
def read(self, size: int) -> bytes: ...
def seek(self, offset: int) -> Any: ...
_File = Union[Text, _ReadableBinary]
_File = Text | _ReadableBinary
@overload
def what(file: _File, h: None = ...) -> str | None: ...

View File

@@ -1,9 +1,9 @@
from _typeshed import Self
from lib2to3.pgen2.grammar import Grammar
from typing import Any, Callable, Iterator, Optional, Text, TypeVar, Union
from typing import Any, Callable, Iterator, Optional, Text, TypeVar
_P = TypeVar("_P")
_NL = Union[Node, Leaf]
_NL = Node | Leaf
_Context = tuple[Text, int, int]
_Results = dict[Text, _NL]
_RawNode = tuple[int, Text, _Context, Optional[list[_NL]]]

View File

@@ -5,10 +5,10 @@ from types import FrameType, TracebackType
from typing import IO, Any, Callable, Generic, Mapping, MutableMapping, Optional, Sequence, Text, TypeVar, Union, overload
_SysExcInfoType = Union[tuple[type, BaseException, Optional[TracebackType]], tuple[None, None, None]]
_ExcInfoType = Union[None, bool, _SysExcInfoType]
_ExcInfoType = None | bool | _SysExcInfoType
_ArgsType = Union[tuple[Any, ...], Mapping[str, Any]]
_FilterType = Union[Filter, Callable[[LogRecord], int]]
_Level = Union[int, Text]
_FilterType = Filter | Callable[[LogRecord], int]
_Level = int | Text
raiseExceptions: bool
logThreads: bool

View File

@@ -1,26 +1,11 @@
import email.message
from types import TracebackType
from typing import (
IO,
Any,
AnyStr,
Callable,
Generic,
Iterable,
Iterator,
Mapping,
Protocol,
Sequence,
Text,
TypeVar,
Union,
overload,
)
from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Mapping, Protocol, Sequence, Text, TypeVar, overload
from typing_extensions import Literal
_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]]: ...

View File

@@ -1,6 +1,6 @@
from typing import Mapping, Sequence, Union
from typing import Mapping, Sequence
_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] = ...

View File

@@ -3,9 +3,9 @@ import socket
import ssl
from _typeshed import Self
from builtins import list as List # alias to avoid a name clash with a method named `list` in `_NNTPBase`
from typing import IO, Any, Iterable, NamedTuple, Union
from typing import IO, Any, Iterable, NamedTuple
_File = Union[IO[bytes], bytes, str, None]
_File = IO[bytes] | bytes | str | None
class NNTPError(Exception):
response: str

View File

@@ -1,7 +1,7 @@
from typing import IO, Any, AnyStr, Callable, Iterable, Mapping, Sequence, Union, overload
from typing import IO, Any, AnyStr, Callable, Iterable, Mapping, Sequence, overload
# See https://groups.google.com/forum/#!topic/python-ideas/gA1gdj3RZ5g
_Text = Union[str, unicode]
_Text = str | unicode
NO_DEFAULT: tuple[_Text, ...]
SUPPRESS_HELP: _Text

View File

@@ -1,6 +1,6 @@
from typing import IO, Any, Mapping, Text, Union
from typing import IO, Any, Mapping, Text
_Path = Union[str, Text]
_Path = str | Text
def readPlist(pathOrFile: _Path | IO[bytes]) -> Any: ...
def writePlist(value: Mapping[str, Any], pathOrFile: _Path | IO[bytes]) -> None: ...

View File

@@ -1,9 +1,9 @@
from _typeshed import Self
from cProfile import Profile as _cProfile
from profile import Profile
from typing import IO, Any, Iterable, Text, TypeVar, Union, overload
from typing import IO, Any, Iterable, Text, TypeVar, overload
_Selector = Union[str, float, int]
_Selector = str | float | int
_T = TypeVar("_T", bound=Stats)
class Stats:

View File

@@ -1,6 +1,6 @@
from typing import Text, Union
from typing import Text
_EitherStr = Union[bytes, Text]
_EitherStr = bytes | Text
class PyCompileError(Exception):
exc_type_name: str

View File

@@ -2,8 +2,8 @@ import sys
from typing import Callable, Optional, Sequence, Text
if sys.platform != "win32":
_CompleterT = Optional[Callable[[str, int], Optional[str]]]
_CompDispT = Optional[Callable[[str, Sequence[str], int], None]]
_CompleterT = Optional[Callable[[str, int], str | None]]
_CompDispT = Callable[[str, Sequence[str], int], None] | None
def parse_and_bind(__string: str) -> None: ...
def read_init_file(__filename: Text | None = ...) -> None: ...
def get_line_buffer() -> str: ...

View File

@@ -1,6 +1,6 @@
from typing import Any, Union
from typing import Any
_Text = Union[str, unicode]
_Text = str | unicode
class Completer:
def __init__(self, namespace: dict[str, Any] | None = ...) -> None: ...

View File

@@ -1,8 +1,8 @@
from _typeshed import Self
from typing import Any, Hashable, Iterable, Iterator, MutableMapping, TypeVar, Union
from typing import Any, Hashable, Iterable, Iterator, MutableMapping, TypeVar
_T = TypeVar("_T")
_Setlike = Union[BaseSet[_T], Iterable[_T]]
_Setlike = BaseSet[_T] | Iterable[_T]
class BaseSet(Iterable[_T]):
def __init__(self) -> None: ...

View File

@@ -1,5 +1,5 @@
from _typeshed import SupportsRead, SupportsWrite
from typing import Any, AnyStr, Callable, Iterable, Sequence, Text, TypeVar, Union
from typing import Any, AnyStr, Callable, Iterable, Sequence, Text, TypeVar
_AnyStr = TypeVar("_AnyStr", str, unicode)
_AnyPath = TypeVar("_AnyPath", str, unicode)
@@ -21,7 +21,7 @@ def copytree(
) -> _PathReturn: ...
def rmtree(path: _AnyPath, ignore_errors: bool = ..., onerror: Callable[[Any, _AnyPath, Any], Any] | None = ...) -> None: ...
_CopyFn = Union[Callable[[str, str], None], Callable[[Text, Text], None]]
_CopyFn = Callable[[str, str], None] | Callable[[Text, Text], None]
def move(src: Text, dst: Text) -> _PathReturn: ...
def make_archive(

View File

@@ -1,5 +1,5 @@
from types import FrameType
from typing import Callable, Union
from typing import Callable
SIG_DFL: int
SIG_IGN: int
@@ -55,7 +55,7 @@ CTRL_BREAK_EVENT: int
class ItimerError(IOError): ...
_HANDLER = Union[Callable[[int, FrameType], None], int, None]
_HANDLER = Callable[[int, FrameType], None] | int | None
def alarm(time: int) -> int: ...
def getsignal(signalnum: int) -> _HANDLER: ...

View File

@@ -377,7 +377,7 @@ _Address = Union[tuple[Any, ...], str]
_RetAddress = Any
# TODO Most methods allow bytes as address objects
_WriteBuffer = Union[bytearray, memoryview]
_WriteBuffer = bytearray | memoryview
_CMSG = tuple[int, int, bytes]

View File

@@ -1,4 +1,4 @@
from typing import Any, Iterable, Match, Optional, Pattern as _Pattern, Union
from typing import Any, Iterable, Match, Optional, Pattern as _Pattern
SPECIAL_CHARS: str
REPEAT_CHARS: str
@@ -25,8 +25,8 @@ _OpSubpatternType = tuple[Optional[int], int, int, SubPattern]
_OpGroupRefExistsType = tuple[int, SubPattern, SubPattern]
_OpInType = list[tuple[str, int]]
_OpBranchType = tuple[None, list[SubPattern]]
_AvType = Union[_OpInType, _OpBranchType, Iterable[SubPattern], _OpGroupRefExistsType, _OpSubpatternType]
_CodeType = Union[str, _AvType]
_AvType = _OpInType | _OpBranchType | Iterable[SubPattern] | _OpGroupRefExistsType | _OpSubpatternType
_CodeType = str | _AvType
class SubPattern:
pattern: str

View File

@@ -1,18 +1,18 @@
import socket
import sys
from _typeshed import Self, StrPath
from typing import Any, Callable, ClassVar, Iterable, NamedTuple, Optional, Text, Union, overload
from typing import Any, Callable, ClassVar, Iterable, NamedTuple, Text, Union, overload
from typing_extensions import Literal
_PCTRTT = tuple[tuple[str, str], ...]
_PCTRTTT = tuple[_PCTRTT, ...]
_PeerCertRetDictType = dict[str, Union[str, _PCTRTTT, _PCTRTT]]
_PeerCertRetType = Union[_PeerCertRetDictType, bytes, None]
_PeerCertRetDictType = dict[str, str | _PCTRTTT | _PCTRTT]
_PeerCertRetType = _PeerCertRetDictType | bytes | None
_EnumRetType = list[tuple[bytes, str, Union[set[str], bool]]]
_PasswordType = Union[Callable[[], Union[str, bytes]], str, bytes]
_PasswordType = Union[Callable[[], str | bytes], str, bytes]
_SC1ArgT = SSLSocket
_SrvnmeCbType = Callable[[_SC1ArgT, Optional[str], SSLSocket], Optional[int]]
_SrvnmeCbType = Callable[[_SC1ArgT, str | None, SSLSocket], int | None]
class SSLError(OSError):
library: str

View File

@@ -1,12 +1,12 @@
from array import array
from mmap import mmap
from typing import Any, Text, Union
from typing import Any, Text
class error(Exception): ...
_FmtType = Union[bytes, Text]
_BufferType = Union[array[int], bytes, bytearray, buffer, memoryview, mmap]
_WriteBufferType = Union[array[Any], bytearray, buffer, memoryview, mmap]
_FmtType = bytes | Text
_BufferType = array[int] | bytes | bytearray | buffer | memoryview | mmap
_WriteBufferType = array[Any] | bytearray | buffer | memoryview | mmap
def pack(fmt: _FmtType, *v: Any) -> bytes: ...
def pack_into(fmt: _FmtType, buffer: _WriteBufferType, offset: int, *v: Any) -> None: ...

View File

@@ -1,9 +1,9 @@
from typing import IO, Any, Callable, Generic, Mapping, Optional, Sequence, Text, TypeVar, Union
from typing import IO, Any, Callable, Generic, Mapping, Sequence, Text, TypeVar
_FILE = Union[None, int, IO[Any]]
_TXT = Union[bytes, Text]
_CMD = Union[_TXT, Sequence[_TXT]]
_ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]]
_FILE = None | int | IO[Any]
_TXT = bytes | Text
_CMD = _TXT | Sequence[_TXT]
_ENV = Mapping[bytes, _TXT] | Mapping[Text, _TXT]
# Same args as Popen.__init__
def call(

View File

@@ -1,6 +1,6 @@
from typing import IO, Any, NoReturn, Text, Union
from typing import IO, Any, NoReturn, Text
_File = Union[Text, IO[bytes]]
_File = Text | IO[bytes]
class Error(Exception): ...

View File

@@ -1,9 +1,9 @@
import sys
from _typeshed import FileDescriptorLike
from typing import Any, Union
from typing import Any
if sys.platform != "win32":
_Attr = list[Union[int, list[Union[bytes, int]]]]
_Attr = list[int | list[bytes | int]]
# TODO constants not really documented
B0: int

View File

@@ -1,8 +1,8 @@
from types import FrameType, TracebackType
from typing import Any, Callable, Iterable, Mapping, Optional, Text, TypeVar
from typing import Any, Callable, Iterable, Mapping, Text, 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]

View File

@@ -1,8 +1,8 @@
from typing import IO, Any, Callable, Sequence, Text, Union
from typing import IO, Any, Callable, Sequence, Text
_str = Union[str, Text]
_str = str | Text
_Timer = Callable[[], float]
_stmt = Union[_str, Callable[[], Any]]
_stmt = _str | Callable[[], Any]
default_timer: _Timer

View File

@@ -1,7 +1,7 @@
import sys
from typing import IO, Union
from typing import IO
_FD = Union[int, IO[str]]
_FD = int | IO[str]
if sys.platform != "win32":
# XXX: Undocumented integer constants

View File

@@ -15,7 +15,7 @@ _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

View File

@@ -10,7 +10,7 @@ _FT = TypeVar("_FT")
_P = ParamSpec("_P")
_ExceptionType = Union[type[BaseException], tuple[type[BaseException], ...]]
_Regexp = Union[Text, Pattern[Text]]
_Regexp = Text | Pattern[Text]
_SysExcInfoType = Union[tuple[type[BaseException], BaseException, types.TracebackType], tuple[None, None, None]]

View File

@@ -1,9 +1,9 @@
import ssl
from httplib import HTTPConnectionProtocol, HTTPResponse
from typing import Any, AnyStr, Callable, Mapping, Sequence, Text, Union
from typing import Any, AnyStr, Callable, Mapping, Sequence, Text
from urllib import addinfourl
_string = Union[str, unicode]
_string = str | unicode
class URLError(IOError):
reason: str | BaseException

View File

@@ -1,6 +1,6 @@
from typing import AnyStr, NamedTuple, Sequence, Union, overload
from typing import AnyStr, NamedTuple, Sequence, overload
_String = Union[str, unicode]
_String = str | unicode
uses_relative: list[str]
uses_netloc: list[str]

View File

@@ -1,6 +1,6 @@
from typing import BinaryIO, Text, Union
from typing import BinaryIO, Text
_File = Union[Text, BinaryIO]
_File = Text | BinaryIO
class Error(Exception): ...

View File

@@ -1,6 +1,6 @@
from typing import IO, Any, BinaryIO, NoReturn, Text, Union
from typing import IO, Any, BinaryIO, NoReturn, Text
_File = Union[Text, IO[bytes]]
_File = Text | IO[bytes]
class Error(Exception): ...

View File

@@ -12,7 +12,6 @@ from typing import (
Sequence,
Text,
TypeVar,
Union,
overload,
)
@@ -29,7 +28,7 @@ _T = TypeVar("_T")
# Type for parser inputs. Parser will accept any unicode/str/bytes and coerce,
# and this is true in py2 and py3 (even fromstringlist() in python3 can be
# called with a heterogeneous list)
_parser_input_type = Union[bytes, Text]
_parser_input_type = bytes | Text
# Type for individual tag/attr/ns/text values in args to most functions.
# In py2, the library accepts str or unicode everywhere and coerces
@@ -38,7 +37,7 @@ _parser_input_type = Union[bytes, Text]
# so we exclude it. (why? the parser never produces bytes when it parses XML,
# so e.g., element.get(b'name') will always return None for parsed XML, even if
# there is a 'name' attribute.)
_str_argument_type = Union[str, Text]
_str_argument_type = str | Text
# Type for return values from individual tag/attr/text values
# in python2, if the tag/attribute/text wasn't decode-able as ascii, it
@@ -46,7 +45,7 @@ _str_argument_type = Union[str, Text]
# _fixtext function in the source). Client code knows best:
_str_result_type = Any
_file_or_filename = Union[Text, FileDescriptor, IO[Any]]
_file_or_filename = Text | FileDescriptor | IO[Any]
class Element(MutableSequence[Element]):
tag: _str_result_type

View File

@@ -10,7 +10,7 @@ from typing import IO, Any, AnyStr, Callable, Iterable, Mapping, MutableMapping,
_Unmarshaller = Any
_timeTuple = tuple[int, int, int, int, int, int, int, int, int]
# Represents types that can be compared against a DateTime object
_dateTimeComp = Union[unicode, DateTime, datetime]
_dateTimeComp = unicode | DateTime | datetime
# A "host description" used by Transport factories
_hostDesc = Union[str, tuple[str, Mapping[Any, Any]]]

View File

@@ -1,9 +1,9 @@
import io
from _typeshed import Self, StrPath
from types import TracebackType
from typing import IO, Any, Callable, Iterable, Pattern, Protocol, Sequence, Text, Union
from typing import IO, Any, Callable, Iterable, Pattern, Protocol, Sequence, Text
_SZI = Union[Text, ZipInfo]
_SZI = Text | ZipInfo
_DT = tuple[int, int, int, int, int, int]
class BadZipfile(Exception): ...