Skip to content

Commit 8d5d252

Browse files
authored
Use PEP 585 syntax wherever possible (#6717)
1 parent e6cb341 commit 8d5d252

File tree

237 files changed

+967
-1070
lines changed

Some content is hidden

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

237 files changed

+967
-1070
lines changed

stdlib/_codecs.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import codecs
22
import sys
3-
from typing import Any, Callable, Dict, Tuple, Union
3+
from typing import Any, Callable, Union
44

55
# This type is not exposed; it is defined in unicodeobject.c
66
class _EncodingMap:
77
def size(self) -> int: ...
88

9-
_MapT = Union[Dict[int, int], _EncodingMap]
10-
_Handler = Callable[[Exception], Tuple[str, int]]
9+
_MapT = Union[dict[int, int], _EncodingMap]
10+
_Handler = Callable[[Exception], tuple[str, int]]
1111

1212
def register(__search_function: Callable[[str], Any]) -> None: ...
1313
def register_error(__errors: str, __handler: _Handler) -> None: ...

stdlib/_compression.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from _typeshed import WriteableBuffer
22
from io import BufferedIOBase, RawIOBase
3-
from typing import Any, Callable, Protocol, Tuple, Type
3+
from typing import Any, Callable, Protocol, Type
44

55
BUFFER_SIZE: Any
66

@@ -16,7 +16,7 @@ class DecompressReader(RawIOBase):
1616
self,
1717
fp: _Reader,
1818
decomp_factory: Callable[..., object],
19-
trailing_error: Type[Exception] | Tuple[Type[Exception], ...] = ...,
19+
trailing_error: Type[Exception] | tuple[Type[Exception], ...] = ...,
2020
**decomp_args: Any,
2121
) -> None: ...
2222
def readable(self) -> bool: ...

stdlib/_csv.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Iterable, Iterator, List, Protocol, Type, Union
1+
from typing import Any, Iterable, Iterator, Protocol, Type, Union
22

33
QUOTE_ALL: int
44
QUOTE_MINIMAL: int
@@ -20,7 +20,7 @@ class Dialect:
2020

2121
_DialectLike = Union[str, Dialect, Type[Dialect]]
2222

23-
class _reader(Iterator[List[str]]):
23+
class _reader(Iterator[list[str]]):
2424
dialect: Dialect
2525
line_num: int
2626
def __next__(self) -> list[str]: ...

stdlib/_dummy_thread.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from typing import Any, Callable, NoReturn, Tuple
1+
from typing import Any, Callable, NoReturn
22

33
TIMEOUT_MAX: int
44
error = RuntimeError
55

6-
def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
6+
def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
77
def exit() -> NoReturn: ...
88
def get_ident() -> int: ...
99
def allocate_lock() -> LockType: ...

stdlib/_operator.pyi

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ from typing import (
1313
Protocol,
1414
Sequence,
1515
SupportsAbs,
16-
Tuple,
1716
TypeVar,
1817
overload,
1918
)
@@ -99,7 +98,7 @@ class attrgetter(Generic[_T_co]):
9998
@overload
10099
def __new__(cls, attr: str, __attr2: str, __attr3: str, __attr4: str) -> attrgetter[tuple[Any, Any, Any, Any]]: ...
101100
@overload
102-
def __new__(cls, attr: str, *attrs: str) -> attrgetter[Tuple[Any, ...]]: ...
101+
def __new__(cls, attr: str, *attrs: str) -> attrgetter[tuple[Any, ...]]: ...
103102
def __call__(self, obj: Any) -> _T_co: ...
104103

105104
@final
@@ -113,7 +112,7 @@ class itemgetter(Generic[_T_co]):
113112
@overload
114113
def __new__(cls, item: Any, __item2: Any, __item3: Any, __item4: Any) -> itemgetter[tuple[Any, Any, Any, Any]]: ...
115114
@overload
116-
def __new__(cls, item: Any, *items: Any) -> itemgetter[Tuple[Any, ...]]: ...
115+
def __new__(cls, item: Any, *items: Any) -> itemgetter[tuple[Any, ...]]: ...
117116
def __call__(self, obj: Any) -> _T_co: ...
118117

119118
@final

stdlib/_osx_support.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import sys
2-
from typing import Iterable, Sequence, Tuple, TypeVar
2+
from typing import Iterable, Sequence, TypeVar
33

