Skip to content

Commit 1acc8f3

Browse files
Use PEP 604 syntax wherever possible, part II (#7514)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 340c6c9 commit 1acc8f3

Some content is hidden

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

55 files changed

+116
-141
lines changed

stdlib/@python2/calendar.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import datetime
22
from time import struct_time
3-
from typing import Any, Iterable, Optional, Sequence
3+
from typing import Any, Iterable, Sequence
44

5-
_LocaleType = tuple[Optional[str], Optional[str]]
5+
_LocaleType = tuple[str | None, str | None]
66

77
class IllegalMonthError(ValueError):
88
def __init__(self, month: int) -> None: ...

stdlib/@python2/copy_reg.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Any, Callable, Hashable, Optional, SupportsInt, TypeVar, Union
1+
from typing import Any, Callable, Hashable, SupportsInt, TypeVar, Union
22

33
_TypeT = TypeVar("_TypeT", bound=type)
4-
_Reduce = Union[tuple[Callable[..., _TypeT], tuple[Any, ...]], tuple[Callable[..., _TypeT], tuple[Any, ...], Optional[Any]]]
4+
_Reduce = Union[tuple[Callable[..., _TypeT], tuple[Any, ...]], tuple[Callable[..., _TypeT], tuple[Any, ...], Any | None]]
55

66
__all__ = ["pickle", "constructor", "add_extension", "remove_extension", "clear_extension_cache"]
77

stdlib/@python2/copyreg.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Any, Callable, Hashable, Optional, SupportsInt, TypeVar, Union
1+
from typing import Any, Callable, Hashable, SupportsInt, TypeVar, Union
22

33
_TypeT = TypeVar("_TypeT", bound=type)
4-
_Reduce = Union[tuple[Callable[..., _TypeT], tuple[Any, ...]], tuple[Callable[..., _TypeT], tuple[Any, ...], Optional[Any]]]
4+
_Reduce = Union[tuple[Callable[..., _TypeT], tuple[Any, ...]], tuple[Callable[..., _TypeT], tuple[Any, ...], Any | None]]
55

66
__all__ = ["pickle", "constructor", "add_extension", "remove_extension", "clear_extension_cache"]
77

stdlib/@python2/ctypes/__init__.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ from typing import (
99
Iterable,
1010
Iterator,
1111
Mapping,
12-
Optional,
1312
Sequence,
1413
Text,
1514
TypeVar,
@@ -88,7 +87,7 @@ class _CData(metaclass=_CDataMeta):
8887
class _CanCastTo(_CData): ...
8988
class _PointerLike(_CanCastTo): ...
9089

91-
_ECT = Callable[[Optional[type[_CData]], _FuncPointer, tuple[_CData, ...]], _CData]
90+
_ECT = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData]
9291
_PF = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]]
9392

9493
class _FuncPointer(_PointerLike, _CData):

stdlib/@python2/distutils/ccompiler.pyi

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

3-
_Macro = Union[tuple[str], tuple[str, Optional[str]]]
3+
_Macro = Union[tuple[str], tuple[str, str | None]]
44

55
def gen_lib_options(
66
compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str]

stdlib/@python2/distutils/fancy_getopt.pyi

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

3-
_Option = tuple[str, Optional[str], str]
3+
_Option = tuple[str, str | None, str]
44
_GR = tuple[list[str], OptionDummy]
55

66
def fancy_getopt(

stdlib/@python2/email/mime/application.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from email.mime.nonmultipart import MIMENonMultipart
2-
from typing import Callable, Optional, Union
2+
from typing import Callable, Union
33

4-
_ParamsType = Union[str, None, tuple[str, Optional[str], str]]
4+
_ParamsType = Union[str, None, tuple[str, str | None, str]]
55

66
class MIMEApplication(MIMENonMultipart):
77
def __init__(

stdlib/@python2/imaplib.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import time
33
from builtins import list as List # alias to avoid name clashes with `IMAP4.list`
44
from socket import socket as _socket
55
from ssl import SSLSocket
6-
from typing import IO, Any, Callable, Pattern, Text, Union
6+
from typing import IO, Any, Callable, Pattern, Text
77
from typing_extensions import Literal
88

99
# TODO: Commands should use their actual return types, not this type alias.
1010
# E.g. tuple[Literal["OK"], list[bytes]]
1111
_CommandResults = tuple[str, list[Any]]
1212

13-
_AnyResponseData = Union[list[None], list[Union[bytes, tuple[bytes, bytes]]]]
13+
_AnyResponseData = list[None] | list[bytes | tuple[bytes, bytes]]
1414

1515
class IMAP4:
1616
error: type[Exception] = ...

stdlib/@python2/inspect.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from types import CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
2-
from typing import Any, AnyStr, Callable, NamedTuple, Optional, Sequence, Union
2+
from typing import Any, AnyStr, Callable, NamedTuple, Sequence, Union
33

44
# Types and members
55
class EndOfBlock(Exception): ...
@@ -106,7 +106,7 @@ class Traceback(NamedTuple):
106106
code_context: list[str] | None
107107
index: int | None # type: ignore[assignment]
108108

109-
_FrameInfo = tuple[FrameType, str, int, str, Optional[list[str]], Optional[int]]
109+
_FrameInfo = tuple[FrameType, str, int, str, list[str] | None, int | None]
110110

111111
def getouterframes(frame: FrameType, context: int = ...) -> list[_FrameInfo]: ...
112112
def getframeinfo(frame: FrameType | TracebackType, context: int = ...) -> Traceback: ...

stdlib/@python2/lib2to3/pgen2/grammar.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from _typeshed import Self, StrPath
2-
from typing import Optional, Text
2+
from typing import Text
33

4-
_Label = tuple[int, Optional[Text]]
4+
_Label = tuple[int, Text | None]
55
_DFA = list[list[tuple[int, int]]]
66
_DFAS = tuple[_DFA, dict[int, int]]
77

0 commit comments

Comments
 (0)