mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 04:34:28 +08:00
Add __class_getitem__ to builtins generified in PEP 585 (#4184)
* Add __class_getitem__ to builtins generified in PEP 585 * Declare types.GenericAlias and use it in __class_getitem__
This commit is contained in:
@@ -26,6 +26,9 @@ if sys.version_info >= (3, 8):
|
||||
else:
|
||||
from typing_extensions import Literal
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
class _SupportsIndex(Protocol):
|
||||
def __index__(self) -> int: ...
|
||||
|
||||
@@ -128,6 +131,8 @@ class type(object):
|
||||
if sys.version_info >= (3,):
|
||||
@classmethod
|
||||
def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, Any]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class super(object):
|
||||
if sys.version_info >= (3,):
|
||||
@@ -920,6 +925,8 @@ class tuple(Sequence[_T_co], Generic[_T_co]):
|
||||
def index(self, __value: Any, __start: int = ..., __stop: int = ...) -> int: ...
|
||||
else:
|
||||
def index(self, __value: Any) -> int: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class function:
|
||||
# TODO not defined in builtins!
|
||||
@@ -983,6 +990,8 @@ class list(MutableSequence[_T], Generic[_T]):
|
||||
def __ge__(self, x: List[_T]) -> bool: ...
|
||||
def __lt__(self, x: List[_T]) -> bool: ...
|
||||
def __le__(self, x: List[_T]) -> bool: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
# NOTE: Keyword arguments are special. If they are used, _KT must include
|
||||
@@ -1034,6 +1043,8 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def __reversed__(self) -> Iterator[_KT]: ...
|
||||
def __str__(self) -> str: ...
|
||||
__hash__: None # type: ignore
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class set(MutableSet[_T], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T] = ...) -> None: ...
|
||||
@@ -1071,6 +1082,8 @@ class set(MutableSet[_T], Generic[_T]):
|
||||
def __ge__(self, s: AbstractSet[object]) -> bool: ...
|
||||
def __gt__(self, s: AbstractSet[object]) -> bool: ...
|
||||
__hash__: None # type: ignore
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class frozenset(AbstractSet[_T_co], Generic[_T_co]):
|
||||
def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ...
|
||||
@@ -1094,6 +1107,8 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
|
||||
def __lt__(self, s: AbstractSet[object]) -> bool: ...
|
||||
def __ge__(self, s: AbstractSet[object]) -> bool: ...
|
||||
def __gt__(self, s: AbstractSet[object]) -> bool: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class enumerate(Iterator[Tuple[int, _T]], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
|
||||
|
||||
@@ -26,6 +26,9 @@ if sys.version_info >= (3, 8):
|
||||
else:
|
||||
from typing_extensions import Literal
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
class _SupportsIndex(Protocol):
|
||||
def __index__(self) -> int: ...
|
||||
|
||||
@@ -128,6 +131,8 @@ class type(object):
|
||||
if sys.version_info >= (3,):
|
||||
@classmethod
|
||||
def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, Any]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class super(object):
|
||||
if sys.version_info >= (3,):
|
||||
@@ -920,6 +925,8 @@ class tuple(Sequence[_T_co], Generic[_T_co]):
|
||||
def index(self, __value: Any, __start: int = ..., __stop: int = ...) -> int: ...
|
||||
else:
|
||||
def index(self, __value: Any) -> int: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class function:
|
||||
# TODO not defined in builtins!
|
||||
@@ -983,6 +990,8 @@ class list(MutableSequence[_T], Generic[_T]):
|
||||
def __ge__(self, x: List[_T]) -> bool: ...
|
||||
def __lt__(self, x: List[_T]) -> bool: ...
|
||||
def __le__(self, x: List[_T]) -> bool: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
# NOTE: Keyword arguments are special. If they are used, _KT must include
|
||||
@@ -1034,6 +1043,8 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def __reversed__(self) -> Iterator[_KT]: ...
|
||||
def __str__(self) -> str: ...
|
||||
__hash__: None # type: ignore
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class set(MutableSet[_T], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T] = ...) -> None: ...
|
||||
@@ -1071,6 +1082,8 @@ class set(MutableSet[_T], Generic[_T]):
|
||||
def __ge__(self, s: AbstractSet[object]) -> bool: ...
|
||||
def __gt__(self, s: AbstractSet[object]) -> bool: ...
|
||||
__hash__: None # type: ignore
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class frozenset(AbstractSet[_T_co], Generic[_T_co]):
|
||||
def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ...
|
||||
@@ -1094,6 +1107,8 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
|
||||
def __lt__(self, s: AbstractSet[object]) -> bool: ...
|
||||
def __ge__(self, s: AbstractSet[object]) -> bool: ...
|
||||
def __gt__(self, s: AbstractSet[object]) -> bool: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
class enumerate(Iterator[Tuple[int, _T]], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
|
||||
|
||||
@@ -286,3 +286,11 @@ def prepare_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any]
|
||||
DynamicClassAttribute = property
|
||||
|
||||
def coroutine(f: Callable[..., Any]) -> CoroutineType: ...
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
class GenericAlias:
|
||||
__origin__: type
|
||||
__args__: Tuple[Any, ...]
|
||||
__parameters__: Tuple[Any, ...]
|
||||
def __init__(self, origin: type, args: Any): ...
|
||||
def __getattr__(self, name: str) -> Any: ... # incomplete
|
||||
|
||||
Reference in New Issue
Block a user