| 1 |
# Test stub for typing module that includes TypedDict related things. |
| 2 |
# |
| 3 |
# Use [typing fixtures/typing-typeddict.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 ABCMeta |
| 10 |
|
| 11 |
cast = 0 |
| 12 |
assert_type = 0 |
| 13 |
overload = 0 |
| 14 |
Any = object() |
| 15 |
Union = 0 |
| 16 |
Optional = 0 |
| 17 |
TypeVar = 0 |
| 18 |
Generic = 0 |
| 19 |
Protocol = 0 |
| 20 |
Tuple = 0 |
| 21 |
Callable = 0 |
| 22 |
NamedTuple = 0 |
| 23 |
Final = 0 |
| 24 |
Literal = 0 |
| 25 |
TypedDict = 0 |
| 26 |
NoReturn = 0 |
| 27 |
NewType = 0 |
| 28 |
Required = 0 |
| 29 |
NotRequired = 0 |
| 30 |
ReadOnly = 0 |
| 31 |
Self = 0 |
| 32 |
ClassVar = 0 |
| 33 |
|
| 34 |
T = TypeVar('T') |
| 35 |
T_co = TypeVar('T_co', covariant=True) |
| 36 |
V = TypeVar('V') |
| 37 |
|
| 38 |
# Note: definitions below are different from typeshed, variances are declared |
| 39 |
# to silence the protocol variance checks. Maybe it is better to use type: ignore? |
| 40 |
|
| 41 |
class Sized(Protocol): |
| 42 |
def __len__(self) -> int: pass |
| 43 |
|
| 44 |
class Iterable(Protocol[T_co]): |
| 45 |
def __iter__(self) -> 'Iterator[T_co]': pass |
| 46 |
|
| 47 |
class Iterator(Iterable[T_co], Protocol): |
| 48 |
def __next__(self) -> T_co: pass |
| 49 |
|
| 50 |
class Sequence(Iterable[T_co]): |
| 51 |
def __getitem__(self, n: Any) -> T_co: pass # type: ignore[explicit-any] |
| 52 |
|
| 53 |
class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta): |
| 54 |
def keys(self) -> Iterable[T]: pass # Approximate return type |
| 55 |
def __getitem__(self, key: T) -> T_co: pass |
| 56 |
@overload |
| 57 |
def get(self, key: T, /) -> Optional[T_co]: pass |
| 58 |
@overload |
| 59 |
def get(self, key: T, default: T_co, /) -> T_co: pass # type: ignore[misc] |
| 60 |
@overload |
| 61 |
def get(self, key: T, default: V, /) -> Union[T_co, V]: pass |
| 62 |
def values(self) -> Iterable[T_co]: pass # Approximate return type |
| 63 |
def __len__(self) -> int: ... |
| 64 |
def __contains__(self, arg: object) -> int: pass |
| 65 |
|
| 66 |
class MutableMapping(Mapping[T, V], Generic[T, V], metaclass=ABCMeta): |
| 67 |
# Other methods are not used in tests. |
| 68 |
def clear(self) -> None: ... |
| 69 |
|
| 70 |
# Fallback type for all typed dicts (does not exist at runtime). |
| 71 |
class _TypedDict(Mapping[str, object]): |
| 72 |
# Needed to make this class non-abstract. It is explicitly declared abstract in |
| 73 |
# typeshed, but we don't want to import abc here, as it would slow down the tests. |
| 74 |
def __iter__(self) -> Iterator[str]: ... |
| 75 |
def copy(self: T) -> T: ... |
| 76 |
# Using NoReturn so that only calls using the plugin hook can go through. |
| 77 |
def setdefault(self, k: NoReturn, default: object) -> object: ... |
| 78 |
# Mypy expects that 'default' has a type variable type. |
| 79 |
def pop(self, k: NoReturn, default: T = ...) -> object: ... |
| 80 |
def update(self: T, __m: T) -> None: ... |
| 81 |
def __delitem__(self, k: NoReturn) -> None: ... |
| 82 |
|
| 83 |
class _SpecialForm: pass |