Added __class_getitem__ (#4695)

Resolves #4682

Co-authored-by: hauntsaninja <>
This commit is contained in:
Utsav
2020-10-22 14:05:04 -07:00
committed by GitHub
co-authored by hauntsaninja <>
parent 5927e5ca30
commit 6f943d43ea
32 changed files with 205 additions and 6 deletions
+5
View File
@@ -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]: ...
+7 -1
View File
@@ -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]): ...
+5
View File
@@ -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]]: ...
+2
View File
@@ -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
+5
View File
@@ -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):
+5
View File
@@ -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: ...
+9
View File
@@ -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]: ...
+5
View File
@@ -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:
+6
View File
@@ -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
+6
View File
@@ -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: ...
+6 -1
View File
@@ -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: ...
+5
View File
@@ -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]):
+5
View File
@@ -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): ...
+7
View File
@@ -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: ...
+7
View File
@@ -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]: ...
+5
View File
@@ -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 = ...
+17
View File
@@ -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
+5
View File
@@ -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
+5
View File
@@ -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): ...