44
_T = TypeVar("_T")
55
_K = TypeVar("_K")
66
_V = TypeVar("_V")
77

88
__all__: list[str]
99

10-
_UNIVERSAL_CONFIG_VARS: Tuple[str, ...] # undocumented
11-
_COMPILER_CONFIG_VARS: Tuple[str, ...] # undocumented
10+
_UNIVERSAL_CONFIG_VARS: tuple[str, ...] # undocumented
11+
_COMPILER_CONFIG_VARS: tuple[str, ...] # undocumented
1212
_INITPRE: str # undocumented
1313

1414
def _find_executable(executable: str, path: str | None = ...) -> str | None: ... # undocumented

stdlib/_py_abc.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import Any, Tuple, Type, TypeVar
1+
from typing import Any, Type, TypeVar
22

33
_T = TypeVar("_T")
44

55
# TODO: Change the return into a NewType bound to int after pytype/#597
66
def get_cache_token() -> object: ...
77

88
class ABCMeta(type):
9-
def __new__(__mcls, __name: str, __bases: Tuple[Type[Any], ...], __namespace: dict[str, Any]) -> ABCMeta: ...
9+
def __new__(__mcls, __name: str, __bases: tuple[Type[Any], ...], __namespace: dict[str, Any]) -> ABCMeta: ...
1010
def register(cls, subclass: Type[_T]) -> Type[_T]: ...

stdlib/_random.pyi

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from typing import Tuple
2-
31
# Actually Tuple[(int,) * 625]
4-
_State = Tuple[int, ...]
2+
_State = tuple[int, ...]
53

64
class Random(object):
75
def __init__(self, seed: object = ...) -> None: ...

stdlib/_socket.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from _typeshed import ReadableBuffer, WriteableBuffer
33
from collections.abc import Iterable
4-
from typing import Any, SupportsInt, Tuple, Union, overload
4+
from typing import Any, SupportsInt, Union, overload
55

66
if sys.version_info >= (3, 8):
77
from typing import SupportsIndex
@@ -10,12 +10,12 @@ if sys.version_info >= (3, 8):
1010
else:
1111
_FD = SupportsInt
1212

13-
_CMSG = Tuple[int, int, bytes]
14-
_CMSGArg = Tuple[int, int, ReadableBuffer]
13+
_CMSG = tuple[int, int, bytes]
14+
_CMSGArg = tuple[int, int, ReadableBuffer]
1515

1616
# Addresses can be either tuples of varying lengths (AF_INET, AF_INET6,
1717
# AF_NETLINK, AF_TIPC) or strings (AF_UNIX).
18-
_Address = Union[Tuple[Any, ...], str]
18+
_Address = Union[tuple[Any, ...], str]
1919
_RetAddress = Any
2020
# TODO Most methods allow bytes as address objects
2121

stdlib/_thread.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import structseq
33
from threading import Thread
44
from types import TracebackType
5-
from typing import Any, Callable, NoReturn, Optional, Tuple, Type
5+
from typing import Any, Callable, NoReturn, Optional, Type
66
from typing_extensions import final
77

88
error = RuntimeError
@@ -21,7 +21,7 @@ class LockType:
2121
self, type: Type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
2222
) -> None: ...
2323

24-
def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ...
24+
def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ...
2525
def interrupt_main() -> None: ...
2626
def exit() -> NoReturn: ...
2727
def allocate_lock() -> LockType: ...
@@ -34,7 +34,7 @@ if sys.version_info >= (3, 8):
3434
def get_native_id() -> int: ... # only available on some platforms
3535
@final
3636
class _ExceptHookArgs(
37-
structseq[Any], Tuple[Type[BaseException], Optional[BaseException], Optional[TracebackType], Optional[Thread]]
37+
structseq[Any], tuple[Type[BaseException], Optional[BaseException], Optional[TracebackType], Optional[Thread]]
3838
):
3939
@property
4040
def exc_type(self) -> Type[BaseException]: ...

stdlib/_threading_local.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Any, Dict
1+
from typing import Any
22
from weakref import ReferenceType
33

4-
localdict = Dict[Any, Any]
4+
localdict = dict[Any, Any]
55

66
class _localimpl:
77
key: str

stdlib/_typeshed/wsgi.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# See the README.md file in this directory for more information.
44

55
from sys import _OptExcInfo
6-
from typing import Any, Callable, Dict, Iterable, Protocol
6+
from typing import Any, Callable, Iterable, Protocol
77

