Use PEP 604 syntax wherever possible, part II (#7514)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Alex Waygood
2022-03-19 14:27:35 +00:00
committed by GitHub
parent 340c6c97ed
commit 1acc8f3bd6
55 changed files with 116 additions and 141 deletions

View File

@@ -1,8 +1,8 @@
import datetime
from time import struct_time
from typing import Any, Iterable, Optional, Sequence
from typing import Any, Iterable, Sequence
_LocaleType = tuple[Optional[str], Optional[str]]
_LocaleType = tuple[str | None, str | None]
class IllegalMonthError(ValueError):
def __init__(self, month: int) -> None: ...

View File

@@ -1,7 +1,7 @@
from typing import Any, Callable, Hashable, Optional, SupportsInt, TypeVar, Union
from typing import Any, Callable, Hashable, SupportsInt, TypeVar, Union
_TypeT = TypeVar("_TypeT", bound=type)
_Reduce = Union[tuple[Callable[..., _TypeT], tuple[Any, ...]], tuple[Callable[..., _TypeT], tuple[Any, ...], Optional[Any]]]
_Reduce = Union[tuple[Callable[..., _TypeT], tuple[Any, ...]], tuple[Callable[..., _TypeT], tuple[Any, ...], Any | None]]
__all__ = ["pickle", "constructor", "add_extension", "remove_extension", "clear_extension_cache"]

View File

@@ -1,7 +1,7 @@
from typing import Any, Callable, Hashable, Optional, SupportsInt, TypeVar, Union
from typing import Any, Callable, Hashable, SupportsInt, TypeVar, Union
_TypeT = TypeVar("_TypeT", bound=type)
_Reduce = Union[tuple[Callable[..., _TypeT], tuple[Any, ...]], tuple[Callable[..., _TypeT], tuple[Any, ...], Optional[Any]]]
_Reduce = Union[tuple[Callable[..., _TypeT], tuple[Any, ...]], tuple[Callable[..., _TypeT], tuple[Any, ...], Any | None]]
__all__ = ["pickle", "constructor", "add_extension", "remove_extension", "clear_extension_cache"]

View File

@@ -9,7 +9,6 @@ from typing import (
Iterable,
Iterator,
Mapping,
Optional,
Sequence,
Text,
TypeVar,
@@ -88,7 +87,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):

View File

@@ -1,6 +1,6 @@
from typing import Any, Callable, Optional, Union
from typing import Any, Callable, Union
_Macro = Union[tuple[str], tuple[str, Optional[str]]]
_Macro = Union[tuple[str], tuple[str, str | None]]
def gen_lib_options(
compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str]

View File

@@ -1,6 +1,6 @@
from typing import Any, Mapping, Optional, overload
from typing import Any, Mapping, overload
_Option = tuple[str, Optional[str], str]
_Option = tuple[str, str | None, str]
_GR = tuple[list[str], OptionDummy]
def fancy_getopt(

View File

@@ -1,7 +1,7 @@
from email.mime.nonmultipart import MIMENonMultipart
from typing import Callable, Optional, Union
from typing import Callable, Union
_ParamsType = Union[str, None, tuple[str, Optional[str], str]]
_ParamsType = Union[str, None, tuple[str, str | None, str]]
class MIMEApplication(MIMENonMultipart):
def __init__(

View File

@@ -3,14 +3,14 @@ import time
from builtins import list as List # alias to avoid name clashes with `IMAP4.list`
from socket import socket as _socket
from ssl import SSLSocket
from typing import IO, Any, Callable, Pattern, Text, Union
from typing import IO, Any, Callable, Pattern, Text
from typing_extensions import Literal
# TODO: Commands should use their actual return types, not this type alias.
# 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]]
class IMAP4:
error: type[Exception] = ...

View File

@@ -1,5 +1,5 @@
from types import CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
from typing import Any, AnyStr, Callable, NamedTuple, Optional, Sequence, Union
from typing import Any, AnyStr, Callable, NamedTuple, Sequence, Union
# Types and members
class EndOfBlock(Exception): ...
@@ -106,7 +106,7 @@ class Traceback(NamedTuple):
code_context: list[str] | None
index: int | None # type: ignore[assignment]
_FrameInfo = tuple[FrameType, str, int, str, Optional[list[str]], Optional[int]]
_FrameInfo = tuple[FrameType, str, int, str, list[str] | None, int | None]
def getouterframes(frame: FrameType, context: int = ...) -> list[_FrameInfo]: ...
def getframeinfo(frame: FrameType | TracebackType, context: int = ...) -> Traceback: ...

View File

@@ -1,7 +1,7 @@
from _typeshed import Self, StrPath
from typing import Optional, Text
from typing import Text
_Label = tuple[int, Optional[Text]]
_Label = tuple[int, Text | None]
_DFA = list[list[tuple[int, int]]]
_DFAS = tuple[_DFA, dict[int, int]]

View File

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

View File

@@ -2,9 +2,9 @@ import threading
from _typeshed import StrPath, SupportsWrite
from time import struct_time
from types import FrameType, TracebackType
from typing import IO, Any, Callable, Generic, Mapping, MutableMapping, Optional, Sequence, Text, TypeVar, Union, overload
from typing import IO, Any, Callable, Generic, Mapping, MutableMapping, Sequence, Text, TypeVar, Union, overload
_SysExcInfoType = Union[tuple[type, BaseException, Optional[TracebackType]], tuple[None, None, None]]
_SysExcInfoType = Union[tuple[type, BaseException, TracebackType | None], tuple[None, None, None]]
_ExcInfoType = None | bool | _SysExcInfoType
_ArgsType = Union[tuple[Any, ...], Mapping[str, Any]]
_FilterType = Filter | Callable[[LogRecord], int]

View File

@@ -1,9 +1,8 @@
import sys
from typing import Optional
if sys.platform == "win32":
_SequenceType = list[tuple[str, Optional[str], int]]
_SequenceType = list[tuple[str, str | None, int]]
AdminExecuteSequence: _SequenceType
AdminUISequence: _SequenceType

View File

@@ -1,4 +1,4 @@
from typing import Optional, Text
from typing import Text
class NetrcParseError(Exception):
filename: str | None
@@ -7,7 +7,7 @@ class NetrcParseError(Exception):
def __init__(self, msg: str, filename: Text | 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]

View File

@@ -16,7 +16,6 @@ from typing import (
Sequence,
Text,
TypeVar,
Union,
overload,
)
@@ -269,7 +268,7 @@ def execlpe(file: Text, __arg0: bytes | Text, *args: Any) -> NoReturn: ...
# The docs say `args: tuple or list of strings`
# The implementation enforces tuple or list so we can't use Sequence.
_ExecVArgs = Union[tuple[Union[bytes, Text], ...], list[bytes], list[Text], list[Union[bytes, Text]]]
_ExecVArgs = tuple[bytes | Text, ...] | list[bytes] | list[Text] | list[bytes | Text]
def execv(path: Text, args: _ExecVArgs) -> NoReturn: ...
def execve(path: Text, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...

View File

@@ -1,4 +1,4 @@
from typing import IO, Any, Callable, Iterator, Optional, Union
from typing import IO, Any, Callable, Iterator, Union
HIGHEST_PROTOCOL: int
bytes_types: tuple[type[Any], ...] # undocumented
@@ -16,8 +16,8 @@ _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]]],
tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None],
tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None],
]
class Pickler:

