Skip to content

Commit 3ab250e

Browse files
authored
Use PEP 604 syntax wherever possible (#7493)
1 parent 15e21a8 commit 3ab250e

File tree

174 files changed

+471
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+471
-489
lines changed

stdlib/@python2/SocketServer.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from socket import SocketType
3-
from typing import Any, BinaryIO, Callable, ClassVar, Text, Union
3+
from typing import Any, BinaryIO, Callable, ClassVar, Text
44

55
class BaseServer:
66
address_family: int

stdlib/@python2/_codecs.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import codecs
22
import sys
3-
from typing import Any, Callable, Text, Union
3+
from typing import Any, Callable, Text
44

55
# For convenience:
66
_Handler = Callable[[Exception], tuple[Text, int]]
7-
_String = Union[bytes, str]
8-
_Errors = Union[str, Text, None]
9-
_Decodable = Union[bytes, Text]
10-
_Encodable = Union[bytes, Text]
7+
_String = bytes | str
8+
_Errors = str | Text | None
9+
_Decodable = bytes | Text
10+
_Encodable = bytes | Text
1111

1212
# This type is not exposed; it is defined in unicodeobject.c
1313
class _EncodingMap(object):
1414
def size(self) -> int: ...
1515

16-
_MapT = Union[dict[int, int], _EncodingMap]
16+
_MapT = dict[int, int] | _EncodingMap
1717

1818
def register(__search_function: Callable[[str], Any]) -> None: ...
1919
def register_error(__errors: str | Text, __handler: _Handler) -> None: ...

stdlib/@python2/_curses.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import IO, Any, BinaryIO, Union, overload
1+
from typing import IO, Any, BinaryIO, overload
22

3-
_chtype = Union[str, bytes, int]
3+
_chtype = str | bytes | int
44

55
# ACS codes are only initialized after initscr is called
66
ACS_BBSS: int

stdlib/@python2/_dummy_threading.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from types import FrameType, TracebackType
2-
from typing import Any, Callable, Iterable, Mapping, Optional, Text
2+
from typing import Any, Callable, Iterable, Mapping, Text
33

44
# TODO recursive type
5-
_TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]]
5+
_TF = Callable[[FrameType, str, Any], Callable[..., Any] | None]
66

77
_PF = Callable[[FrameType, str, Any], None]
88

stdlib/@python2/_io.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from _typeshed import Self
22
from mmap import mmap
3-
from typing import IO, Any, BinaryIO, Iterable, Text, TextIO, Union
3+
from typing import IO, Any, BinaryIO, Iterable, Text, TextIO
44

5-
_bytearray_like = Union[bytearray, mmap]
5+
_bytearray_like = bytearray | mmap
66

77
DEFAULT_BUFFER_SIZE: int
88

stdlib/@python2/_typeshed/__init__.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import array
1616
import mmap
17-
from typing import Any, Container, Iterable, Protocol, Text, TypeVar, Union
17+
from typing import Any, Container, Iterable, Protocol, Text, TypeVar
1818
from typing_extensions import Literal, final
1919

