From 6f943d43ea2c2b159023fb3cd27c56679ca85943 Mon Sep 17 00:00:00 2001 From: Utsav <39943143+utsav00@users.noreply.github.com> Date: Fri, 23 Oct 2020 02:35:04 +0530 Subject: [PATCH] Added __class_getitem__ (#4695) Resolves #4682 Co-authored-by: hauntsaninja <> --- stdlib/2and3/_weakref.pyi | 5 +++++ stdlib/2and3/_weakrefset.pyi | 6 ++++++ stdlib/2and3/ctypes/__init__.pyi | 7 +++++++ stdlib/2and3/difflib.pyi | 5 +++++ stdlib/2and3/filecmp.pyi | 8 ++++++-- stdlib/2and3/mailbox.pyi | 8 ++++++++ stdlib/3.7/contextvars.pyi | 8 ++++++++ stdlib/3.7/dataclasses.pyi | 11 ++++++++++- stdlib/3/asyncio/futures.pyi | 5 +++++ stdlib/3/asyncio/queues.pyi | 8 +++++++- stdlib/3/asyncio/tasks.pyi | 5 +++++ stdlib/3/builtins.pyi | 2 ++ stdlib/3/concurrent/futures/_base.pyi | 5 +++++ stdlib/3/concurrent/futures/thread.pyi | 5 +++++ stdlib/3/functools.pyi | 9 +++++++++ stdlib/3/multiprocessing/managers.pyi | 5 +++++ stdlib/3/multiprocessing/pool.pyi | 6 ++++++ stdlib/3/multiprocessing/queues.pyi | 6 ++++++ stdlib/3/multiprocessing/shared_memory.pyi | 7 ++++++- stdlib/3/os/__init__.pyi | 5 +++++ stdlib/3/pathlib.pyi | 5 +++++ stdlib/3/queue.pyi | 7 +++++++ stdlib/3/subprocess.pyi | 7 +++++++ stdlib/3/tempfile.pyi | 5 +++++ stdlib/3/typing.pyi | 17 +++++++++++++++++ stdlib/3/unittest/case.pyi | 5 +++++ stdlib/3/urllib/parse.pyi | 5 +++++ third_party/2/concurrent/futures/_base.pyi | 5 +++++ third_party/2/concurrent/futures/thread.pyi | 5 +++++ third_party/2/pathlib2.pyi | 5 +++++ third_party/3/contextvars.pyi | 8 ++++++++ third_party/3/dataclasses.pyi | 11 ++++++++++- 32 files changed, 205 insertions(+), 6 deletions(-) diff --git a/stdlib/2and3/_weakref.pyi b/stdlib/2and3/_weakref.pyi index 7324ab831..5b4870229 100644 --- a/stdlib/2and3/_weakref.pyi +++ b/stdlib/2and3/_weakref.pyi @@ -1,6 +1,9 @@ import sys from typing import Any, Callable, Generic, Optional, TypeVar, overload +if sys.version_info >= (3, 9): + from types import GenericAlias + _C = TypeVar("_C", bound=Callable[..., Any]) _T = TypeVar("_T") @@ -16,6 +19,8 @@ class ReferenceType(Generic[_T]): def __init__(self, o: _T, callback: Optional[Callable[[ReferenceType[_T]], Any]] = ...) -> None: ... def __call__(self) -> Optional[_T]: ... def __hash__(self) -> int: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... ref = ReferenceType diff --git a/stdlib/2and3/_weakrefset.pyi b/stdlib/2and3/_weakrefset.pyi index 208d2fe41..6f8412464 100644 --- a/stdlib/2and3/_weakrefset.pyi +++ b/stdlib/2and3/_weakrefset.pyi @@ -1,5 +1,9 @@ +import sys from typing import Any, Generic, Iterable, Iterator, MutableSet, Optional, TypeVar, Union +if sys.version_info >= (3, 9): + from types import GenericAlias + _S = TypeVar("_S") _T = TypeVar("_T") _SelfT = TypeVar("_SelfT", bound=WeakSet[Any]) @@ -39,3 +43,5 @@ class WeakSet(MutableSet[_T], Generic[_T]): def union(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... def __or__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... def isdisjoint(self, other: Iterable[_T]) -> bool: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/2and3/ctypes/__init__.pyi b/stdlib/2and3/ctypes/__init__.pyi index 652db3f6f..8ccc47c0b 100644 --- a/stdlib/2and3/ctypes/__init__.pyi +++ b/stdlib/2and3/ctypes/__init__.pyi @@ -21,6 +21,9 @@ from typing import ( overload, ) +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") _DLLT = TypeVar("_DLLT", bound=CDLL) _CT = TypeVar("_CT", bound=_CData) @@ -58,6 +61,8 @@ class LibraryLoader(Generic[_DLLT]): def __getattr__(self, name: str) -> _DLLT: ... def __getitem__(self, name: str) -> _DLLT: ... def LoadLibrary(self, name: str) -> _DLLT: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... cdll: LibraryLoader[CDLL] = ... if sys.platform == "win32": @@ -302,3 +307,5 @@ class Array(Generic[_CT], _CData): # Can't inherit from Sized because the metaclass conflict between # Sized and _CData prevents using _CDataMeta. def __len__(self) -> int: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/2and3/difflib.pyi b/stdlib/2and3/difflib.pyi index b0b9bd02b..af460079b 100644 --- a/stdlib/2and3/difflib.pyi +++ b/stdlib/2and3/difflib.pyi @@ -19,6 +19,9 @@ from typing import ( overload, ) +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") if sys.version_info >= (3,): @@ -53,6 +56,8 @@ class SequenceMatcher(Generic[_T]): def ratio(self) -> float: ... def quick_ratio(self) -> float: ... def real_quick_ratio(self) -> float: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... # mypy thinks the signatures of the overloads overlap, but the types still work fine @overload diff --git a/stdlib/2and3/filecmp.pyi b/stdlib/2and3/filecmp.pyi index a24bf50ce..adbe956e1 100644 --- a/stdlib/2and3/filecmp.pyi +++ b/stdlib/2and3/filecmp.pyi @@ -1,10 +1,13 @@ # Stubs for filecmp (Python 2/3) import sys -from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Text, Tuple, Union +from typing import Any, AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Text, Tuple, Union if sys.version_info >= (3, 6): from os import PathLike +if sys.version_info >= (3, 9): + from types import GenericAlias + DEFAULT_IGNORES: List[str] if sys.version_info >= (3, 6): @@ -41,7 +44,6 @@ class dircmp(Generic[AnyStr]): right: AnyStr hide: Sequence[AnyStr] ignore: Sequence[AnyStr] - # These properties are created at runtime by __getattr__ subdirs: Dict[AnyStr, dircmp[AnyStr]] same_files: List[AnyStr] @@ -65,6 +67,8 @@ class dircmp(Generic[AnyStr]): def phase3(self) -> None: ... def phase4(self) -> None: ... def phase4_closure(self) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... if sys.version_info >= (3,): def clear_cache() -> None: ... diff --git a/stdlib/2and3/mailbox.pyi b/stdlib/2and3/mailbox.pyi index a089fd3b8..27377f8c5 100644 --- a/stdlib/2and3/mailbox.pyi +++ b/stdlib/2and3/mailbox.pyi @@ -1,4 +1,5 @@ import email.message +import sys from _typeshed import AnyPath from types import TracebackType from typing import ( @@ -24,6 +25,9 @@ from typing import ( ) from typing_extensions import Literal +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") _MessageType = TypeVar("_MessageType", bound=Message) _MessageData = Union[email.message.Message, bytes, str, IO[str], IO[bytes]] @@ -76,6 +80,8 @@ class Mailbox(Generic[_MessageType]): def lock(self) -> None: ... def unlock(self) -> None: ... def close(self) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class Maildir(Mailbox[MaildirMessage]): @@ -188,6 +194,8 @@ class _ProxyFile(Generic[AnyStr]): def flush(self) -> None: ... @property def closed(self) -> bool: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class _PartialFile(_ProxyFile[AnyStr]): def __init__(self, f: IO[AnyStr], start: Optional[int] = ..., stop: Optional[int] = ...) -> None: ... diff --git a/stdlib/3.7/contextvars.pyi b/stdlib/3.7/contextvars.pyi index 7310e752d..429d2037a 100644 --- a/stdlib/3.7/contextvars.pyi +++ b/stdlib/3.7/contextvars.pyi @@ -1,5 +1,9 @@ +import sys from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") class ContextVar(Generic[_T]): @@ -9,6 +13,8 @@ class ContextVar(Generic[_T]): def get(self, default: _T = ...) -> _T: ... def set(self, value: _T) -> Token[_T]: ... def reset(self, token: Token[_T]) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class Token(Generic[_T]): @property @@ -16,6 +22,8 @@ class Token(Generic[_T]): @property def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express MISSING: ClassVar[object] + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... def copy_context() -> Context: ... diff --git a/stdlib/3.7/dataclasses.pyi b/stdlib/3.7/dataclasses.pyi index 25215f6ff..1f5b6b4d3 100644 --- a/stdlib/3.7/dataclasses.pyi +++ b/stdlib/3.7/dataclasses.pyi @@ -1,5 +1,9 @@ +import sys from typing import Any, Callable, Dict, Generic, Iterable, List, Mapping, Optional, Tuple, Type, TypeVar, Union, overload +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") class _MISSING_TYPE: ... @@ -32,6 +36,8 @@ class Field(Generic[_T]): init: bool compare: bool metadata: Mapping[str, Any] + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... # NOTE: Actual return type is 'Field[_T]', but we want to help type checkers # to understand the magic that happens at runtime. @@ -68,7 +74,10 @@ def fields(class_or_instance: Any) -> Tuple[Field[Any], ...]: ... def is_dataclass(obj: Any) -> bool: ... class FrozenInstanceError(AttributeError): ... -class InitVar(Generic[_T]): ... + +class InitVar(Generic[_T]): + if sys.version_info >= (3, 9): + def __class_getitem__(cls, type: Any) -> GenericAlias: ... def make_dataclass( cls_name: str, diff --git a/stdlib/3/asyncio/futures.pyi b/stdlib/3/asyncio/futures.pyi index 1b4bfb2b4..eccda8903 100644 --- a/stdlib/3/asyncio/futures.pyi +++ b/stdlib/3/asyncio/futures.pyi @@ -11,6 +11,9 @@ if sys.version_info < (3, 8): if sys.version_info >= (3, 7): from contextvars import Context +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") _S = TypeVar("_S") @@ -58,5 +61,7 @@ class Future(Awaitable[_T], Iterable[_T]): def __await__(self) -> Generator[Any, None, _T]: ... @property def _loop(self) -> AbstractEventLoop: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... def wrap_future(future: Union[_ConcurrentFuture[_T], Future[_T]], *, loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ... diff --git a/stdlib/3/asyncio/queues.pyi b/stdlib/3/asyncio/queues.pyi index 9dc9ec1f0..d5048744b 100644 --- a/stdlib/3/asyncio/queues.pyi +++ b/stdlib/3/asyncio/queues.pyi @@ -1,5 +1,9 @@ +import sys from asyncio.events import AbstractEventLoop -from typing import Generic, Optional, TypeVar +from typing import Any, Generic, Optional, TypeVar + +if sys.version_info >= (3, 9): + from types import GenericAlias class QueueEmpty(Exception): ... class QueueFull(Exception): ... @@ -25,6 +29,8 @@ class Queue(Generic[_T]): def get_nowait(self) -> _T: ... async def join(self) -> bool: ... def task_done(self) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, type: Any) -> GenericAlias: ... class PriorityQueue(Queue[_T]): ... class LifoQueue(Queue[_T]): ... diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index 3fb59ea95..ed5db5815 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -22,6 +22,9 @@ from typing_extensions import Literal from .events import AbstractEventLoop from .futures import Future +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") _T1 = TypeVar("_T1") _T2 = TypeVar("_T2") @@ -189,6 +192,8 @@ class Task(Future[_T], Generic[_T]): def all_tasks(cls, loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ... if sys.version_info < (3, 7): def _wakeup(self, fut: Future[Any]) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... if sys.version_info >= (3, 7): def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 211c1f499..0e91a9ccb 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -858,6 +858,8 @@ class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... def __iter__(self) -> Iterator[Tuple[int, _T]]: ... def __next__(self) -> Tuple[int, _T]: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class range(Sequence[int]): start: int diff --git a/stdlib/3/concurrent/futures/_base.pyi b/stdlib/3/concurrent/futures/_base.pyi index e84042f12..77ac77a3d 100644 --- a/stdlib/3/concurrent/futures/_base.pyi +++ b/stdlib/3/concurrent/futures/_base.pyi @@ -5,6 +5,9 @@ from logging import Logger from types import TracebackType from typing import Any, Callable, Container, Generic, Iterable, Iterator, List, Optional, Protocol, Set, Tuple, TypeVar +if sys.version_info >= (3, 9): + from types import GenericAlias + FIRST_COMPLETED: str FIRST_EXCEPTION: str ALL_COMPLETED: str @@ -54,6 +57,8 @@ class Future(Generic[_T]): def exception_info(self, timeout: Optional[float] = ...) -> Tuple[Any, Optional[TracebackType]]: ... def set_exception(self, exception: Any) -> None: ... def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class Executor: if sys.version_info >= (3, 9): diff --git a/stdlib/3/concurrent/futures/thread.pyi b/stdlib/3/concurrent/futures/thread.pyi index 75a4060ef..35b42f436 100644 --- a/stdlib/3/concurrent/futures/thread.pyi +++ b/stdlib/3/concurrent/futures/thread.pyi @@ -7,6 +7,9 @@ if sys.version_info >= (3, 7): from ._base import BrokenExecutor class BrokenThreadPool(BrokenExecutor): ... +if sys.version_info >= (3, 9): + from types import GenericAlias + _S = TypeVar("_S") class ThreadPoolExecutor(Executor): @@ -30,3 +33,5 @@ class _WorkItem(Generic[_S]): kwargs: Mapping[str, Any] def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... def run(self) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index c44dcf7f8..2a411b5e6 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -18,6 +18,9 @@ from typing import ( overload, ) +if sys.version_info >= (3, 9): + from types import GenericAlias + _AnyCallable = Callable[..., Any] _T = TypeVar("_T") @@ -68,6 +71,8 @@ class partial(Generic[_T]): keywords: Dict[str, Any] def __init__(self, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> _T: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... # With protocols, this could change into a generic protocol that defines __get__ and returns _T _Descriptor = Any @@ -83,6 +88,8 @@ class partialmethod(Generic[_T]): def __get__(self, obj: Any, cls: Type[Any]) -> Callable[..., _T]: ... @property def __isabstractmethod__(self) -> bool: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class _SingleDispatchCallable(Generic[_T]): registry: Mapping[Any, Callable[..., _T]] @@ -115,6 +122,8 @@ if sys.version_info >= (3, 8): @overload def __get__(self, instance: _S, owner: Optional[Type[Any]] = ...) -> _T: ... def __set_name__(self, owner: Type[Any], name: str) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... if sys.version_info >= (3, 9): def cache(__user_function: Callable[..., _T]) -> _lru_cache_wrapper[_T]: ... diff --git a/stdlib/3/multiprocessing/managers.pyi b/stdlib/3/multiprocessing/managers.pyi index 7dd12f707..8bacf9ab3 100644 --- a/stdlib/3/multiprocessing/managers.pyi +++ b/stdlib/3/multiprocessing/managers.pyi @@ -30,6 +30,9 @@ if sys.version_info >= (3, 8): _SharedMemory = SharedMemory _ShareableList = ShareableList +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") _KT = TypeVar("_KT") _VT = TypeVar("_VT") @@ -89,6 +92,8 @@ class ValueProxy(BaseProxy, Generic[_T]): def get(self) -> _T: ... def set(self, value: _T) -> None: ... value: _T + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... # Returned by BaseManager.get_server() class Server: diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index d605d228d..d7cc04b14 100644 --- a/stdlib/3/multiprocessing/pool.pyi +++ b/stdlib/3/multiprocessing/pool.pyi @@ -1,5 +1,9 @@ +import sys from typing import Any, Callable, ContextManager, Generic, Iterable, Iterator, List, Mapping, Optional, TypeVar +if sys.version_info >= (3, 9): + from types import GenericAlias + _PT = TypeVar("_PT", bound=Pool) _S = TypeVar("_S") _T = TypeVar("_T") @@ -9,6 +13,8 @@ class ApplyResult(Generic[_T]): def wait(self, timeout: Optional[float] = ...) -> None: ... def ready(self) -> bool: ... def successful(self) -> bool: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... # alias created during issue #17805 AsyncResult = ApplyResult diff --git a/stdlib/3/multiprocessing/queues.pyi b/stdlib/3/multiprocessing/queues.pyi index 380e840ba..3d61e44e6 100644 --- a/stdlib/3/multiprocessing/queues.pyi +++ b/stdlib/3/multiprocessing/queues.pyi @@ -1,6 +1,10 @@ import queue +import sys from typing import Any, Generic, Optional, TypeVar +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") class Queue(queue.Queue[_T]): @@ -27,3 +31,5 @@ class SimpleQueue(Generic[_T]): def empty(self) -> bool: ... def get(self) -> _T: ... def put(self, item: _T) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/3/multiprocessing/shared_memory.pyi b/stdlib/3/multiprocessing/shared_memory.pyi index c837155e1..cf8b68bfc 100644 --- a/stdlib/3/multiprocessing/shared_memory.pyi +++ b/stdlib/3/multiprocessing/shared_memory.pyi @@ -1,5 +1,8 @@ import sys -from typing import Generic, Iterable, Optional, Tuple, TypeVar +from typing import Any, Generic, Iterable, Optional, Tuple, TypeVar + +if sys.version_info >= (3, 9): + from types import GenericAlias _S = TypeVar("_S") _SLT = TypeVar("_SLT", int, float, bool, str, bytes, None) @@ -26,3 +29,5 @@ if sys.version_info >= (3, 8): def format(self) -> str: ... def count(self, value: _SLT) -> int: ... def index(self, value: _SLT) -> int: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index 69edd4368..85d2e8aa8 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -38,6 +38,9 @@ from typing_extensions import Literal from . import path as path +if sys.version_info >= (3, 9): + from types import GenericAlias + # We need to use something from path, or flake8 and pytype get unhappy _supports_unicode_filenames = path.supports_unicode_filenames @@ -288,6 +291,8 @@ if sys.version_info >= (3, 6): def is_symlink(self) -> bool: ... def stat(self, *, follow_symlinks: bool = ...) -> stat_result: ... def __fspath__(self) -> AnyStr: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... else: class DirEntry(Generic[AnyStr]): diff --git a/stdlib/3/pathlib.pyi b/stdlib/3/pathlib.pyi index be94eb59a..3f3bfac51 100644 --- a/stdlib/3/pathlib.pyi +++ b/stdlib/3/pathlib.pyi @@ -6,6 +6,9 @@ from types import TracebackType from typing import IO, Any, BinaryIO, Generator, List, Optional, Sequence, Text, TextIO, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal +if sys.version_info >= (3, 9): + from types import GenericAlias + _P = TypeVar("_P", bound=PurePath) if sys.version_info >= (3, 6): @@ -52,6 +55,8 @@ class PurePath(_PurePathBase): def parents(self: _P) -> Sequence[_P]: ... @property def parent(self: _P) -> _P: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, type: Any) -> GenericAlias: ... class PurePosixPath(PurePath): ... class PureWindowsPath(PurePath): ... diff --git a/stdlib/3/queue.pyi b/stdlib/3/queue.pyi index 57a848a88..8e366b3bd 100644 --- a/stdlib/3/queue.pyi +++ b/stdlib/3/queue.pyi @@ -6,6 +6,9 @@ import sys from threading import Condition, Lock from typing import Any, Generic, Optional, TypeVar +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") class Empty(Exception): ... @@ -34,6 +37,8 @@ class Queue(Generic[_T]): def qsize(self) -> int: ... def _qsize(self) -> int: ... def task_done(self) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class PriorityQueue(Queue[_T]): ... class LifoQueue(Queue[_T]): ... @@ -47,3 +52,5 @@ if sys.version_info >= (3, 7): def put(self, item: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ... def put_nowait(self, item: _T) -> None: ... def qsize(self) -> int: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 77b29f59c..159a8e18b 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -4,6 +4,9 @@ from types import TracebackType from typing import IO, Any, AnyStr, Callable, Generic, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal +if sys.version_info >= (3, 9): + from types import GenericAlias + # We prefer to annotate inputs to methods (eg subprocess.check_call) with these # union types. # For outputs we use laborious literal based overloads to try to determine @@ -38,6 +41,8 @@ class CompletedProcess(Generic[_T]): stderr: _T def __init__(self, args: _CMD, returncode: int, stdout: Optional[_T] = ..., stderr: Optional[_T] = ...) -> None: ... def check_returncode(self) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... if sys.version_info >= (3, 7): # Nearly the same args as for 3.6, except for capture_output and text @@ -1211,6 +1216,8 @@ class Popen(Generic[AnyStr]): def __exit__( self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType] ) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... # The result really is always a str. def getstatusoutput(cmd: _TXT) -> Tuple[int, str]: ... diff --git a/stdlib/3/tempfile.pyi b/stdlib/3/tempfile.pyi index 3c46be284..acfe24a4c 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -4,6 +4,9 @@ from types import TracebackType from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, List, Optional, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal +if sys.version_info >= (3, 9): + from types import GenericAlias + # global variables TMP_MAX: int tempdir: Optional[str] @@ -287,6 +290,8 @@ class TemporaryDirectory(Generic[AnyStr]): def __exit__( self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] ) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... def mkstemp( suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[_DirT[AnyStr]] = ..., text: bool = ... diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index a3f46e9b5..8c7f79c9b 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -3,6 +3,9 @@ import sys from abc import ABCMeta, abstractmethod from types import CodeType, FrameType, TracebackType +if sys.version_info >= (3, 9): + from types import GenericAlias + # Definitions of special type checking related constructs. Their definitions # are not used, so their value does not matter. @@ -167,6 +170,8 @@ class Hashable(Protocol, metaclass=ABCMeta): class Iterable(Protocol[_T_co]): @abstractmethod def __iter__(self) -> Iterator[_T_co]: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... @runtime_checkable class Iterator(Iterable[_T_co], Protocol[_T_co]): @@ -201,6 +206,8 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): class Awaitable(Protocol[_T_co]): @abstractmethod def __await__(self) -> Generator[Any, None, _T_co]: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): __name__: str @@ -236,6 +243,8 @@ class AwaitableGenerator( class AsyncIterable(Protocol[_T_co]): @abstractmethod def __aiter__(self) -> AsyncIterator[_T_co]: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... @runtime_checkable class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]): @@ -274,6 +283,8 @@ if sys.version_info >= (3, 6): class Container(Protocol[_T_co]): @abstractmethod def __contains__(self, __x: object) -> bool: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... if sys.version_info >= (3, 6): @runtime_checkable @@ -364,6 +375,8 @@ class MutableSet(AbstractSet[_T], Generic[_T]): class MappingView(Sized): def __init__(self, mapping: Mapping[_KT_co, _VT_co]) -> None: ... # undocumented def __len__(self) -> int: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class ItemsView(MappingView, AbstractSet[Tuple[_KT_co, _VT_co]], Generic[_KT_co, _VT_co]): def __init__(self, mapping: Mapping[_KT_co, _VT_co]) -> None: ... # undocumented @@ -568,6 +581,8 @@ class Match(Generic[AnyStr]): def regs(self) -> Tuple[Tuple[int, int], ...]: ... # undocumented if sys.version_info >= (3, 6): def __getitem__(self, g: Union[int, str]) -> AnyStr: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class Pattern(Generic[AnyStr]): flags: int @@ -589,6 +604,8 @@ class Pattern(Generic[AnyStr]): def subn(self, repl: AnyStr, string: AnyStr, count: int = ...) -> Tuple[AnyStr, int]: ... @overload def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> Tuple[AnyStr, int]: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... # Functions diff --git a/stdlib/3/unittest/case.pyi b/stdlib/3/unittest/case.pyi index 341b22b64..e3c23f8e9 100644 --- a/stdlib/3/unittest/case.pyi +++ b/stdlib/3/unittest/case.pyi @@ -28,6 +28,9 @@ from typing import ( ) from warnings import WarningMessage +if sys.version_info >= (3, 9): + from types import GenericAlias + _E = TypeVar("_E", bound=BaseException) _FT = TypeVar("_FT", bound=Callable[..., Any]) @@ -258,6 +261,8 @@ class _AssertRaisesContext(Generic[_E]): def __exit__( self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] ) -> bool: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class _AssertWarnsContext: warning: WarningMessage diff --git a/stdlib/3/urllib/parse.pyi b/stdlib/3/urllib/parse.pyi index 18032b839..91ef41888 100644 --- a/stdlib/3/urllib/parse.pyi +++ b/stdlib/3/urllib/parse.pyi @@ -2,6 +2,9 @@ import sys from typing import Any, AnyStr, Callable, Dict, Generic, List, Mapping, NamedTuple, Optional, Sequence, Tuple, Union, overload +if sys.version_info >= (3, 9): + from types import GenericAlias + _Str = Union[bytes, str] uses_relative: List[str] @@ -27,6 +30,8 @@ class _NetlocResultMixinBase(Generic[AnyStr]): password: Optional[AnyStr] hostname: Optional[AnyStr] port: Optional[int] + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class _NetlocResultMixinStr(_NetlocResultMixinBase[str], _ResultMixinStr): ... class _NetlocResultMixinBytes(_NetlocResultMixinBase[bytes], _ResultMixinBytes): ... diff --git a/third_party/2/concurrent/futures/_base.pyi b/third_party/2/concurrent/futures/_base.pyi index e84042f12..77ac77a3d 100644 --- a/third_party/2/concurrent/futures/_base.pyi +++ b/third_party/2/concurrent/futures/_base.pyi @@ -5,6 +5,9 @@ from logging import Logger from types import TracebackType from typing import Any, Callable, Container, Generic, Iterable, Iterator, List, Optional, Protocol, Set, Tuple, TypeVar +if sys.version_info >= (3, 9): + from types import GenericAlias + FIRST_COMPLETED: str FIRST_EXCEPTION: str ALL_COMPLETED: str @@ -54,6 +57,8 @@ class Future(Generic[_T]): def exception_info(self, timeout: Optional[float] = ...) -> Tuple[Any, Optional[TracebackType]]: ... def set_exception(self, exception: Any) -> None: ... def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class Executor: if sys.version_info >= (3, 9): diff --git a/third_party/2/concurrent/futures/thread.pyi b/third_party/2/concurrent/futures/thread.pyi index 75a4060ef..35b42f436 100644 --- a/third_party/2/concurrent/futures/thread.pyi +++ b/third_party/2/concurrent/futures/thread.pyi @@ -7,6 +7,9 @@ if sys.version_info >= (3, 7): from ._base import BrokenExecutor class BrokenThreadPool(BrokenExecutor): ... +if sys.version_info >= (3, 9): + from types import GenericAlias + _S = TypeVar("_S") class ThreadPoolExecutor(Executor): @@ -30,3 +33,5 @@ class _WorkItem(Generic[_S]): kwargs: Mapping[str, Any] def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... def run(self) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/third_party/2/pathlib2.pyi b/third_party/2/pathlib2.pyi index be94eb59a..3f3bfac51 100644 --- a/third_party/2/pathlib2.pyi +++ b/third_party/2/pathlib2.pyi @@ -6,6 +6,9 @@ from types import TracebackType from typing import IO, Any, BinaryIO, Generator, List, Optional, Sequence, Text, TextIO, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal +if sys.version_info >= (3, 9): + from types import GenericAlias + _P = TypeVar("_P", bound=PurePath) if sys.version_info >= (3, 6): @@ -52,6 +55,8 @@ class PurePath(_PurePathBase): def parents(self: _P) -> Sequence[_P]: ... @property def parent(self: _P) -> _P: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, type: Any) -> GenericAlias: ... class PurePosixPath(PurePath): ... class PureWindowsPath(PurePath): ... diff --git a/third_party/3/contextvars.pyi b/third_party/3/contextvars.pyi index 7310e752d..429d2037a 100644 --- a/third_party/3/contextvars.pyi +++ b/third_party/3/contextvars.pyi @@ -1,5 +1,9 @@ +import sys from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") class ContextVar(Generic[_T]): @@ -9,6 +13,8 @@ class ContextVar(Generic[_T]): def get(self, default: _T = ...) -> _T: ... def set(self, value: _T) -> Token[_T]: ... def reset(self, token: Token[_T]) -> None: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... class Token(Generic[_T]): @property @@ -16,6 +22,8 @@ class Token(Generic[_T]): @property def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express MISSING: ClassVar[object] + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... def copy_context() -> Context: ... diff --git a/third_party/3/dataclasses.pyi b/third_party/3/dataclasses.pyi index 25215f6ff..1f5b6b4d3 100644 --- a/third_party/3/dataclasses.pyi +++ b/third_party/3/dataclasses.pyi @@ -1,5 +1,9 @@ +import sys from typing import Any, Callable, Dict, Generic, Iterable, List, Mapping, Optional, Tuple, Type, TypeVar, Union, overload +if sys.version_info >= (3, 9): + from types import GenericAlias + _T = TypeVar("_T") class _MISSING_TYPE: ... @@ -32,6 +36,8 @@ class Field(Generic[_T]): init: bool compare: bool metadata: Mapping[str, Any] + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... # NOTE: Actual return type is 'Field[_T]', but we want to help type checkers # to understand the magic that happens at runtime. @@ -68,7 +74,10 @@ def fields(class_or_instance: Any) -> Tuple[Field[Any], ...]: ... def is_dataclass(obj: Any) -> bool: ... class FrozenInstanceError(AttributeError): ... -class InitVar(Generic[_T]): ... + +class InitVar(Generic[_T]): + if sys.version_info >= (3, 9): + def __class_getitem__(cls, type: Any) -> GenericAlias: ... def make_dataclass( cls_name: str,