2 from importlib.abc import _LoaderProtocol
3 from importlib.machinery import ModuleSpec
24 from typing_extensions import Literal, ParamSpec, final
26 # Note, all classes "defined" here require special handling.
31 _T_co = TypeVar("_T_co", covariant=True)
32 _T_contra = TypeVar("_T_contra", contravariant=True)
34 _VT_co = TypeVar("_VT_co", covariant=True)
35 _V_co = TypeVar("_V_co", covariant=True)
39 __hash__: None # type: ignore
44 __closure__: Tuple[_Cell, ...] | None
46 __defaults__: Tuple[Any, ...] | None
47 __dict__: dict[str, Any]
48 __globals__: dict[str, Any]
51 __annotations__: dict[str, Any]
52 __kwdefaults__: dict[str, Any]
56 globals: dict[str, Any],
57 name: str | None = ...,
58 argdefs: Tuple[object, ...] | None = ...,
59 closure: Tuple[_Cell, ...] | None = ...,
61 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
62 def __get__(self, obj: object | None, type: type | None) -> MethodType: ...
64 LambdaType = FunctionType
68 """Create a code object. Not for the faint of heart."""
71 if sys.version_info >= (3, 8):
72 co_posonlyargcount: int
73 co_kwonlyargcount: int
78 co_consts: Tuple[Any, ...]
79 co_names: Tuple[str, ...]
80 co_varnames: Tuple[str, ...]
85 co_freevars: Tuple[str, ...]
86 co_cellvars: Tuple[str, ...]
87 if sys.version_info >= (3, 8):
97 constants: Tuple[Any, ...],
98 names: Tuple[str, ...],
99 varnames: Tuple[str, ...],
104 freevars: Tuple[str, ...] = ...,
105 cellvars: Tuple[str, ...] = ...,
116 constants: Tuple[Any, ...],
117 names: Tuple[str, ...],
118 varnames: Tuple[str, ...],
123 freevars: Tuple[str, ...] = ...,
124 cellvars: Tuple[str, ...] = ...,
126 if sys.version_info >= (3, 8):
130 co_argcount: int = ...,
131 co_posonlyargcount: int = ...,
132 co_kwonlyargcount: int = ...,
133 co_nlocals: int = ...,
134 co_stacksize: int = ...,
136 co_firstlineno: int = ...,
137 co_code: bytes = ...,
138 co_consts: Tuple[Any, ...] = ...,
139 co_names: Tuple[str, ...] = ...,
140 co_varnames: Tuple[str, ...] = ...,
141 co_freevars: Tuple[str, ...] = ...,
142 co_cellvars: Tuple[str, ...] = ...,
143 co_filename: str = ...,
145 co_lnotab: bytes = ...,
147 if sys.version_info >= (3, 11):
148 def co_positions(self) -> Iterable[tuple[int | None, int | None, int | None, int | None]]: ...
151 class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]):
152 __hash__: None # type: ignore
153 def __init__(self, mapping: Mapping[_KT, _VT_co]) -> None: ...
154 def __getitem__(self, k: _KT) -> _VT_co: ...
155 def __iter__(self) -> Iterator[_KT]: ...
156 def __len__(self) -> int: ...
157 def copy(self) -> dict[_KT, _VT_co]: ...
158 def keys(self) -> KeysView[_KT]: ...
159 def values(self) -> ValuesView[_VT_co]: ...
160 def items(self) -> ItemsView[_KT, _VT_co]: ...
161 if sys.version_info >= (3, 9):
162 def __class_getitem__(cls, item: Any) -> GenericAlias: ...
163 def __reversed__(self) -> Iterator[_KT]: ...
164 def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT_co | _T2]: ...
165 def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT_co | _T2]: ...
167 class SimpleNamespace:
168 __hash__: None # type: ignore
169 def __init__(self, **kwargs: Any) -> None: ...
170 def __getattribute__(self, name: str) -> Any: ...
171 def __setattr__(self, name: str, value: Any) -> None: ...
172 def __delattr__(self, name: str) -> None: ...
177 __dict__: dict[str, Any]
178 __loader__: _LoaderProtocol | None
179 __package__: str | None
180 __path__: MutableSequence[str]
181 __spec__: ModuleSpec | None
182 def __init__(self, name: str, doc: str | None = ...) -> None: ...
183 # __getattr__ doesn't exist at runtime,
184 # but having it here in typeshed makes dynamic imports
185 # using `builtins.__import__` or `importlib.import_module` less painful
186 def __getattr__(self, name: str) -> Any: ...
189 class GeneratorType(Generator[_T_co, _T_contra, _V_co]):
193 gi_yieldfrom: GeneratorType[_T_co, _T_contra, Any] | None
194 def __iter__(self) -> GeneratorType[_T_co, _T_contra, _V_co]: ...
195 def __next__(self) -> _T_co: ...
196 def close(self) -> None: ...
197 def send(self, __arg: _T_contra) -> _T_co: ...
200 self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
203 def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
206 class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]):
207 ag_await: Awaitable[Any] | None
211 def __aiter__(self) -> AsyncGeneratorType[_T_co, _T_contra]: ...
212 def __anext__(self) -> Awaitable[_T_co]: ...
213 def asend(self, __val: _T_contra) -> Awaitable[_T_co]: ...
216 self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
217 ) -> Awaitable[_T_co]: ...
219 def athrow(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> Awaitable[_T_co]: ...
220 def aclose(self) -> Awaitable[None]: ...
223 class CoroutineType(Coroutine[_T_co, _T_contra, _V_co]):
230 def close(self) -> None: ...
231 def __await__(self) -> Generator[Any, None, _V_co]: ...
232 def send(self, __arg: _T_contra) -> _T_co: ...
235 self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
238 def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
240 class _StaticFunctionType:
241 """Fictional type to correct the type of MethodType.__func__.
243 FunctionType is a descriptor, so mypy follows the descriptor protocol and
244 converts MethodType.__func__ back to MethodType (the return type of
245 FunctionType.__get__). But this is actually a special case; MethodType is
246 implemented in C and its attribute access doesn't go through
249 By wrapping FunctionType in _StaticFunctionType, we get the right result;
250 similar to wrapping a function in staticmethod() at runtime to prevent it
251 being bound as a method.
254 def __get__(self, obj: object | None, type: type | None) -> FunctionType: ...
258 __closure__: Tuple[_Cell, ...] | None # inherited from the added function
259 __defaults__: Tuple[Any, ...] | None # inherited from the added function
260 __func__: _StaticFunctionType
262 __name__: str # inherited from the added function
263 __qualname__: str # inherited from the added function
264 def __init__(self, func: Callable[..., Any], obj: object) -> None: ...
265 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
268 class BuiltinFunctionType:
269 __self__: object | ModuleType
272 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
274 BuiltinMethodType = BuiltinFunctionType
276 if sys.version_info >= (3, 7):
278 class WrapperDescriptorType:
282 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
283 def __get__(self, obj: Any, type: type = ...) -> Any: ...
285 class MethodWrapperType:
290 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
291 def __eq__(self, other: Any) -> bool: ...
292 def __ne__(self, other: Any) -> bool: ...
294 class MethodDescriptorType:
298 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
299 def __get__(self, obj: Any, type: type = ...) -> Any: ...
301 class ClassMethodDescriptorType:
305 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
306 def __get__(self, obj: Any, type: type = ...) -> Any: ...
310 if sys.version_info >= (3, 7):
311 def __init__(self, tb_next: TracebackType | None, tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ...
312 tb_next: TracebackType | None
315 def tb_next(self) -> TracebackType | None: ...
316 # the rest are read-only even in 3.7
318 def tb_frame(self) -> FrameType: ...
320 def tb_lasti(self) -> int: ...
322 def tb_lineno(self) -> int: ...
326 f_back: FrameType | None
327 f_builtins: dict[str, Any]
329 f_globals: dict[str, Any]
332 f_locals: dict[str, Any]
333 f_trace: Callable[[FrameType, str, Any], Any] | None
334 if sys.version_info >= (3, 7):
336 f_trace_opcodes: bool
337 def clear(self) -> None: ...
340 class GetSetDescriptorType:
343 def __get__(self, __obj: Any, __type: type = ...) -> Any: ...
344 def __set__(self, __instance: Any, __value: Any) -> None: ...
345 def __delete__(self, obj: Any) -> None: ...
348 class MemberDescriptorType:
351 def __get__(self, __obj: Any, __type: type = ...) -> Any: ...
352 def __set__(self, __instance: Any, __value: Any) -> None: ...
353 def __delete__(self, obj: Any) -> None: ...
355 if sys.version_info >= (3, 7):
358 bases: Iterable[object] = ...,
359 kwds: dict[str, Any] | None = ...,
360 exec_body: Callable[[dict[str, Any]], None] | None = ...,
362 def resolve_bases(bases: Iterable[object]) -> Tuple[Any, ...]: ...
367 bases: Tuple[type, ...] = ...,
368 kwds: dict[str, Any] | None = ...,
369 exec_body: Callable[[dict[str, Any]], None] | None = ...,
373 name: str, bases: Tuple[type, ...] = ..., kwds: dict[str, Any] | None = ...
374 ) -> tuple[type, dict[str, Any], dict[str, Any]]: ...
376 # Actually a different type, but `property` is special and we want that too.
377 DynamicClassAttribute = property
379 _Fn = TypeVar("_Fn", bound=Callable[..., object])
383 # it's not really an Awaitable, but can be used in an await expression. Real type: Generator & Awaitable
385 def coroutine(func: Callable[_P, Generator[_R, Any, Any]]) -> Callable[_P, Awaitable[_R]]: ... # type: ignore
387 def coroutine(func: _Fn) -> _Fn: ... # type: ignore
389 if sys.version_info >= (3, 8):
392 if sys.version_info >= (3, 9):
395 __args__: Tuple[Any, ...]
396 __parameters__: Tuple[Any, ...]
397 def __init__(self, origin: type, args: Any) -> None: ...
398 def __getattr__(self, name: str) -> Any: ... # incomplete
400 if sys.version_info >= (3, 10):
403 def __bool__(self) -> Literal[False]: ...
404 EllipsisType = ellipsis # noqa F811 from builtins
405 from builtins import _NotImplementedType
407 NotImplementedType = _NotImplementedType # noqa F811 from builtins
410 __args__: Tuple[Any, ...]
411 def __or__(self, obj: Any) -> UnionType: ...
412 def __ror__(self, obj: Any) -> UnionType: ...