2020
_KT = TypeVar("_KT")
@@ -104,7 +104,7 @@ OpenTextModeUpdating = Literal[
104104
]
105105
OpenTextModeWriting = Literal["w", "wt", "tw", "a", "at", "ta", "x", "xt", "tx"]
106106
OpenTextModeReading = Literal["r", "rt", "tr", "U", "rU", "Ur", "rtU", "rUt", "Urt", "trU", "tUr", "Utr"]
107-
OpenTextMode = Union[OpenTextModeUpdating, OpenTextModeWriting, OpenTextModeReading]
107+
OpenTextMode = OpenTextModeUpdating | OpenTextModeWriting | OpenTextModeReading
108108
OpenBinaryModeUpdating = Literal[
109109
"rb+",
110110
"r+b",
@@ -133,13 +133,13 @@ OpenBinaryModeUpdating = Literal[
133133
]
134134
OpenBinaryModeWriting = Literal["wb", "bw", "ab", "ba", "xb", "bx"]
135135
OpenBinaryModeReading = Literal["rb", "br", "rbU", "rUb", "Urb", "brU", "bUr", "Ubr"]
136-
OpenBinaryMode = Union[OpenBinaryModeUpdating, OpenBinaryModeReading, OpenBinaryModeWriting]
136+
OpenBinaryMode = OpenBinaryModeUpdating | OpenBinaryModeReading | OpenBinaryModeWriting
137137

138138
class HasFileno(Protocol):
139139
def fileno(self) -> int: ...
140140

141141
FileDescriptor = int
142-
FileDescriptorLike = Union[int, HasFileno]
142+
FileDescriptorLike = int | HasFileno
143143

144144
class SupportsRead(Protocol[_T_co]):
145145
def read(self, __length: int = ...) -> _T_co: ...
@@ -153,8 +153,8 @@ class SupportsNoArgReadline(Protocol[_T_co]):
153153
class SupportsWrite(Protocol[_T_contra]):
154154
def write(self, __s: _T_contra) -> Any: ...
155155

156-
ReadableBuffer = Union[bytes, bytearray, memoryview, array.array[Any], mmap.mmap, buffer]
157-
WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, buffer]
156+
ReadableBuffer = bytes | bytearray | memoryview | array.array[Any] | mmap.mmap | buffer
157+
WriteableBuffer = bytearray | memoryview | array.array[Any] | mmap.mmap | buffer
158158

159159
# Used by type checkers for checks involving None (does not exist at runtime)
160160
@final

stdlib/@python2/_typeshed/wsgi.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# file. They are provided for type checking purposes.
55

66
from sys import _OptExcInfo
7-
from typing import Any, Callable, Iterable, Optional, Protocol, Text
7+
from typing import Any, Callable, Iterable, Protocol, Text
88