View File

@@ -1,12 +1,12 @@
from _typeshed import SupportsRead
from typing import IO, Any, Callable, Iterable, Iterator, TypeVar, Union
from typing import IO, Any, Callable, Iterable, Iterator, TypeVar
Loader = Any
MetaPathFinder = Any
PathEntryFinder = Any
_PathT = TypeVar("_PathT", bound=Iterable[str])
_ModuleInfoLike = tuple[Union[MetaPathFinder, PathEntryFinder], str, bool]
_ModuleInfoLike = tuple[MetaPathFinder | PathEntryFinder, str, bool]
def extend_path(path: _PathT, name: str) -> _PathT: ...

View File

@@ -1,7 +1,7 @@
import pyexpat.errors as errors
import pyexpat.model as model
from _typeshed import SupportsRead
from typing import Any, Callable, Optional, Text
from typing import Any, Callable, Text
EXPAT_VERSION: str # undocumented
version_info: tuple[int, int, int] # undocumented
@@ -19,7 +19,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, ...]]
class XMLParserType(object):
def Parse(self, __data: Text | bytes, __isfinal: bool = ...) -> int: ...

View File

@@ -1,6 +1,6 @@
from typing import Text, Union
from typing import Text
_SndHeaders = tuple[str, int, int, int, Union[int, str]]
_SndHeaders = tuple[str, int, int, int, int | str]
def what(filename: Text) -> _SndHeaders | None: ...
def whathdr(filename: Text) -> _SndHeaders | None: ...

