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 585 syntax wherever possible #6717

Merged
merged 5 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/_codecs.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import codecs
import sys
from typing import Any, Callable, Dict, Tuple, Union
from typing import Any, Callable, Union

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

_MapT = Union[Dict[int, int], _EncodingMap]
_Handler = Callable[[Exception], Tuple[str, int]]
_MapT = Union[dict[int, int], _EncodingMap]
_Handler = Callable[[Exception], tuple[str, int]]

def register(__search_function: Callable[[str], Any]) -> None: ...
def register_error(__errors: str, __handler: _Handler) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_compression.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import WriteableBuffer
from io import BufferedIOBase, RawIOBase
from typing import Any, Callable, Protocol, Tuple, Type
from typing import Any, Callable, Protocol, Type

BUFFER_SIZE: Any

Expand All @@ -16,7 +16,7 @@ class DecompressReader(RawIOBase):
self,
fp: _Reader,
decomp_factory: Callable[..., object],
trailing_error: Type[Exception] | Tuple[Type[Exception], ...] = ...,
trailing_error: Type[Exception] | tuple[Type[Exception], ...] = ...,
**decomp_args: Any,
) -> None: ...
def readable(self) -> bool: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_csv.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Iterable, Iterator, List, Protocol, Type, Union
from typing import Any, Iterable, Iterator, Protocol, Type, Union

QUOTE_ALL: int
QUOTE_MINIMAL: int
Expand All @@ -20,7 +20,7 @@ class Dialect:

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

class _reader(Iterator[List[str]]):
class _reader(Iterator[list[str]]):
dialect: Dialect
line_num: int
def __next__(self) -> list[str]: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_dummy_thread.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Callable, NoReturn, Tuple
from typing import Any, Callable, NoReturn

TIMEOUT_MAX: int
error = RuntimeError

def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
def exit() -> NoReturn: ...
def get_ident() -> int: ...
def allocate_lock() -> LockType: ...
Expand Down
5 changes: 2 additions & 3 deletions stdlib/_operator.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ from typing import (
Protocol,
Sequence,
SupportsAbs,
Tuple,
TypeVar,
overload,
)
Expand Down Expand Up @@ -99,7 +98,7 @@ class attrgetter(Generic[_T_co]):
@overload
def __new__(cls, attr: str, __attr2: str, __attr3: str, __attr4: str) -> attrgetter[tuple[Any, Any, Any, Any]]: ...
@overload
def __new__(cls, attr: str, *attrs: str) -> attrgetter[Tuple[Any, ...]]: ...
def __new__(cls, attr: str, *attrs: str) -> attrgetter[tuple[Any, ...]]: ...
def __call__(self, obj: Any) -> _T_co: ...

@final
Expand All @@ -113,7 +112,7 @@ class itemgetter(Generic[_T_co]):
@overload
def __new__(cls, item: Any, __item2: Any, __item3: Any, __item4: Any) -> itemgetter[tuple[Any, Any, Any, Any]]: ...
@overload
def __new__(cls, item: Any, *items: Any) -> itemgetter[Tuple[Any, ...]]: ...
def __new__(cls, item: Any, *items: Any) -> itemgetter[tuple[Any, ...]]: ...
def __call__(self, obj: Any) -> _T_co: ...

@final
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_osx_support.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sys
from typing import Iterable, Sequence, Tuple, TypeVar
from typing import Iterable, Sequence, TypeVar

_T = TypeVar("_T")
_K = TypeVar("_K")
_V = TypeVar("_V")

__all__: list[str]

_UNIVERSAL_CONFIG_VARS: Tuple[str, ...] # undocumented
_COMPILER_CONFIG_VARS: Tuple[str, ...] # undocumented
_UNIVERSAL_CONFIG_VARS: tuple[str, ...] # undocumented
_COMPILER_CONFIG_VARS: tuple[str, ...] # undocumented
_INITPRE: str # undocumented

def _find_executable(executable: str, path: str | None = ...) -> str | None: ... # undocumented
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_py_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Any, Tuple, Type, TypeVar
from typing import Any, Type, TypeVar

_T = TypeVar("_T")

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

class ABCMeta(type):
def __new__(__mcls, __name: str, __bases: Tuple[Type[Any], ...], __namespace: dict[str, Any]) -> ABCMeta: ...
def __new__(__mcls, __name: str, __bases: tuple[Type[Any], ...], __namespace: dict[str, Any]) -> ABCMeta: ...
def register(cls, subclass: Type[_T]) -> Type[_T]: ...
4 changes: 1 addition & 3 deletions stdlib/_random.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Tuple

