2 # Note, all classes "defined" here require special handling.
\r
4 # TODO parts of this should be conditional on version
\r
8 Any, Awaitable, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar,
\r
9 Union, overload, Type
\r
12 # ModuleType is exported from this module, but for circular import
\r
13 # reasons exists in its own stub file (with ModuleSpec and Loader).
\r
14 from _importlib_modulespec import ModuleType as ModuleType # Exported
\r
17 _T_co = TypeVar('_T_co', covariant=True)
\r
18 _T_contra = TypeVar('_T_contra', contravariant=True)
\r
19 _KT = TypeVar('_KT')
\r
20 _VT = TypeVar('_VT')
\r
23 cell_contents = ... # type: Any
\r
26 __closure__ = ... # type: Optional[Tuple[_Cell, ...]]
\r
27 __code__ = ... # type: CodeType
\r
28 __defaults__ = ... # type: Optional[Tuple[Any, ...]]
\r
29 __dict__ = ... # type: Dict[str, Any]
\r
30 __globals__ = ... # type: Dict[str, Any]
\r
31 __name__ = ... # type: str
\r
32 __qualname__ = ... # type: str
\r
33 __annotations__ = ... # type: Dict[str, Any]
\r
34 __kwdefaults__ = ... # type: Dict[str, Any]
\r
35 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
\r
36 def __get__(self, obj: Optional[object], type: Optional[type]) -> 'MethodType': ...
\r
37 LambdaType = FunctionType
\r
40 """Create a code object. Not for the faint of heart."""
\r
41 co_argcount = ... # type: int
\r
42 co_kwonlyargcount = ... # type: int
\r
43 co_nlocals = ... # type: int
\r
44 co_stacksize = ... # type: int
\r
45 co_flags = ... # type: int
\r
46 co_code = ... # type: bytes
\r
47 co_consts = ... # type: Tuple[Any, ...]
\r
48 co_names = ... # type: Tuple[str, ...]
\r
49 co_varnames = ... # type: Tuple[str, ...]
\r
50 co_filename = ... # type: Optional[str]
\r
51 co_name = ... # type: str
\r
52 co_firstlineno = ... # type: int
\r
53 co_lnotab = ... # type: bytes
\r
54 co_freevars = ... # type: Tuple[str, ...]
\r
55 co_cellvars = ... # type: Tuple[str, ...]
\r
59 kwonlyargcount: int,
\r
64 constants: Tuple[Any, ...],
\r
65 names: Tuple[str, ...],
\r
66 varnames: Tuple[str, ...],
\r
71 freevars: Tuple[str, ...] = ...,
\r
72 cellvars: Tuple[str, ...] = ...,
\r
75 class MappingProxyType(Mapping[_KT, _VT], Generic[_KT, _VT]):
\r
76 def __init__(self, mapping: Mapping[_KT, _VT]) -> None: ...
\r
77 def __getitem__(self, k: _KT) -> _VT: ...
\r
78 def __iter__(self) -> Iterator[_KT]: ...
\r
79 def __len__(self) -> int: ...
\r
81 class SimpleNamespace:
\r
82 def __init__(self, **kwargs: Any) -> None: ...
\r
83 def __getattribute__(self, name: str) -> Any: ...
\r
84 def __setattr__(self, name: str, value: Any) -> None: ...
\r
85 def __delattr__(self, name: str) -> None: ...
\r
87 class GeneratorType:
\r
88 gi_code = ... # type: CodeType
\r
89 gi_frame = ... # type: FrameType
\r
90 gi_running = ... # type: bool
\r
91 gi_yieldfrom = ... # type: Optional[GeneratorType]
\r
92 def __iter__(self) -> 'GeneratorType': ...
\r
93 def __next__(self) -> Any: ...
\r
94 def close(self) -> None: ...
\r
95 def send(self, arg: Any) -> Any: ...
\r
97 def throw(self, val: BaseException) -> Any: ...
\r
99 def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ...
\r
101 if sys.version_info >= (3, 6):
\r
102 class AsyncGeneratorType(Generic[_T_co, _T_contra]):
\r
103 ag_await: Optional[Awaitable[Any]]
\r
104 ag_frame: FrameType
\r
107 def __aiter__(self) -> Awaitable[AsyncGeneratorType[_T_co, _T_contra]]: ...
\r
108 def __anext__(self) -> Awaitable[_T_co]: ...
\r
109 def asend(self, val: _T_contra) -> Awaitable[_T_co]: ...
\r
111 def athrow(self, val: BaseException) -> Awaitable[_T_co]: ...
\r
113 def athrow(self, typ: Type[BaseException], val: BaseException, tb: TracebackType = ...) -> Awaitable[_T_co]: ...
\r
114 def aclose(self) -> Awaitable[_T_co]: ...
\r
116 class CoroutineType:
\r
117 cr_await = ... # type: Optional[Any]
\r
118 cr_code = ... # type: CodeType
\r
119 cr_frame = ... # type: FrameType
\r
120 cr_running = ... # type: bool
\r
121 def close(self) -> None: ...
\r
122 def send(self, arg: Any) -> Any: ...
\r
124 def throw(self, val: BaseException) -> Any: ...
\r
126 def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ...
\r
128 class _StaticFunctionType:
\r
129 """Fictional type to correct the type of MethodType.__func__.
\r
131 FunctionType is a descriptor, so mypy follows the descriptor protocol and
\r
132 converts MethodType.__func__ back to MethodType (the return type of
\r
133 FunctionType.__get__). But this is actually a special case; MethodType is
\r
134 implemented in C and its attribute access doesn't go through
\r
137 By wrapping FunctionType in _StaticFunctionType, we get the right result;
\r
138 similar to wrapping a function in staticmethod() at runtime to prevent it
\r
139 being bound as a method.
\r
141 def __get__(self, obj: Optional[object], type: Optional[type]) -> 'FunctionType': ...
\r
144 __func__ = ... # type: _StaticFunctionType
\r
145 __self__ = ... # type: object
\r
146 __name__ = ... # type: str
\r
147 __qualname__ = ... # type: str
\r
148 def __init__(self, func: Callable, obj: object) -> None: ...
\r
149 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
\r
150 class BuiltinFunctionType:
\r
151 __self__ = ... # type: Union[object, ModuleType]
\r
152 __name__ = ... # type: str
\r
153 __qualname__ = ... # type: str
\r
154 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
\r
155 BuiltinMethodType = BuiltinFunctionType
\r
157 class TracebackType:
\r
158 if sys.version_info >= (3, 7):
\r
159 def __init__(self, tb_next: Optional[TracebackType], tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ...
\r
160 tb_next: Optional[TracebackType]
\r
163 def tb_next(self) -> Optional[TracebackType]: ...
\r
164 # the rest are read-only even in 3.7
\r
166 def tb_frame(self) -> FrameType: ...
\r
168 def tb_lasti(self) -> int: ...
\r
170 def tb_lineno(self) -> int: ...
\r
173 f_back = ... # type: FrameType
\r
174 f_builtins = ... # type: Dict[str, Any]
\r
175 f_code = ... # type: CodeType
\r
176 f_globals = ... # type: Dict[str, Any]
\r
177 f_lasti = ... # type: int
\r
178 f_lineno = ... # type: int
\r
179 f_locals = ... # type: Dict[str, Any]
\r
180 f_trace = ... # type: Callable[[], None]
\r
181 if sys.version_info >= (3, 7):
\r
182 f_frace_lines: bool
\r
183 f_trace_opcodes: bool
\r
185 def clear(self) -> None: ...
\r
187 class GetSetDescriptorType:
\r
188 __name__ = ... # type: str
\r
189 __objclass__ = ... # type: type
\r
190 def __get__(self, obj: Any, type: type = ...) -> Any: ...
\r
191 def __set__(self, obj: Any) -> None: ...
\r
192 def __delete__(self, obj: Any) -> None: ...
\r
193 class MemberDescriptorType:
\r
194 __name__ = ... # type: str
\r
195 __objclass__ = ... # type: type
\r
196 def __get__(self, obj: Any, type: type = ...) -> Any: ...
\r
197 def __set__(self, obj: Any) -> None: ...
\r
198 def __delete__(self, obj: Any) -> None: ...
\r
200 def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ...
\r
201 def prepare_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ...) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ...
\r
203 # Actually a different type, but `property` is special and we want that too.
\r
204 DynamicClassAttribute = property
\r
206 def coroutine(f: Callable[..., Any]) -> CoroutineType: ...
\r