View File

@@ -1,5 +1,5 @@
import sys
from typing import Any, BinaryIO, Iterable, Text, Union, overload
from typing import Any, BinaryIO, Iterable, Text, overload
# ----- Constants -----
# Some socket families are listed in the "Socket families" section of the docs,
@@ -373,7 +373,7 @@ class timeout(error):
# 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

View File

@@ -1,4 +1,4 @@
from typing import Any, Iterable, Match, Optional, Pattern as _Pattern
from typing import Any, Iterable, Match, Pattern as _Pattern
SPECIAL_CHARS: str
REPEAT_CHARS: str
@@ -21,7 +21,7 @@ class Pattern:
def closegroup(self, gid: int) -> None: ...
def checkgroup(self, gid: int) -> bool: ...
_OpSubpatternType = tuple[Optional[int], int, int, SubPattern]
_OpSubpatternType = tuple[int | None, int, int, SubPattern]
_OpGroupRefExistsType = tuple[int, SubPattern, SubPattern]
_OpInType = list[tuple[str, int]]
_OpBranchType = tuple[None, list[SubPattern]]
@@ -56,7 +56,7 @@ def isdigit(char: str) -> bool: ...
def isname(name: str) -> bool: ...
def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ...
_Template = tuple[list[tuple[int, int]], list[Optional[int]]]
_Template = tuple[list[tuple[int, int]], list[int | None]]
def parse_template(source: str, pattern: _Pattern[Any]) -> _Template: ...
def expand_template(template: _Template, match: Match[Any]) -> str: ...

View File