# Actually Tuple[(int,) * 625]
_State = Tuple[int, ...]
_State = tuple[int, ...]

class Random(object):
def __init__(self, seed: object = ...) -> None: ...
Expand Down
8 changes: 4 additions & 4 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, Tuple, Union, overload
from typing import Any, SupportsInt, Union, overload

if sys.version_info >= (3, 8):
from typing import SupportsIndex
Expand All @@ -10,12 +10,12 @@ if sys.version_info >= (3, 8):
else:
_FD = SupportsInt

_CMSG = Tuple[int, int, bytes]
_CMSGArg = Tuple[int, int, ReadableBuffer]
_CMSG = tuple[int, int, bytes]
_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 = Union[tuple[Any, ...], str]
_RetAddress = Any
# TODO Most methods allow bytes as address objects

Expand Down
6 changes: 3 additions & 3 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, Tuple, Type
from typing import Any, Callable, NoReturn, Optional, Type
from typing_extensions import final

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

def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ...
def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ...
def interrupt_main() -> None: ...
def exit() -> NoReturn: ...
def allocate_lock() -> LockType: ...
Expand All @@ -34,7 +34,7 @@ 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]]
structseq[Any], tuple[Type[BaseException], Optional[BaseException], Optional[TracebackType], Optional[Thread]]
):
@property
def exc_type(self) -> Type[BaseException]: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_threading_local.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict
from typing import Any
from weakref import ReferenceType

localdict = Dict[Any, Any]
localdict = dict[Any, Any]

class _localimpl:
key: str
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_typeshed/wsgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# See the README.md file in this directory for more information.

from sys import _OptExcInfo
from typing import Any, Callable, Dict, Iterable, Protocol
from typing import Any, Callable, Iterable, Protocol

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

WSGIEnvironment = Dict[str, Any] # stable
WSGIEnvironment = dict[str, Any] # stable
WSGIApplication = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] # stable

# WSGI input streams per PEP 3333, stable
Expand Down
4 changes: 2 additions & 2 deletions stdlib/abc.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sys
from _typeshed import SupportsWrite
from typing import Any, Callable, Tuple, Type, TypeVar
from typing import Any, Callable, Type, TypeVar

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

# These definitions have special processing in mypy
class ABCMeta(type):
__abstractmethods__: frozenset[str]
def __init__(self, name: str, bases: Tuple[type, ...], namespace: dict[str, Any]) -> None: ...
def __init__(self, name: str, bases: tuple[type, ...], namespace: dict[str, Any]) -> None: ...
def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ...
def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ...
def _dump_registry(cls: ABCMeta, file: SupportsWrite[str] | None = ...) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/aifc.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from _typeshed import Self
from types import TracebackType
from typing import IO, Any, NamedTuple, Tuple, Type, Union, overload
from typing import IO, Any, NamedTuple, Type, Union, overload
from typing_extensions import Literal

class Error(Exception): ...
Expand All @@ -15,7 +15,7 @@ class _aifc_params(NamedTuple):
compname: bytes

_File = Union[str, IO[bytes]]
_Marker = Tuple[int, int, bytes]
_Marker = tuple[int, int, bytes]

class Aifc_read:
def __init__(self, f: _File) -> None: ...
Expand Down
35 changes: 10 additions & 25 deletions stdlib/argparse.pyi
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
import sys
from typing import (
IO,
Any,
Callable,
Generator,
Generic,
Iterable,
NoReturn,
Pattern,
Protocol,
Sequence,
Tuple,
Type,
TypeVar,
overload,
)
from typing import IO, Any, Callable, Generator, Generic, Iterable, NoReturn, Pattern, Protocol, Sequence, Type, TypeVar, overload