99
class StartResponse(Protocol):
1010
def __call__(

stdlib/@python2/_winreg.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import sys
22
from _typeshed import Self
33
from types import TracebackType
4-
from typing import Any, Union
4+
from typing import Any
55

66
if sys.platform == "win32":
7-
_KeyType = Union[HKEYType, int]
7+
_KeyType = HKEYType | int
88
def CloseKey(__hkey: _KeyType) -> None: ...
99
def ConnectRegistry(__computer_name: str | None, __key: _KeyType) -> HKEYType: ...
1010
def CreateKey(__key: _KeyType, __sub_key: str | None) -> HKEYType: ...

stdlib/@python2/aifc.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import IO, Any, NamedTuple, Text, Union, overload
1+
from typing import IO, Any, NamedTuple, Text, overload
22
from typing_extensions import Literal
33

44
class Error(Exception): ...
@@ -11,7 +11,7 @@ class _aifc_params(NamedTuple):
1111
comptype: bytes
1212
compname: bytes
1313

14-
_File = Union[Text, IO[bytes]]
14+
_File = Text | IO[bytes]
1515
_Marker = tuple[int, int, bytes]
1616

1717
class Aifc_read:

stdlib/@python2/argparse.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import IO, Any, Callable, Generator, Iterable, NoReturn, Pattern, Protocol, Sequence, Text, TypeVar, Union, overload
1+
from typing import IO, Any, Callable, Generator, Iterable, NoReturn, Pattern, Protocol, Sequence, Text, TypeVar, overload
22

33
_T = TypeVar("_T")
44
_ActionT = TypeVar("_ActionT", bound=Action)
55
_N = TypeVar("_N")
66

7-
_Text = Union[str, unicode]
7+
_Text = str | unicode
88

99
ONE_OR_MORE: str
1010
OPTIONAL: str

stdlib/@python2/array.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from _typeshed import Self
2-
from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, Text, TypeVar, Union, overload
2+
from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, Text, TypeVar, overload
33
from typing_extensions import Literal
44

55
_IntTypeCode = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
66
_FloatTypeCode = Literal["f", "d"]
77
_UnicodeTypeCode = Literal["u"]
8-
_TypeCode = Union[_IntTypeCode, _FloatTypeCode, _UnicodeTypeCode]
8+
_TypeCode = _IntTypeCode | _FloatTypeCode | _UnicodeTypeCode
99

1010
_T = TypeVar("_T", int, float, Text)
1111

stdlib/@python2/asyncore.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from _typeshed import FileDescriptorLike
33
from socket import SocketType
4-
from typing import Any, Optional, overload
4+
from typing import Any, overload
55

66
# cyclic dependence with asynchat
77
_maptype = dict[int, Any]

stdlib/@python2/base64.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import IO, Union
1+
from typing import IO
22

3-
_encodable = Union[bytes, unicode]
4-
_decodable = Union[bytes, unicode]
3+
_encodable = bytes | unicode
4+
_decodable = bytes | unicode
55

66
def b64encode(s: _encodable, altchars: bytes | None = ...) -> bytes: ...
77
def b64decode(s: _decodable, altchars: bytes | None = ..., validate: bool = ...) -> bytes: ...

stdlib/@python2/binhex.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import IO, Any, Union
1+
from typing import IO, Any
22

33
class Error(Exception): ...
44

@@ -13,7 +13,7 @@ class FInfo:
1313
Flags: int
1414

1515
_FileInfoTuple = tuple[str, FInfo, int, int]
16-
_FileHandleUnion = Union[str, IO[bytes]]
16+
_FileHandleUnion = str | IO[bytes]
1717

1818
def getfileinfo(name: str) -> _FileInfoTuple: ...
1919

stdlib/@python2/bz2.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import io
22
from _typeshed import ReadableBuffer, Self, WriteableBuffer
3-
from typing import IO, Any, Iterable, Text, Union
3+
from typing import IO, Any, Iterable, Text
44
from typing_extensions import SupportsIndex
55

6-
_PathOrFile = Union[Text, IO[bytes]]
6+
_PathOrFile = Text | IO[bytes]
77

88
def compress(data: bytes, compresslevel: int = ...) -> bytes: ...
99
def decompress(data: bytes) -> bytes: ...

stdlib/@python2/cmath.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from typing import SupportsComplex, SupportsFloat, Union
1+
from typing import SupportsComplex, SupportsFloat
22

33
e: float
44
pi: float
5-
_C = Union[SupportsFloat, SupportsComplex, complex]
5+
_C = SupportsFloat | SupportsComplex | complex
66

77
def acos(__z: _C) -> complex: ...
88
def acosh(__z: _C) -> complex: ...

stdlib/@python2/codecs.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import types
22
from _typeshed import Self
33
from abc import abstractmethod
4-
from typing import IO, Any, BinaryIO, Callable, Generator, Iterable, Iterator, Protocol, Text, TextIO, Union, overload
4+
from typing import IO, Any, BinaryIO, Callable, Generator, Iterable, Iterator, Protocol, Text, TextIO, overload
55
from typing_extensions import Literal
66

77
# TODO: this only satisfies the most common interface, where

stdlib/@python2/contextlib.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from types import TracebackType
2-
from typing import IO, Any, Callable, ContextManager, Iterable, Iterator, Optional, Protocol, TypeVar
2+
from typing import IO, Any, Callable, ContextManager, Iterable, Iterator, Protocol, TypeVar
33
from typing_extensions import ParamSpec
44

55
_T = TypeVar("_T")
66
_T_co = TypeVar("_T_co", covariant=True)
77
_F = TypeVar("_F", bound=Callable[..., Any])
88
_P = ParamSpec("_P")
99

10-
_ExitFunc = Callable[[Optional[type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
10+
_ExitFunc = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], bool]
1111

1212
class GeneratorContextManager(ContextManager[_T_co]):
1313
def __call__(self, func: _F) -> _F: ...

stdlib/@python2/ctypes/__init__.pyi

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ pythonapi: PyDLL
5959
# Anything that implements the read-write buffer interface.
6060
# The buffer interface is defined purely on the C level, so we cannot define a normal Protocol
6161
# for it. Instead we have to list the most common stdlib buffer classes in a Union.
62-
_WritableBuffer = _UnionT[bytearray, memoryview, array[Any], _CData]
62+
_WritableBuffer = bytearray | memoryview | array[Any] | _CData
6363
# Same as _WritableBuffer, but also includes read-only buffer types (like bytes).
64-
_ReadOnlyBuffer = _UnionT[_WritableBuffer, bytes]
64+
_ReadOnlyBuffer = _WritableBuffer | bytes
6565

6666
class _CDataMeta(type):
6767
# By default mypy complains about the following two methods, because strictly speaking cls
@@ -81,7 +81,7 @@ class _CData(metaclass=_CDataMeta):
8181
@classmethod
8282
def from_address(cls: type[Self], address: int) -> Self: ...
8383
@classmethod
84-
def from_param(cls: type[_CT], obj: Any) -> _UnionT[_CT, _CArgObject]: ...
84+
def from_param(cls: type[_CT], obj: Any) -> _CT | _CArgObject: ...
8585
@classmethod
8686
def in_dll(cls: type[Self], library: CDLL, name: str) -> Self: ...
8787

@@ -92,7 +92,7 @@ _ECT = Callable[[Optional[type[_CData]], _FuncPointer, tuple[_CData, ...]], _CDa
9292
_PF = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]]
9393

9494
class _FuncPointer(_PointerLike, _CData):
95-
restype: _UnionT[type[_CData], Callable[[int], Any], None] = ...
95+
restype: type[_CData] | Callable[[int], Any] | None = ...
9696
argtypes: Sequence[type[_CData]] = ...
9797
errcheck: _ECT = ...
9898
@overload
@@ -125,25 +125,25 @@ class _CArgObject: ...
125125

126126
# Any type that can be implicitly converted to c_void_p when passed as a C function argument.
127127
# (bytes is not included here, see below.)
128-
_CVoidPLike = _UnionT[_PointerLike, Array[Any], _CArgObject, int]
128+
_CVoidPLike = _PointerLike | Array[Any] | _CArgObject | int
129129
# Same as above, but including types known to be read-only (i. e. bytes).
130130
# This distinction is not strictly necessary (ctypes doesn't differentiate between const
131131
# and non-const pointers), but it catches errors like memmove(b'foo', buf, 4)
132132
# when memmove(buf, b'foo', 4) was intended.
133-
_CVoidConstPLike = _UnionT[_CVoidPLike, bytes]
133+
_CVoidConstPLike = _CVoidPLike | bytes
134134

135135
def addressof(obj: _CData) -> int: ...
136-
def alignment(obj_or_type: _UnionT[_CData, type[_CData]]) -> int: ...
136+
def alignment(obj_or_type: _CData | type[_CData]) -> int: ...
137137
def byref(obj: _CData, offset: int = ...) -> _CArgObject: ...
138138

139139
_CastT = TypeVar("_CastT", bound=_CanCastTo)
140140

141-
def cast(obj: _UnionT[_CData, _CArgObject, int], typ: type[_CastT]) -> _CastT: ...
142-
def create_string_buffer(init: _UnionT[int, bytes], size: int | None = ...) -> Array[c_char]: ...
141+
def cast(obj: _CData | _CArgObject | int, typ: type[_CastT]) -> _CastT: ...
142+
def create_string_buffer(init: int | bytes, size: int | None = ...) -> Array[c_char]: ...
143143

144144
c_buffer = create_string_buffer
145145

146-
def create_unicode_buffer(init: _UnionT[int, Text], size: int | None = ...) -> Array[c_wchar]: ...
146+
def create_unicode_buffer(init: int | Text, size: int | None = ...) -> Array[c_wchar]: ...
147147

148148
if sys.platform == "win32":
149149
def DllCanUnloadNow() -> int: ...
@@ -183,7 +183,7 @@ def set_errno(value: int) -> int: ...
183183
if sys.platform == "win32":
184184
def set_last_error(value: int) -> int: ...
185185

186-
def sizeof(obj_or_type: _UnionT[_CData, type[_CData]]) -> int: ...
186+
def sizeof(obj_or_type: _CData | type[_CData]) -> int: ...
187187
def string_at(address: _CVoidConstPLike, size: int = ...) -> bytes: ...
188188

189189
if sys.platform == "win32":
@@ -198,10 +198,10 @@ class _SimpleCData(Generic[_T], _CData):
198198
class c_byte(_SimpleCData[int]): ...
199199

200200
class c_char(_SimpleCData[bytes]):
201-
def __init__(self, value: _UnionT[int, bytes] = ...) -> None: ...
201+
def __init__(self, value: int | bytes = ...) -> None: ...
202202

203-
class c_char_p(_PointerLike, _SimpleCData[Optional[bytes]]):
204-
def __init__(self, value: _UnionT[int, bytes] | None = ...) -> None: ...
203+
class c_char_p(_PointerLike, _SimpleCData[bytes | None]):
204+
def __init__(self, value: int | bytes | None = ...) -> None: ...
205205

206206
class c_double(_SimpleCData[float]): ...
207207
class c_longdouble(_SimpleCData[float]): ...
@@ -225,11 +225,11 @@ class c_uint64(_SimpleCData[int]): ...
225225
class c_ulong(_SimpleCData[int]): ...
226226
class c_ulonglong(_SimpleCData[int]): ...
227227
class c_ushort(_SimpleCData[int]): ...
228-
class c_void_p(_PointerLike, _SimpleCData[Optional[int]]): ...
228+
class c_void_p(_PointerLike, _SimpleCData[int | None]): ...
229229
class c_wchar(_SimpleCData[Text]): ...
230230

231-
class c_wchar_p(_PointerLike, _SimpleCData[Optional[Text]]):
232-
def __init__(self, value: _UnionT[int, Text] | None = ...) -> None: ...
231+
class c_wchar_p(_PointerLike, _SimpleCData[Text | None]):
232+
def __init__(self, value: int | Text | None = ...) -> None: ...
233233

234234
class c_bool(_SimpleCData[bool]):
235235
def __init__(self, value: bool = ...) -> None: ...

stdlib/@python2/datetime.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from _typeshed import Self
22
from time import struct_time
3-
from typing import AnyStr, ClassVar, SupportsAbs, Union, overload
3+
from typing import AnyStr, ClassVar, SupportsAbs, overload
44

5-
_Text = Union[str, unicode]
5+
_Text = str | unicode
66

77
MINYEAR: int
88
MAXYEAR: int

stdlib/@python2/dbm/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from _typeshed import Self
22
from types import TracebackType
3-
from typing import Iterator, MutableMapping, Union
3+
from typing import Iterator, MutableMapping
44
from typing_extensions import Literal
55

6-
_KeyType = Union[str, bytes]
7-
_ValueType = Union[str, bytes]
6+
_KeyType = str | bytes
7+
_ValueType = str | bytes
88

99
class _Database(MutableMapping[_KeyType, bytes]):
1010
def close(self) -> None: ...

stdlib/@python2/dbm/dumb.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from _typeshed import Self
22
from types import TracebackType
3-
from typing import Iterator, MutableMapping, Union
3+
from typing import Iterator, MutableMapping
44

5-
_KeyType = Union[str, bytes]
6-
_ValueType = Union[str, bytes]
5+
_KeyType = str | bytes
6+
_ValueType = str | bytes
77

88
error = OSError
99

0 commit comments

Comments
 (0)