Debian Codegraph @

mypyc/test-data/fixtures/typing-full.pyi

raw
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 class TypeVar:
16 def __init__(self, name: str, *args: Any, bound: Any = None): ...
17 def __or__(self, other: Any) -> Any: ...
18
19 cast = 0
20 overload = 0
21 Any = object()
22 Optional = 0
23 Generic = 0
24 Protocol = 0
25 Tuple = 0
26 _promote = 0
27 NamedTuple = 0
28 Type = 0
29 no_type_check = 0
30 ClassVar = 0
31 Final = 0
32 TypedDict = 0
33 NoReturn = 0
34 NewType = 0
35 Self = 0
36 Callable: _SpecialForm
37 Union: _SpecialForm
38 Literal: _SpecialForm
39
40 T = TypeVar('T')
41 T_co = TypeVar('T_co', covariant=True)
42 T_contra = TypeVar('T_contra', contravariant=True)
43 U = TypeVar('U')
44 V = TypeVar('V')
45 S = TypeVar('S')
46
47 # Note: definitions below are different from typeshed, variances are declared
48 # to silence the protocol variance checks. Maybe it is better to use type: ignore?
49
50 @runtime_checkable
51 class Container(Protocol[T_co]):
52 @abstractmethod
53 # Use int because bool isn't in the default test builtins
54 def __contains__(self, arg: object) -> int: pass
55
56 @runtime_checkable
57 class Sized(Protocol):
58 @abstractmethod
59 def __len__(self) -> int: pass
60
61 @runtime_checkable
62 class Iterable(Protocol[T_co]):
63 @abstractmethod
64 def __iter__(self) -> 'Iterator[T_co]': pass
65
66 @runtime_checkable
67 class Iterator(Iterable[T_co], Protocol):
68 @abstractmethod
69 def __next__(self) -> T_co: pass
70
71 class Generator(Iterator[T], Generic[T, U, V]):
72 @abstractmethod
73 def send(self, value: U) -> T: pass
74
75 @abstractmethod
76 def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass
77
78 @abstractmethod
79 def close(self) -> None: pass
80
81 @abstractmethod
82 def __iter__(self) -> 'Generator[T, U, V]': pass
83
84 class AsyncGenerator(AsyncIterator[T], Generic[T, U]):
85 @abstractmethod
86 def __anext__(self) -> Awaitable[T]: pass
87
88 @abstractmethod
89 def asend(self, value: U) -> Awaitable[T]: pass
90
91 @abstractmethod
92 def athrow(self, typ: Any, val: Any=None, tb: Any=None) -> Awaitable[T]: pass
93
94 @abstractmethod
95 def aclose(self) -> Awaitable[T]: pass
96
97 @abstractmethod
98 def __aiter__(self) -> 'AsyncGenerator[T, U]': pass
99
100 @runtime_checkable
101 class Awaitable(Protocol[T]):
102 @abstractmethod
103 def __await__(self) -> Generator[Any, Any, T]: pass
104
105 class AwaitableGenerator(Generator[T, U, V], Awaitable[V], Generic[T, U, V, S], metaclass=ABCMeta):
106 pass
107
108 class Coroutine(Awaitable[V], Generic[T, U, V]):
109 @abstractmethod
110 def send(self, value: U) -> T: pass
111
112 @abstractmethod
113 def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass
114
115 @abstractmethod
116 def close(self) -> None: pass
117
118 @runtime_checkable
119 class AsyncIterable(Protocol[T]):
120 @abstractmethod
121 def __aiter__(self) -> 'AsyncIterator[T]': pass
122
123 @runtime_checkable
124 class AsyncIterator(AsyncIterable[T], Protocol):
125 def __aiter__(self) -> 'AsyncIterator[T]': return self
126 @abstractmethod
127 def __anext__(self) -> Awaitable[T]: pass
128
129 class Sequence(Iterable[T_co], Container[T_co]):
130 @abstractmethod
131 def __getitem__(self, n: Any) -> T_co: pass
132
133 class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
134 def keys(self) -> Iterable[T]: pass # Approximate return type
135 def __getitem__(self, key: T) -> T_co: pass
136 @overload
137 def get(self, k: T) -> Optional[T_co]: pass
138 @overload
139 def get(self, k: T, default: Union[T_co, V]) -> Union[T_co, V]: pass
140 def values(self) -> Iterable[T_co]: pass # Approximate return type
141 def items(self) -> Iterable[Tuple[T, T_co]]: pass # Approximate return type
142 def __len__(self) -> int: ...
143 def __contains__(self, arg: object) -> int: pass
144
145 class MutableMapping(Mapping[T, U], metaclass=ABCMeta):
146 def __setitem__(self, k: T, v: U) -> None: pass
147
148 class SupportsInt(Protocol):
149 def __int__(self) -> int: pass
150
151 class SupportsFloat(Protocol):
152 def __float__(self) -> float: pass
153
154 def runtime_checkable(cls: T) -> T:
155 return cls
156
157 class ContextManager(Generic[T]):
158 def __enter__(self) -> T: pass
159 # Use Any because not all the precise types are in the fixtures.
160 def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass
161
162 TYPE_CHECKING = 1
163
164 # Fallback type for all typed dicts (does not exist at runtime).
165 class _TypedDict(Mapping[str, object]):
166 # Needed to make this class non-abstract. It is explicitly declared abstract in
167 # typeshed, but we don't want to import abc here, as it would slow down the tests.
168 def __iter__(self) -> Iterator[str]: ...
169 def copy(self: T) -> T: ...
170 # Using NoReturn so that only calls using the plugin hook can go through.
171 def setdefault(self, k: NoReturn, default: object) -> object: ...
172 # Mypy expects that 'default' has a type variable type.
173 def pop(self, k: NoReturn, default: T = ...) -> object: ...
174 def update(self: T, __m: T) -> None: ...
175 def __delitem__(self, k: NoReturn) -> None: ...
176
177 class TypeAliasType:
178 pass