mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
Use PEP 604 syntax wherever possible, part II (#7514)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
@@ -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: ...
|
||||
|
||||
@@ -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"]
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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__(
|
||||
|
||||
@@ -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] = ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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]]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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__(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user