Added __class_getitem__ (#4695)

Resolves #4682

Co-authored-by: hauntsaninja <>
This commit is contained in:
Utsav
2020-10-23 02:35:04 +05:30
committed by GitHub
parent 5927e5ca30
commit 6f943d43ea
32 changed files with 205 additions and 6 deletions

View File

@@ -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

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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

View File

@@ -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: ...

View File

@@ -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: ...