| 1 |
# More complete stub for typing module. |
| 2 |
# |
| 3 |
# Use [typing fixtures/typing-full.pyi] to use this instead of lib-stub/typing.pyi |
| 4 |
# in a particular test case. |
| 5 |
# |
| 6 |
# Many of the definitions have special handling in the type checker, so they |
| 7 |
# can just be initialized to anything. |
| 8 |
|
| 9 |
from abc import abstractmethod, ABCMeta |
| 10 |
|
| 11 |
class GenericMeta(type): pass |
| 12 |
|
| 13 |
class _SpecialForm: |
| 14 |
def __getitem__(self, index: Any) -> Any: ... |
| 15 |
def __or__(self, other): ... |
| 16 |
def __ror__(self, other): ... |
| 17 |
class TypeVar: |
| 18 |
def __init__(self, name, *args, bound=None): ... |
| 19 |
def __or__(self, other): ... |
| 20 |
class ParamSpec: ... |
| 21 |
class TypeVarTuple: ... |
| 22 |
|
| 23 |
def cast(t, o): ... |
| 24 |
def assert_type(o, t): ... |
| 25 |
overload = 0 |
| 26 |
Any = object() |
| 27 |
Optional = 0 |
| 28 |
Generic = 0 |
| 29 |
Protocol = 0 |
| 30 |
Tuple = 0 |
| 31 |
_promote = 0 |
| 32 |
Type = 0 |
| 33 |
TypeForm = 0 |
| 34 |
no_type_check = 0 |
| 35 |
ClassVar = 0 |
| 36 |
Final = 0 |
| 37 |
TypedDict = 0 |
| 38 |
TypeGuard = 0 |
| 39 |
NoReturn = 0 |
| 40 |
NewType = 0 |
| 41 |
Self = 0 |
| 42 |
Unpack = 0 |
| 43 |
Callable: _SpecialForm |
| 44 |
Union: _SpecialForm |
| 45 |
Literal: _SpecialForm |
| 46 |
|
| 47 |
T = TypeVar('T') |
| 48 |
T_co = TypeVar('T_co', covariant=True) |
| 49 |
R_co = TypeVar('R_co', covariant=True) |
| 50 |
S_contra = TypeVar('S_contra', contravariant=True) |
| 51 |
U = TypeVar('U') |
| 52 |
V = TypeVar('V') |
| 53 |
S = TypeVar('S') |
| 54 |
|
| 55 |
def final(x: T) -> T: ... |
| 56 |
|
| 57 |
class NamedTuple(tuple[Any, ...]): ... |
| 58 |
|
| 59 |
# Note: definitions below are different from typeshed, variances are declared |
| 60 |
# to silence the protocol variance checks. Maybe it is better to use type: ignore? |
| 61 |
|
| 62 |
@runtime_checkable |
| 63 |
class Hashable(Protocol, metaclass=ABCMeta): |
| 64 |
@abstractmethod |
| 65 |
def __hash__(self) -> int: pass |
| 66 |
|
| 67 |
@runtime_checkable |
| 68 |
class Container(Protocol[T_co]): |
| 69 |
@abstractmethod |
| 70 |
# Use int because bool isn't in the default test builtins |
| 71 |
def __contains__(self, arg: object) -> int: pass |
| 72 |
|
| 73 |
@runtime_checkable |
| 74 |
class Sized(Protocol): |
| 75 |
@abstractmethod |
| 76 |
def __len__(self) -> int: pass |
| 77 |
|
| 78 |
@runtime_checkable |
| 79 |
class Iterable(Protocol[T_co]): |
| 80 |
@abstractmethod |
| 81 |
def __iter__(self) -> 'Iterator[T_co]': pass |
| 82 |
|
| 83 |
@runtime_checkable |
| 84 |
class Iterator(Iterable[T_co], Protocol): |
| 85 |
@abstractmethod |
| 86 |
def __next__(self) -> T_co: pass |
| 87 |
|
| 88 |
class Generator(Iterator[T_co], Generic[T_co, S_contra, R_co]): |
| 89 |
@abstractmethod |
| 90 |
def send(self, value: S_contra) -> T_co: pass |
| 91 |
|
| 92 |
@abstractmethod |
| 93 |
def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass |
| 94 |
|
| 95 |
@abstractmethod |
| 96 |
def close(self) -> None: pass |
| 97 |
|
| 98 |
@abstractmethod |
| 99 |
def __iter__(self) -> 'Generator[T_co, S_contra, R_co]': pass |
| 100 |
|
| 101 |
class AsyncGenerator(AsyncIterator[T_co], Generic[T_co, S_contra]): |
| 102 |
@abstractmethod |
| 103 |
def __anext__(self) -> Awaitable[T_co]: pass |
| 104 |
|
| 105 |
@abstractmethod |
| 106 |
def asend(self, value: S_contra) -> Awaitable[T_co]: pass |
| 107 |
|
| 108 |
@abstractmethod |
| 109 |
def athrow(self, typ: Any, val: Any=None, tb: Any=None) -> Awaitable[T_co]: pass |
| 110 |
|
| 111 |
@abstractmethod |
| 112 |
def aclose(self) -> Awaitable[T_co]: pass |
| 113 |
|
| 114 |
@abstractmethod |
| 115 |
def __aiter__(self) -> 'AsyncGenerator[T_co, S_contra]': pass |
| 116 |
|
| 117 |
@runtime_checkable |
| 118 |
class Awaitable(Protocol[T_co]): |
| 119 |
@abstractmethod |
| 120 |
def __await__(self) -> Generator[Any, Any, T_co]: pass |
| 121 |
|
| 122 |
class AwaitableGenerator( |
| 123 |
Awaitable[R_co], |
| 124 |
Generator[T_co, S_contra, R_co], |
| 125 |
Generic[T_co, S_contra, R_co, S], |
| 126 |
metaclass=ABCMeta |
| 127 |
): |
| 128 |
pass |
| 129 |
|
| 130 |
class Coroutine(Awaitable[R_co], Generic[T_co, S_contra, R_co]): |
| 131 |
@abstractmethod |
| 132 |
def send(self, value: S_contra) -> T_co: pass |
| 133 |
|
| 134 |
@abstractmethod |
| 135 |
def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass |
| 136 |
|
| 137 |
@abstractmethod |
| 138 |
def close(self) -> None: pass |
| 139 |
|
| 140 |
@runtime_checkable |
| 141 |
class AsyncIterable(Protocol[T_co]): |
| 142 |
@abstractmethod |
| 143 |
def __aiter__(self) -> 'AsyncIterator[T_co]': pass |
| 144 |
|
| 145 |
@runtime_checkable |
| 146 |
class AsyncIterator(AsyncIterable[T_co], Protocol): |
| 147 |
def __aiter__(self) -> 'AsyncIterator[T_co]': return self |
| 148 |
@abstractmethod |
| 149 |
def __anext__(self) -> Awaitable[T_co]: pass |
| 150 |
|
| 151 |
class Sequence(Iterable[T_co], Container[T_co]): |
| 152 |
@abstractmethod |
| 153 |
def __getitem__(self, n: Any) -> T_co: pass |
| 154 |
|
| 155 |
class MutableSequence(Sequence[T]): |
| 156 |
@abstractmethod |
| 157 |
def __setitem__(self, n: Any, o: T) -> None: pass |
| 158 |
|
| 159 |
class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta): |
| 160 |
def keys(self) -> Iterable[T]: pass # Approximate return type |
| 161 |
def __getitem__(self, key: T) -> T_co: pass |
| 162 |
@overload |
| 163 |
def get(self, key: T, /) -> Optional[T_co]: pass |
| 164 |
@overload |
| 165 |
def get(self, key: T, default: T_co, /) -> T_co: pass # type: ignore[misc] |
| 166 |
@overload |
| 167 |
def get(self, key: T, default: V, /) -> Union[T_co, V]: pass |
| 168 |
def values(self) -> Iterable[T_co]: pass # Approximate return type |
| 169 |
def __len__(self) -> int: ... |
| 170 |
def __contains__(self, arg: object) -> int: pass |
| 171 |
|
| 172 |
class MutableMapping(Mapping[T, U], metaclass=ABCMeta): |
| 173 |
def __setitem__(self, k: T, v: U) -> None: pass |
| 174 |
|
| 175 |
class SupportsInt(Protocol): |
| 176 |
def __int__(self) -> int: pass |
| 177 |
|
| 178 |
class SupportsFloat(Protocol): |
| 179 |
def __float__(self) -> float: pass |
| 180 |
|
| 181 |
class SupportsAbs(Protocol[T_co]): |
| 182 |
def __abs__(self) -> T_co: pass |
| 183 |
|
| 184 |
def runtime_checkable(cls: T) -> T: |
| 185 |
return cls |
| 186 |
|
| 187 |
class ContextManager(Generic[T_co]): |
| 188 |
def __enter__(self) -> T_co: pass |
| 189 |
# Use Any because not all the precise types are in the fixtures. |
| 190 |
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass |
| 191 |
|
| 192 |
TYPE_CHECKING = 1 |
| 193 |
|
| 194 |
# Fallback type for all typed dicts (does not exist at runtime). |
| 195 |
class _TypedDict(Mapping[str, object]): |
| 196 |
# Needed to make this class non-abstract. It is explicitly declared abstract in |
| 197 |
# typeshed, but we don't want to import abc here, as it would slow down the tests. |
| 198 |
def __iter__(self) -> Iterator[str]: ... |
| 199 |
def copy(self: T) -> T: ... |
| 200 |
# Using NoReturn so that only calls using the plugin hook can go through. |
| 201 |
def setdefault(self, k: NoReturn, default: object) -> object: ... |
| 202 |
# Mypy expects that 'default' has a type variable type. |
| 203 |
def pop(self, k: NoReturn, default: T = ...) -> object: ... |
| 204 |
def update(self: T, __m: T) -> None: ... |
| 205 |
def __delitem__(self, k: NoReturn) -> None: ... |
| 206 |
|
| 207 |
def dataclass_transform( |
| 208 |
*, |
| 209 |
eq_default: bool = ..., |
| 210 |
order_default: bool = ..., |
| 211 |
kw_only_default: bool = ..., |
| 212 |
field_specifiers: tuple[type[Any] | Callable[..., Any], ...] = ..., |
| 213 |
**kwargs: Any, |
| 214 |
) -> Callable[[T], T]: ... |
| 215 |
def override(__arg: T) -> T: ... |
| 216 |
|
| 217 |
# Was added in 3.11 |
| 218 |
def reveal_type(__obj: T) -> T: ... |
| 219 |
|
| 220 |
# Only exists in type checking time: |
| 221 |
def type_check_only(__func_or_class: T) -> T: ... |
| 222 |
|
| 223 |
# Was added in 3.12 |
| 224 |
@final |
| 225 |
class TypeAliasType: |
| 226 |
def __init__( |
| 227 |
self, name: str, value: Any, *, type_params: Tuple[Union[TypeVar, ParamSpec, TypeVarTuple], ...] = () |
| 228 |
) -> None: ... |
| 229 |
|
| 230 |
def __or__(self, other: Any) -> Any: ... |
| 231 |
def __ror__(self, other: Any) -> Any: ... |