Skip to content

Use PEP 585 syntax everywhere #6681

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

Closed
wants to merge 5 commits into from
Closed
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
The table of contents is too big for display.
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

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
6 changes: 3 additions & 3 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, Union

QUOTE_ALL: int
QUOTE_MINIMAL: int
Expand All @@ -18,9 +18,9 @@ class Dialect:
strict: int
def __init__(self) -> None: ...

_DialectLike = Union[str, Dialect, Type[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
10 changes: 5 additions & 5 deletions stdlib/_dummy_threading.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from types import FrameType, TracebackType
from typing import Any, Callable, Iterable, Mapping, Optional, Type, TypeVar
from typing import Any, Callable, Iterable, Mapping, Optional, TypeVar

# TODO recursive type
_TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]]
Expand Down Expand Up @@ -67,7 +67,7 @@ class Lock:
def __init__(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
def release(self) -> None: ...
Expand All @@ -77,7 +77,7 @@ class _RLock:
def __init__(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
def release(self) -> None: ...
Expand All @@ -88,7 +88,7 @@ class Condition:
def __init__(self, lock: Lock | _RLock | None = ...) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
def release(self) -> None: ...
Expand All @@ -101,7 +101,7 @@ class Condition:
class Semaphore:
def __init__(self, value: int = ...) -> None: ...
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...
def acquire(self, blocking: bool = ..., timeout: float | None = ...) -> bool: ...
def __enter__(self, blocking: bool = ..., timeout: float | None = ...) -> bool: ...
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
6 changes: 3 additions & 3 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, 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 register(cls, subclass: Type[_T]) -> Type[_T]: ...
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
10 changes: 5 additions & 5 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
from typing_extensions import final

error = RuntimeError
Expand All @@ -18,10 +18,10 @@ class LockType:
def locked(self) -> bool: ...
def __enter__(self) -> bool: ...
def __exit__(
self, type: Type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
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,10 +34,10 @@ 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]: ...
def exc_type(self) -> type[BaseException]: ...
@property
def exc_value(self) -> BaseException | None: ...
@property
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/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ctypes
import mmap
import sys
from os import PathLike
from typing import AbstractSet, Any, Awaitable, ClassVar, Container, Generic, Iterable, Protocol, Type, TypeVar, Union
from typing import AbstractSet, Any, Awaitable, ClassVar, Container, Generic, Iterable, Protocol, TypeVar, Union
from typing_extensions import Literal, final

_KT = TypeVar("_KT")
Expand Down Expand Up @@ -215,4 +215,4 @@ class structseq(Generic[_T_co]):
# The second parameter will accept a dict of any kind without raising an exception,
# but only has any meaning if you supply it a dict where the keys are strings.
# https://github.com/python/typeshed/pull/6560#discussion_r767149830
def __new__(cls: Type[_T], sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> _T: ...
def __new__(cls: type[_T], sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> _T: ...
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
12 changes: 6 additions & 6 deletions stdlib/_warnings.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from typing import Any, Type, overload
from typing import Any, overload

_defaultaction: str
_onceregistry: dict[Any, Any]
filters: list[tuple[str, str | None, Type[Warning], str | None, int]]
filters: list[tuple[str, str | None, type[Warning], str | None, int]]

@overload
def warn(message: str, category: Type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...) -> None: ...
def warn(message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...) -> None: ...
@overload
def warn(message: Warning, category: Any = ..., stacklevel: int = ..., source: Any | None = ...) -> None: ...
@overload
def warn_explicit(
message: str,
category: Type[Warning],
category: type[Warning],
filename: str,
lineno: int,
module: str | None = ...,
registry: dict[str | tuple[str, Type[Warning], int], int] | None = ...,
registry: dict[str | tuple[str, type[Warning], int], int] | None = ...,
module_globals: dict[str, Any] | None = ...,
source: Any | None = ...,
) -> None: ...
Expand All @@ -26,7 +26,7 @@ def warn_explicit(
filename: str,
lineno: int,
module: str | None = ...,
registry: dict[str | tuple[str, Type[Warning], int], int] | None = ...,
registry: dict[str | tuple[str, type[Warning], int], int] | None = ...,
module_globals: dict[str, Any] | None = ...,
source: Any | None = ...,
) -> None: ...
8 changes: 4 additions & 4 deletions stdlib/abc.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import sys
from _typeshed import SupportsWrite
from typing import Any, Callable, Tuple, Type, TypeVar
from typing import Any, Callable, 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: ...
def register(cls: ABCMeta, subclass: Type[_T]) -> Type[_T]: ...
def register(cls: ABCMeta, subclass: type[_T]) -> type[_T]: ...

def abstractmethod(funcobj: _FuncT) -> _FuncT: ...

Expand All @@ -27,4 +27,4 @@ class ABC(metaclass=ABCMeta): ...
def get_cache_token() -> object: ...

if sys.version_info >= (3, 10):
def update_abstractmethods(cls: Type[_T]) -> Type[_T]: ...
def update_abstractmethods(cls: type[_T]) -> type[_T]: ...
8 changes: 4 additions & 4 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, Union, overload
from typing_extensions import Literal

class Error(Exception): ...
Expand All @@ -15,13 +15,13 @@ 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: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
def initfp(self, file: IO[bytes]) -> None: ...
def getfp(self) -> IO[bytes]: ...
Expand All @@ -45,7 +45,7 @@ class Aifc_write:
def __del__(self) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
def initfp(self, file: IO[bytes]) -> None: ...
def aiff(self) -> None: ...
Expand Down
Loading