Skip to content

Commit

Permalink
Use PEP 604 syntax wherever possible, part II (#7514)
Browse files Browse the repository at this point in the history
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
  • Loading branch information
AlexWaygood and JelleZijlstra authored Mar 19, 2022
1 parent 340c6c9 commit 1acc8f3
Show file tree
Hide file tree
Showing 55 changed files with 116 additions and 141 deletions.
4 changes: 2 additions & 2 deletions stdlib/@python2/calendar.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/copy_reg.pyi
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/copyreg.pyi
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
3 changes: 1 addition & 2 deletions stdlib/@python2/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ from typing import (
Iterable,
Iterator,
Mapping,
Optional,
Sequence,
Text,
TypeVar,
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/distutils/ccompiler.pyi
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/distutils/fancy_getopt.pyi
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/email/mime/application.pyi
Original file line number Diff line number Diff line change
@@ -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__(
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/imaplib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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] = ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/inspect.pyi
Original file line number Diff line number Diff line change
@@ -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): ...
Expand Down Expand Up @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/lib2to3/pgen2/grammar.pyi
Original file line number Diff line number Diff line change
@@ -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]]

Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/lib2to3/pytree.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/logging/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions stdlib/@python2/msilib/sequence.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/netrc.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Text
from typing import Text

class NetrcParseError(Exception):
filename: str | None
Expand All @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions stdlib/@python2/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ from typing import (
Sequence,
Text,
TypeVar,
Union,
overload,
)

Expand Down Expand Up @@ -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: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/@python2/pickle.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/pkgutil.pyi
Original file line number Diff line number Diff line change
@@ -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: ...

Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/pyexpat/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/sndhdr.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
4 changes: 2 additions & 2 deletions stdlib/@python2/socket.pyi
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions stdlib/@python2/sre_parse.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]]
Expand Down Expand Up @@ -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: ...
4 changes: 2 additions & 2 deletions stdlib/@python2/trace.pyi
Original file line number Diff line number Diff line change
@@ -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__(
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/traceback.pyi
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_socket.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
6 changes: 2 additions & 4 deletions stdlib/_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions stdlib/calendar.pyi
Original file line number Diff line number Diff line change
@@ -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__ = [
Expand Down Expand Up @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/cgitb.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions stdlib/copyreg.pyi
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
Loading

0 comments on commit 1acc8f3

Please sign in to comment.