@@ -1,12 +1,12 @@
import types
from _typeshed import StrPath
from typing import Any, Callable, Mapping, Optional, Sequence, TypeVar
from typing import Any, Callable, Mapping, Sequence, TypeVar
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__(

View File

@@ -1,7 +1,7 @@
from types import FrameType, TracebackType
from typing import IO, Optional
from typing import IO
_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: ...
def print_exception(

View File

@@ -1,7 +1,7 @@
import sys
from _typeshed import ReadableBuffer, WriteableBuffer
from collections.abc import Iterable
from typing import Any, SupportsInt, Union, overload
from typing import Any, SupportsInt, overload
if sys.version_info >= (3, 8):
from typing import SupportsIndex
@@ -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

View File

@@ -2,7 +2,7 @@ import sys
from _typeshed import structseq
from threading import Thread
from types import TracebackType
from typing import Any, Callable, NoReturn, Optional
from typing import Any, Callable, NoReturn
from typing_extensions import final
error = RuntimeError
@@ -33,9 +33,7 @@ TIMEOUT_MAX: float
if sys.version_info >= (3, 8):
def get_native_id() -> int: ... # only available on some platforms
@final
class _ExceptHookArgs(
structseq[Any], tuple[type[BaseException], Optional[BaseException], Optional[TracebackType], Optional[Thread]]
):
class _ExceptHookArgs(structseq[Any], tuple[type[BaseException], BaseException | None, TracebackType | None, Thread | None]):
@property
def exc_type(self) -> type[BaseException]: ...
@property

View File

@@ -1,7 +1,7 @@
import datetime
import sys
from time import struct_time
from typing import Any, Iterable, Optional, Sequence
from typing import Any, Iterable, Sequence
from typing_extensions import Literal
__all__ = [
@@ -31,7 +31,7 @@ __all__ = [
"weekheader",
]
_LocaleType = tuple[Optional[str], Optional[str]]
_LocaleType = tuple[str | None, str | None]
class IllegalMonthError(ValueError):
def __init__(self, month: int) -> None: ...

View File

@@ -1,8 +1,8 @@
from _typeshed import StrOrBytesPath
from types import FrameType, TracebackType
from typing import IO, Any, Callable, Optional
from typing import IO, Any, Callable
_ExcInfo = tuple[Optional[type[BaseException]], Optional[BaseException], Optional[TracebackType]]
_ExcInfo = tuple[type[BaseException] | None, BaseException | None, TracebackType | None]
__UNDEF__: object # undocumented sentinel

View File

@@ -1,7 +1,7 @@
from typing import Any, Callable, Hashable, Optional, SupportsInt, TypeVar, Union
from typing import Any, Callable, Hashable, SupportsInt, TypeVar, Union
_T = TypeVar("_T")
_Reduce = Union[tuple[Callable[..., _T], tuple[Any, ...]], tuple[Callable[..., _T], tuple[Any, ...], Optional[Any]]]
_Reduce = Union[tuple[Callable[..., _T], tuple[Any, ...]], tuple[Callable[..., _T], tuple[Any, ...], Any | None]]
__all__ = ["pickle", "constructor", "add_extension", "remove_extension", "clear_extension_cache"]

View File

@@ -1,20 +1,7 @@
import sys
from _typeshed import ReadableBuffer, Self, WriteableBuffer
from abc import abstractmethod
from typing import (
Any,
Callable,
ClassVar,
Generic,
Iterable,
Iterator,
Mapping,
Optional,
Sequence,
TypeVar,
Union as _UnionT,
overload,
)
from typing import Any, Callable, ClassVar, Generic, Iterable, Iterator, Mapping, Sequence, TypeVar, Union as _UnionT, overload
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -97,7 +84,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):

View File

@@ -1,6 +1,6 @@
from typing import Any, Callable, Optional, Union
from typing import Any, Callable, Union
_Macro = Union[tuple[str], tuple[str, Optional[str]]]
_Macro = Union[tuple[str], tuple[str, str | None]]
def gen_lib_options(
compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str]

View File

@@ -1,6 +1,6 @@
from typing import Any, Iterable, Mapping, Optional, overload
from typing import Any, Iterable, Mapping, overload
_Option = tuple[str, Optional[str], str]
_Option = tuple[str, str | None, str]
_GR = tuple[list[str], OptionDummy]
def fancy_getopt(

View File

@@ -4,7 +4,7 @@ from email.errors import MessageDefect
from email.policy import Policy
# using a type alias ("_HeaderType = Any") breaks mypy, who knows why
from typing import Any, Any as _HeaderType, Generator, Iterator, Optional, Sequence, TypeVar, Union
from typing import Any, Any as _HeaderType, Generator, Iterator, Sequence, TypeVar, Union
__all__ = ["Message", "EmailMessage"]
@@ -12,8 +12,8 @@ _T = TypeVar("_T")
_PayloadType = list[Message] | str | bytes
_CharsetType = Charset | str | None
_ParamsType = Union[str, None, tuple[str, Optional[str], str]]
_ParamType = Union[str, tuple[Optional[str], Optional[str], str]]
_ParamsType = Union[str, None, tuple[str, str | None, str]]
_ParamType = Union[str, tuple[str | None, str | None, str]]
class Message:
policy: Policy # undocumented

View File

@@ -1,10 +1,10 @@
from email.mime.nonmultipart import MIMENonMultipart
from email.policy import Policy
from typing import Callable, Optional, Union
from typing import Callable, Union
__all__ = ["MIMEApplication"]
_ParamsType = Union[str, None, tuple[str, Optional[str], str]]
_ParamsType = Union[str, None, tuple[str, str | None, str]]
class MIMEApplication(MIMENonMultipart):
def __init__(

View File

@@ -1,10 +1,10 @@
from email.mime.nonmultipart import MIMENonMultipart
from email.policy import Policy
from typing import Callable, Optional, Union
from typing import Callable, Union
__all__ = ["MIMEAudio"]
_ParamsType = Union[str, None, tuple[str, Optional[str], str]]
_ParamsType = Union[str, None, tuple[str, str | None, str]]
class MIMEAudio(MIMENonMultipart):
def __init__(

View File

@@ -1,10 +1,10 @@
import email.message
from email.policy import Policy
from typing import Optional, Union
from typing import Union
__all__ = ["MIMEBase"]
_ParamsType = Union[str, None, tuple[str, Optional[str], str]]
_ParamsType = Union[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: ...

View File

@@ -1,10 +1,10 @@
from email.mime.nonmultipart import MIMENonMultipart
from email.policy import Policy
from typing import Callable, Optional, Union
from typing import Callable, Union
__all__ = ["MIMEImage"]
_ParamsType = Union[str, None, tuple[str, Optional[str], str]]
_ParamsType = Union[str, None, tuple[str, str | None, str]]
class MIMEImage(MIMENonMultipart):
def __init__(

View File

@@ -1,11 +1,11 @@
from email.message import Message
from email.mime.base import MIMEBase
from email.policy import Policy
from typing import Optional, Sequence, Union
from typing import Sequence, Union
__all__ = ["MIMEMultipart"]
_ParamsType = Union[str, None, tuple[str, Optional[str], str]]
_ParamsType = Union[str, None, tuple[str, str | None, str]]
class MIMEMultipart(MIMEBase):
def __init__(

View File

@@ -1,7 +1,7 @@
import datetime
import sys
from email.charset import Charset
from typing import Optional, Union, overload
from typing import Union, overload
__all__ = [
"collapse_rfc2231_value",
@@ -21,8 +21,8 @@ __all__ = [
"unquote",
]
_ParamType = Union[str, tuple[Optional[str], Optional[str], str]]
_PDTZ = tuple[int, int, int, int, int, int, int, int, int, Optional[int]]
_ParamType = Union[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: ...
def unquote(str: str) -> str: ...

View File

@@ -1,11 +1,11 @@
import sys
from _typeshed import structseq
from typing import Any, Optional
from typing import Any
from typing_extensions import final
if sys.platform != "win32":
@final
class struct_group(structseq[Any], tuple[str, Optional[str], int, list[str]]):
class struct_group(structseq[Any], tuple[str, str | None, int, list[str]]):
@property
def gr_name(self) -> str: ...
@property

View File

@@ -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, Pattern, Union
from typing import IO, Any, Callable, Pattern
from typing_extensions import Literal
__all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate", "IMAP4_SSL"]
@@ -14,7 +14,7 @@ __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags"
# 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"

View File

@@ -1,7 +1,6 @@
from _typeshed import Self, StrPath
from typing import Optional
_Label = tuple[int, Optional[str]]
_Label = tuple[int, str | None]
_DFA = list[list[tuple[int, int]]]
_DFAS = tuple[_DFA, dict[int, int]]

View File

@@ -1,11 +1,11 @@
from _typeshed import Self
from lib2to3.pgen2.grammar import Grammar
from typing import Any, Callable, Iterator, Optional
from typing import Any, Callable, Iterator
_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

View File

@@ -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, TypeVar, Union, overload
from typing import Any, ClassVar, Generic, Pattern, TextIO, TypeVar, Union, overload
from typing_extensions import Literal
__all__ = [
@@ -54,9 +54,9 @@ __all__ = [
"raiseExceptions",
]
_SysExcInfoType = Union[tuple[type[BaseException], BaseException, Optional[TracebackType]], tuple[None, None, None]]
_SysExcInfoType = Union[tuple[type[BaseException], BaseException, TracebackType | None], tuple[None, None, None]]
_ExcInfoType = None | bool | _SysExcInfoType | BaseException
_ArgsType = Union[tuple[object, ...], Mapping[str, object]]
_ArgsType = tuple[object, ...] | Mapping[str, object]
_FilterType = Filter | Callable[[LogRecord], int]
_Level = int | str
_FormatStyle = Literal["%", "{", "$"]

View File

@@ -1,9 +1,8 @@
import sys
from typing import Optional
if sys.platform == "win32":
_SequenceType = list[tuple[str, Optional[str], int]]
_SequenceType = list[tuple[str, str | None, int]]
AdminExecuteSequence: _SequenceType
AdminUISequence: _SequenceType

View File

@@ -1,5 +1,4 @@
from _typeshed import StrOrBytesPath
from typing import Optional
__all__ = ["netrc", "NetrcParseError"]
@@ -10,7 +9,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]

View File

@@ -1,5 +1,5 @@
import sys
from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Optional, Protocol, Union
from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Protocol, Union
from typing_extensions import final
if sys.version_info >= (3, 8):
@@ -227,8 +227,8 @@ _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]]],
tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None],
tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None],
]
class Pickler:

View File

@@ -1,7 +1,7 @@
import pyexpat.errors as errors
import pyexpat.model as model
from _typeshed import SupportsRead
from typing import Any, Callable, Optional
from typing import Any, Callable
from typing_extensions import final
EXPAT_VERSION: str # undocumented
@@ -20,7 +20,7 @@ XML_PARAM_ENTITY_PARSING_NEVER: int
XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE: int
XML_PARAM_ENTITY_PARSING_ALWAYS: int
_Model = tuple[int, int, Optional[str], tuple[Any, ...]]
_Model = tuple[int, int, str | None, tuple[Any, ...]]
@final
class XMLParserType:

View File

@@ -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, Pattern, Protocol, Sequence, Union, overload
from typing import Any, Pattern, Protocol, Sequence, overload
if sys.version_info >= (3, 7):
__all__ = [
@@ -43,7 +43,7 @@ else:
_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

View File

@@ -1,7 +1,7 @@
import sys
from sre_constants import *
from sre_constants import _NamedIntConstant as _NIC, error as _Error
from typing import Any, Iterable, Match, Optional, Pattern as _Pattern, overload
from typing import Any, Iterable, Match, Pattern as _Pattern, overload
SPECIAL_CHARS: str
REPEAT_CHARS: str
@@ -37,7 +37,7 @@ 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]]
@@ -87,8 +87,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

View File

@@ -9,7 +9,7 @@ _PCTRTT = tuple[tuple[str, str], ...]
_PCTRTTT = tuple[_PCTRTT, ...]
_PeerCertRetDictType = dict[str, str | _PCTRTTT | _PCTRTT]
_PeerCertRetType = _PeerCertRetDictType | bytes | None
_EnumRetType = list[tuple[bytes, str, Union[set[str], bool]]]
_EnumRetType = list[tuple[bytes, str, set[str] | bool]]
_PasswordType = Union[Callable[[], str | bytes], str, bytes]
_SrvnmeCbType = Callable[[SSLSocket | SSLObject, str | None, SSLSocket], int | None]

View File

@@ -1,7 +1,7 @@
import _tkinter
import sys
import tkinter
from typing import Any, Union, overload
from typing import Any, overload
from typing_extensions import Literal, TypedDict
if sys.version_info >= (3, 9):
@@ -12,17 +12,13 @@ ROMAN: Literal["roman"]
BOLD: Literal["bold"]
ITALIC: Literal["italic"]
_FontDescription = Union[
# "Helvetica 12"
str,
# A font object constructed in Python
Font,
# ("Helvetica", 12, BOLD)
list[Any],
tuple[Any, ...],
# A font object constructed in Tcl
_tkinter.Tcl_Obj,
]
_FontDescription = (
str # "Helvetica 12"
| Font # A font object constructed in Python
| list[Any] # ("Helvetica", 12, BOLD)
| tuple[Any, ...]
| _tkinter.Tcl_Obj # A font object constructed in Tcl
)
class _FontDict(TypedDict):
family: str

View File

@@ -1,7 +1,7 @@
import sys
import types
from _typeshed import StrPath
from typing import Any, Callable, Mapping, Optional, Sequence, TypeVar
from typing import Any, Callable, Mapping, Sequence, TypeVar
from typing_extensions import ParamSpec
__all__ = ["Trace", "CoverageResults"]
@@ -9,7 +9,7 @@ __all__ = ["Trace", "CoverageResults"]
_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__(

View File

@@ -1,6 +1,6 @@
import sys
from _tracemalloc import *
from typing import Any, Optional, Sequence, Union, overload
from typing import Any, Sequence, Union, overload
from typing_extensions import SupportsIndex
def get_object_traceback(obj: object) -> Traceback | None: ...
@@ -61,7 +61,7 @@ class Frame:
def __le__(self, other: Frame, NotImplemented: Any = ...) -> bool: ...
if sys.version_info >= (3, 9):
_TraceTupleT = Union[tuple[int, int, Sequence[_FrameTupleT], Optional[int]], tuple[int, int, Sequence[_FrameTupleT]]]
_TraceTupleT = Union[tuple[int, int, Sequence[_FrameTupleT], int | None], tuple[int, int, Sequence[_FrameTupleT]]]
else:
_TraceTupleT = tuple[int, int, Sequence[_FrameTupleT]]

View File

@@ -3,11 +3,11 @@ import pydoc
import socketserver
import sys
from datetime import datetime
from typing import Any, Callable, Iterable, Mapping, Pattern, Protocol, Union
from typing import Any, Callable, Iterable, Mapping, Pattern, Protocol
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):

View File

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