88
# stable
99
class StartResponse(Protocol):
1010
def __call__(
1111
self, status: str, headers: list[tuple[str, str]], exc_info: _OptExcInfo | None = ...
1212
) -> Callable[[bytes], Any]: ...
1313

14-
WSGIEnvironment = Dict[str, Any] # stable
14+
WSGIEnvironment = dict[str, Any] # stable
1515
WSGIApplication = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] # stable
1616

1717
# WSGI input streams per PEP 3333, stable

stdlib/abc.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import sys
22
from _typeshed import SupportsWrite
3-
from typing import Any, Callable, Tuple, Type, TypeVar
3+
from typing import Any, Callable, Type, TypeVar
44

55
_T = TypeVar("_T")
66
_FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
77

88
# These definitions have special processing in mypy
99
class ABCMeta(type):
1010
__abstractmethods__: frozenset[str]
11-
def __init__(self, name: str, bases: Tuple[type, ...], namespace: dict[str, Any]) -> None: ...
11+
def __init__(self, name: str, bases: tuple[type, ...], namespace: dict[str, Any]) -> None: ...
1212
def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ...
1313
def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ...
1414
def _dump_registry(cls: ABCMeta, file: SupportsWrite[str] | None = ...) -> None: ...

stdlib/aifc.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from _typeshed import Self
33
from types import TracebackType
4-
from typing import IO, Any, NamedTuple, Tuple, Type, Union, overload
4+
from typing import IO, Any, NamedTuple, Type, Union, overload
55
from typing_extensions import Literal
66

77
class Error(Exception): ...
@@ -15,7 +15,7 @@ class _aifc_params(NamedTuple):
1515
compname: bytes
1616

1717
_File = Union[str, IO[bytes]]
18-
_Marker = Tuple[int, int, bytes]
18+
_Marker = tuple[int, int, bytes]
1919

2020
class Aifc_read:
2121
def __init__(self, f: _File) -> None: ...

stdlib/argparse.pyi

+10-25
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
import sys
2-
from typing import (
3-
IO,
4-
Any,
5-
Callable,
6-
Generator,
7-
Generic,
8-
Iterable,
9-
NoReturn,
10-
Pattern,
11-
Protocol,
12-
Sequence,
13-
Tuple,
14-
Type,
15-
TypeVar,
16-
overload,
17-
)
2+
from typing import IO, Any, Callable, Generator, Generic, Iterable, NoReturn, Pattern, Protocol, Sequence, Type, TypeVar, overload
183

194
_T = TypeVar("_T")
205
_ActionT = TypeVar("_ActionT", bound=Action)
@@ -70,7 +55,7 @@ class _ActionsContainer:
7055
choices: Iterable[_T] | None = ...,
7156
required: bool = ...,
7257
help: str | None = ...,
73-
metavar: str | Tuple[str, ...] | None = ...,
58+
metavar: str | tuple[str, ...] | None = ...,
7459
dest: str | None = ...,
7560
version: str = ...,
7661
**kwargs: Any,
@@ -274,7 +259,7 @@ class HelpFormatter:
274259
def _format_text(self, text: str) -> str: ...
275260
def _format_action(self, action: Action) -> str: ...
276261
def _format_action_invocation(self, action: Action) -> str: ...
277-
def _metavar_formatter(self, action: Action, default_metavar: str) -> Callable[[int], Tuple[str, ...]]: ...
262+
def _metavar_formatter(self, action: Action, default_metavar: str) -> Callable[[int], tuple[str, ...]]: ...
278263
def _format_args(self, action: Action, default_metavar: str) -> str: ...
279264
def _expand_help(self, action: Action) -> str: ...
280265
def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ...
@@ -299,7 +284,7 @@ class Action(_AttributeHolder):
299284
choices: Iterable[Any] | None
300285
required: bool
301286
help: str | None
302-
metavar: str | Tuple[str, ...] | None
287+
metavar: str | tuple[str, ...] | None
303288
def __init__(
304289
self,
305290
option_strings: Sequence[str],
@@ -311,7 +296,7 @@ class Action(_AttributeHolder):
311296
choices: Iterable[_T] | None = ...,
312297
required: bool = ...,
313298
help: str | None = ...,
314-
metavar: str | Tuple[str, ...] | None = ...,
299+
metavar: str | tuple[str, ...] | None = ...,
315300
) -> None: ...
316301
def __call__(
317302
self, parser: ArgumentParser, namespace: Namespace, values: str | Sequence[Any] | None, option_string: str | None = ...
@@ -330,7 +315,7 @@ if sys.version_info >= (3, 9):
330315
choices: Iterable[_T] | None = ...,
331316
required: bool = ...,
332317
help: str | None = ...,
333-
metavar: str | Tuple[str, ...] | None = ...,
318+
metavar: str | tuple[str, ...] | None = ...,
334319
) -> None: ...
335320

336321
class Namespace(_AttributeHolder):
@@ -375,7 +360,7 @@ class _StoreConstAction(Action):
375360
default: Any = ...,
376361
required: bool = ...,
377362
help: str | None = ...,
378-
metavar: str | Tuple[str, ...] | None = ...,
363+
metavar: str | tuple[str, ...] | None = ...,
379364
) -> None: ...
380365

381366
# undocumented
@@ -403,7 +388,7 @@ class _AppendConstAction(Action):
403388
default: Any = ...,
404389
required: bool = ...,
405390
help: str | None = ...,
406-
metavar: str | Tuple[str, ...] | None = ...,
391+
metavar: str | tuple[str, ...] | None = ...,
407392
) -> None: ...
408393

409394
# undocumented
@@ -440,7 +425,7 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
440425
dest: str = ...,
441426
required: bool = ...,
442427
help: str | None = ...,
443-
metavar: str | Tuple[str, ...] | None = ...,
428+
metavar: str | tuple[str, ...] | None = ...,
444429
) -> None: ...
445430
else:
446431
def __init__(
@@ -450,7 +435,7 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
450435
parser_class: Type[_ArgumentParserT],
451436
dest: str = ...,
452437
help: str | None = ...,
453-
metavar: str | Tuple[str, ...] | None = ...,
438+
metavar: str | tuple[str, ...] | None = ...,
454439
) -> None: ...
455440
# TODO: Type keyword args properly.
456441
def add_parser(self, name: str, **kwargs: Any) -> _ArgumentParserT: ...

stdlib/asyncio/base_events.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ from asyncio.tasks import Task
99
from asyncio.transports import BaseTransport
1010
from collections.abc import Iterable
1111
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
12-
from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, Union, overload
12+
from typing import IO, Any, Awaitable, Callable, Generator, Sequence, TypeVar, Union, overload
1313
from typing_extensions import Literal
1414

1515
if sys.version_info >= (3, 7):
1616
from contextvars import Context
1717

1818
_T = TypeVar("_T")
19-
_Context = Dict[str, Any]
19+
_Context = dict[str, Any]
2020
_ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any]
2121
_ProtocolFactory = Callable[[], BaseProtocol]
2222
_SSLContext = Union[bool, None, ssl.SSLContext]
23-
_TransProtPair = Tuple[BaseTransport, BaseProtocol]
23+
_TransProtPair = tuple[BaseTransport, BaseProtocol]
2424

2525
class Server(AbstractServer):
2626
if sys.version_info >= (3, 7):
@@ -37,7 +37,7 @@ class Server(AbstractServer):
3737
def __init__(self, loop: AbstractEventLoop, sockets: list[socket]) -> None: ...
3838
if sys.version_info >= (3, 8):
3939
@property
40-
def sockets(self) -> Tuple[socket, ...]: ...
40+
def sockets(self) -> tuple[socket, ...]: ...
4141
elif sys.version_info >= (3, 7):
4242
@property
4343
def sockets(self) -> list[socket]: ...

stdlib/asyncio/base_subprocess.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import subprocess
22
from collections import deque
3-
from typing import IO, Any, Callable, Optional, Sequence, Tuple, Union
3+
from typing import IO, Any, Callable, Optional, Sequence, Union
44

55
from . import events, futures, protocols, transports
66

@@ -15,7 +15,7 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
1515
_pid: int | None # undocumented
1616
_returncode: int | None # undocumented
1717
_exit_waiters: list[futures.Future[Any]] # undocumented
18-
_pending_calls: deque[tuple[Callable[..., Any], Tuple[Any, ...]]] # undocumented
18+
_pending_calls: deque[tuple[Callable[..., Any], tuple[Any, ...]]] # undocumented
1919
_pipes: dict[int, _File] # undocumented
2020
_finished: bool # undocumented
2121
def __init__(

0 commit comments

Comments
 (0)