|
| 1 | +from _typeshed import Self |
1 | 2 | import collections # Needed by aliases like DefaultDict, see mypy issue 2986
|
2 | 3 | import sys
|
3 | 4 | from abc import ABCMeta, abstractmethod
|
@@ -715,3 +716,52 @@ if sys.version_info >= (3, 7):
|
715 | 716 |
|
716 | 717 | if sys.version_info >= (3, 10):
|
717 | 718 | def is_typeddict(tp: Any) -> bool: ...
|
| 719 | + |
| 720 | +class _Final: |
| 721 | + """Mixin to prohibit subclassing""" |
| 722 | + |
| 723 | + def __init_subclass__(__cls, *args: object, **kwds: object): ... |
| 724 | + |
| 725 | + |
| 726 | +class _BaseGenericAlias(_Final, _root=True): |
| 727 | + __origin__: type |
| 728 | + def __init__(self, origin: type, *, inst: bool = ..., name: str | None = ...) -> None: |
| 729 | + self._inst = inst |
| 730 | + self._name = name |
| 731 | + self.__origin__ = origin |
| 732 | + |
| 733 | +_Params = Union[type, Tuple[type, ...]] |
| 734 | + |
| 735 | +class _GenericAlias(_BaseGenericAlias, _root=True): |
| 736 | + def __init__( |
| 737 | + self, |
| 738 | + origin: type, |
| 739 | + params: _Params, |
| 740 | + *, |
| 741 | + inst: bool = ..., |
| 742 | + name: str | None = ..., |
| 743 | + _typevar_types: type[TypeVar] = ..., |
| 744 | + _paramspec_tvars: bool = ..., |
| 745 | + ): |
| 746 | + self.__args__: tuple[type, ...] |
| 747 | + self.__parameters__: tuple[TypeVar, ...] |
| 748 | + self._typevar_types = _typevar_types |
| 749 | + self._paramspec_tvars = _paramspec_tvars |
| 750 | + self.__module__ = origin.__module__ |
| 751 | + # def __eq__(self, other: object) -> bool: |
| 752 | + # ... |
| 753 | + def __hash__(self) -> int: ... |
| 754 | + def __or__(self, right: object) -> _SpecialForm: ... |
| 755 | + def __ror__(self, left: object) -> _SpecialForm: ... |
| 756 | + def __getitem__(self: Self, params: _Params) -> Self: ... |
| 757 | + def copy_with(self: Self, params: _Params) -> Self: ... |
| 758 | + # def __reduce__(self): |
| 759 | + # if self._name: |
| 760 | + # origin = globals()[self._name] |
| 761 | + # else: |
| 762 | + # origin = self.__origin__ |
| 763 | + # args = tuple(self.__args__) |
| 764 | + # if len(args) == 1 and not isinstance(args[0], tuple): |
| 765 | + # args, = args |
| 766 | + # return operator.getitem, (origin, args) |
| 767 | + def __mro_entries__(self, bases: tuple[type, ...]) -> tuple[type, ...]: ... |
0 commit comments