_T = TypeVar("_T")
_ActionT = TypeVar("_ActionT", bound=Action)
Expand Down Expand Up @@ -70,7 +55,7 @@ class _ActionsContainer:
choices: Iterable[_T] | None = ...,
required: bool = ...,
help: str | None = ...,
metavar: str | Tuple[str, ...] | None = ...,
metavar: str | tuple[str, ...] | None = ...,
dest: str | None = ...,
version: str = ...,
**kwargs: Any,
Expand Down Expand Up @@ -274,7 +259,7 @@ class HelpFormatter:
def _format_text(self, text: str) -> str: ...
def _format_action(self, action: Action) -> str: ...
def _format_action_invocation(self, action: Action) -> str: ...
def _metavar_formatter(self, action: Action, default_metavar: str) -> Callable[[int], Tuple[str, ...]]: ...
def _metavar_formatter(self, action: Action, default_metavar: str) -> Callable[[int], tuple[str, ...]]: ...
def _format_args(self, action: Action, default_metavar: str) -> str: ...
def _expand_help(self, action: Action) -> str: ...
def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ...
Expand All @@ -299,7 +284,7 @@ class Action(_AttributeHolder):
choices: Iterable[Any] | None
required: bool
help: str | None
metavar: str | Tuple[str, ...] | None
metavar: str | tuple[str, ...] | None
def __init__(
self,
option_strings: Sequence[str],
Expand All @@ -311,7 +296,7 @@ class Action(_AttributeHolder):
choices: Iterable[_T] | None = ...,
required: bool = ...,
help: str | None = ...,
metavar: str | Tuple[str, ...] | None = ...,
metavar: str | tuple[str, ...] | None = ...,
) -> None: ...
def __call__(
self, parser: ArgumentParser, namespace: Namespace, values: str | Sequence[Any] | None, option_string: str | None = ...
Expand All @@ -330,7 +315,7 @@ if sys.version_info >= (3, 9):
choices: Iterable[_T] | None = ...,
required: bool = ...,
help: str | None = ...,
metavar: str | Tuple[str, ...] | None = ...,
metavar: str | tuple[str, ...] | None = ...,
) -> None: ...

class Namespace(_AttributeHolder):
Expand Down Expand Up @@ -375,7 +360,7 @@ class _StoreConstAction(Action):
default: Any = ...,
required: bool = ...,
help: str | None = ...,
metavar: str | Tuple[str, ...] | None = ...,
metavar: str | tuple[str, ...] | None = ...,
) -> None: ...

# undocumented
Expand Down Expand Up @@ -403,7 +388,7 @@ class _AppendConstAction(Action):
default: Any = ...,
required: bool = ...,
help: str | None = ...,
metavar: str | Tuple[str, ...] | None = ...,
metavar: str | tuple[str, ...] | None = ...,
) -> None: ...

# undocumented
Expand Down Expand Up @@ -440,7 +425,7 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
dest: str = ...,
required: bool = ...,
help: str | None = ...,
metavar: str | Tuple[str, ...] | None = ...,
metavar: str | tuple[str, ...] | None = ...,
) -> None: ...
else:
def __init__(
Expand All @@ -450,7 +435,7 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
parser_class: Type[_ArgumentParserT],
dest: str = ...,
help: str | None = ...,
metavar: str | Tuple[str, ...] | None = ...,
metavar: str | tuple[str, ...] | None = ...,
) -> None: ...
# TODO: Type keyword args properly.
def add_parser(self, name: str, **kwargs: Any) -> _ArgumentParserT: ...
Expand Down
8 changes: 4 additions & 4 deletions stdlib/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ from asyncio.tasks import Task
from asyncio.transports import BaseTransport
from collections.abc import Iterable
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
from typing import IO, Any, Awaitable, Callable, Dict, Generator, Sequence, Tuple, TypeVar, Union, overload
from typing import IO, Any, Awaitable, Callable, Generator, Sequence, TypeVar, Union, overload
from typing_extensions import Literal

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

_T = TypeVar("_T")
_Context = Dict[str, Any]
_Context = dict[str, Any]
_ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any]
_ProtocolFactory = Callable[[], BaseProtocol]
_SSLContext = Union[bool, None, ssl.SSLContext]
_TransProtPair = Tuple[BaseTransport, BaseProtocol]
_TransProtPair = tuple[BaseTransport, BaseProtocol]

class Server(AbstractServer):
if sys.version_info >= (3, 7):
Expand All @@ -37,7 +37,7 @@ class Server(AbstractServer):
def __init__(self, loop: AbstractEventLoop, sockets: list[socket]) -> None: ...
if sys.version_info >= (3, 8):
@property
def sockets(self) -> Tuple[socket, ...]: ...
def sockets(self) -> tuple[socket, ...]: ...
elif sys.version_info >= (3, 7):
@property
def sockets(self) -> list[socket]: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/asyncio/base_subprocess.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess
from collections import deque
from typing import IO, Any, Callable, Optional, Sequence, Tuple, Union
from typing import IO, Any, Callable, Optional, Sequence, Union

from . import events, futures, protocols, transports

Expand All @@ -15,7 +15,7 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
_pid: int | None # undocumented
_returncode: int | None # undocumented
_exit_waiters: list[futures.Future[Any]] # undocumented
_pending_calls: deque[tuple[Callable[..., Any], Tuple[Any, ...]]] # undocumented
_pending_calls: deque[tuple[Callable[..., Any], tuple[Any, ...]]] # undocumented
_pipes: dict[int, _File] # undocumented
_finished: bool # undocumented
def __init__(
Expand Down
Loading