Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PEP 604 syntax wherever possible #7493

Merged
merged 14 commits into from
Mar 16, 2022
2 changes: 1 addition & 1 deletion stdlib/@python2/SocketServer.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions stdlib/@python2/_codecs.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/_curses.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/_dummy_threading.pyi
Original file line number Diff line number Diff line change
@@ -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]

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

Expand Down
12 changes: 6 additions & 6 deletions stdlib/@python2/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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: ...
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stdlib/@python2/_typeshed/wsgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/_winreg.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/aifc.pyi
Original file line number Diff line number Diff line change
@@ -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): ...
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/argparse.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/array.pyi
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion stdlib/@python2/asyncore.pyi
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
6 changes: 3 additions & 3 deletions stdlib/@python2/base64.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/binhex.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import IO, Any, Union
from typing import IO, Any

class Error(Exception): ...

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

Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/bz2.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/cmath.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/@python2/codecs.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/contextlib.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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")
_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: ...
Expand Down
34 changes: 17 additions & 17 deletions stdlib/@python2/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ...

Expand All @@ -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
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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":
Expand All @@ -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]): ...
Expand All @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/datetime.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions stdlib/@python2/dbm/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/@python2/dbm/dumb.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading