Skip to content

Commit 132583c

Browse files
DetachHeadKotlinIsland
authored andcommitted
add _GenericAlias stub to typeshed
1 parent 1bf48b1 commit 132583c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

mypy/typeshed/stdlib/typing.pyi

+47
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Self
12
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
23
import sys
34
from abc import ABCMeta, abstractmethod
@@ -715,3 +716,49 @@ if sys.version_info >= (3, 7):
715716

716717
if sys.version_info >= (3, 10):
717718
def is_typeddict(tp: Any) -> bool: ...
719+
720+
class _Final:
721+
"""Mixin to prohibit subclassing"""
722+
723+
class _BaseGenericAlias(_Final, _root=True):
724+
__origin__: type
725+
def __init__(self, origin: type, *, inst: bool = ..., name: str | None = ...) -> None:
726+
self._inst = inst
727+
self._name = name
728+
self.__origin__ = origin
729+
730+
_Params = Union[type, Tuple[type, ...]]
731+
732+
class _GenericAlias(_BaseGenericAlias, _root=True):
733+
def __init__(
734+
self,
735+
origin: type,
736+
params: _Params,
737+
*,
738+
inst: bool = ...,
739+
name: str | None = ...,
740+
_typevar_types: type[TypeVar] = ...,
741+
_paramspec_tvars: bool = ...,
742+
):
743+
self.__args__: tuple[type, ...]
744+
self.__parameters__: tuple[TypeVar, ...]
745+
self._typevar_types = _typevar_types
746+
self._paramspec_tvars = _paramspec_tvars
747+
self.__module__ = origin.__module__
748+
# def __eq__(self, other: object) -> bool:
749+
# ...
750+
def __hash__(self) -> int: ...
751+
def __or__(self, right: object) -> _SpecialForm: ...
752+
def __ror__(self, left: object) -> _SpecialForm: ...
753+
def __getitem__(self: Self, params: _Params) -> Self: ...
754+
def copy_with(self: Self, params: _Params) -> Self: ...
755+
# def __reduce__(self):
756+
# if self._name:
757+
# origin = globals()[self._name]
758+
# else:
759+
# origin = self.__origin__
760+
# args = tuple(self.__args__)
761+
# if len(args) == 1 and not isinstance(args[0], tuple):
762+
# args, = args
763+
# return operator.getitem, (origin, args)
764+
def __mro_entries__(self, bases: tuple[type, ...]) -> tuple[type, ...]: ...

0 commit comments

Comments
 (0)