2 from typing import (AbstractSet, Any, Callable, Dict, Generator, List, Mapping,
\r
3 MutableMapping, NamedTuple, Optional, Sequence, Tuple,
\r
6 from types import CodeType, FrameType, ModuleType, TracebackType
\r
11 class EndOfBlock(Exception): ...
\r
19 decoratorhasargs: bool
\r
21 def tokeneater(self, type: int, token: str, srow_scol: Tuple[int, int],
\r
22 erow_ecol: Tuple[int, int], line: str) -> None: ...
\r
31 if sys.version_info >= (3, 5):
\r
33 CO_ITERABLE_COROUTINE: int
\r
34 if sys.version_info >= (3, 6):
\r
35 CO_ASYNC_GENERATOR: int
\r
36 TPFLAGS_IS_ABSTRACT: int
\r
38 if sys.version_info < (3, 6):
\r
39 ModuleInfo = NamedTuple('ModuleInfo', [('name', str),
\r
42 ('module_type', int),
\r
44 def getmoduleinfo(path: str) -> Optional[ModuleInfo]: ...
\r
46 def getmembers(object: object,
\r
47 predicate: Optional[Callable[[Any], bool]] = ...,
\r
48 ) -> List[Tuple[str, Any]]: ...
\r
49 def getmodulename(path: str) -> Optional[str]: ...
\r
51 def ismodule(object: object) -> bool: ...
\r
52 def isclass(object: object) -> bool: ...
\r
53 def ismethod(object: object) -> bool: ...
\r
54 def isfunction(object: object) -> bool: ...
\r
55 def isgeneratorfunction(object: object) -> bool: ...
\r
56 def isgenerator(object: object) -> bool: ...
\r
58 if sys.version_info >= (3, 5):
\r
59 def iscoroutinefunction(object: object) -> bool: ...
\r
60 def iscoroutine(object: object) -> bool: ...
\r
61 def isawaitable(object: object) -> bool: ...
\r
62 if sys.version_info >= (3, 6):
\r
63 def isasyncgenfunction(object: object) -> bool: ...
\r
64 def isasyncgen(object: object) -> bool: ...
\r
65 def istraceback(object: object) -> bool: ...
\r
66 def isframe(object: object) -> bool: ...
\r
67 def iscode(object: object) -> bool: ...
\r
68 def isbuiltin(object: object) -> bool: ...
\r
69 def isroutine(object: object) -> bool: ...
\r
70 def isabstract(object: object) -> bool: ...
\r
71 def ismethoddescriptor(object: object) -> bool: ...
\r
72 def isdatadescriptor(object: object) -> bool: ...
\r
73 def isgetsetdescriptor(object: object) -> bool: ...
\r
74 def ismemberdescriptor(object: object) -> bool: ...
\r
78 # Retrieving source code
\r
80 def findsource(object: object) -> Tuple[List[str], int]: ...
\r
81 def getabsfile(object: object) -> str: ...
\r
82 def getblock(lines: Sequence[str]) -> Sequence[str]: ...
\r
83 def getdoc(object: object) -> str: ...
\r
84 def getcomments(object: object) -> str: ...
\r
85 def getfile(object: object) -> str: ...
\r
86 def getmodule(object: object) -> ModuleType: ...
\r
87 def getsourcefile(object: object) -> str: ...
\r
88 # TODO restrict to "module, class, method, function, traceback, frame,
\r
90 def getsourcelines(object: object) -> Tuple[List[str], int]: ...
\r
91 # TODO restrict to "a module, class, method, function, traceback, frame,
\r
93 def getsource(object: object) -> str: ...
\r
94 def cleandoc(doc: str) -> str: ...
\r
95 def indentsize(line: str) -> int: ...
\r
99 # Introspecting callables with the Signature object
\r
101 def signature(callable: Callable[..., Any],
\r
103 follow_wrapped: bool = ...) -> 'Signature': ...
\r
107 parameters: Optional[Sequence['Parameter']] = ...,
\r
109 return_annotation: Any = ...) -> None: ...
\r
110 # TODO: can we be more specific here?
\r
111 empty: object = ...
\r
113 parameters: Mapping[str, 'Parameter']
\r
115 # TODO: can we be more specific here?
\r
116 return_annotation: Any
\r
118 def bind(self, *args: Any, **kwargs: Any) -> 'BoundArguments': ...
\r
119 def bind_partial(self, *args: Any, **kwargs: Any) -> 'BoundArguments': ...
\r
122 parameters: Optional[Sequence['Parameter']] = ...,
\r
123 return_annotation: Any = ...) -> 'Signature': ...
\r
125 if sys.version_info >= (3, 5):
\r
127 def from_callable(cls,
\r
128 obj: Callable[..., Any],
\r
130 follow_wrapped: bool = ...) -> 'Signature': ...
\r
132 # The name is the same as the enum's name in CPython
\r
133 class _ParameterKind: ...
\r
138 kind: _ParameterKind,
\r
140 default: Any = ...,
\r
141 annotation: Any = ...) -> None: ...
\r
147 kind: _ParameterKind
\r
148 POSITIONAL_ONLY: _ParameterKind = ...
\r
149 POSITIONAL_OR_KEYWORD: _ParameterKind = ...
\r
150 VAR_POSITIONAL: _ParameterKind = ...
\r
151 KEYWORD_ONLY: _ParameterKind = ...
\r
152 VAR_KEYWORD: _ParameterKind = ...
\r
156 name: Optional[str] = ...,
\r
157 kind: Optional[_ParameterKind] = ...,
\r
158 default: Any = ...,
\r
159 annotation: Any = ...) -> 'Parameter': ...
\r
161 class BoundArguments:
\r
162 arguments: MutableMapping[str, Any]
\r
163 args: Tuple[Any, ...]
\r
164 kwargs: Dict[str, Any]
\r
165 signature: Signature
\r
167 if sys.version_info >= (3, 5):
\r
168 def apply_defaults(self) -> None: ...
\r
172 # Classes and functions
\r
175 # TODO: The actual return type should be List[_ClassTreeItem] but mypy doesn't
\r
176 # seem to be supporting this at the moment:
\r
177 # _ClassTreeItem = Union[List['_ClassTreeItem'], Tuple[type, Tuple[type, ...]]]
\r
178 def getclasstree(classes: List[type], unique: bool = ...) -> Any: ...
\r
180 ArgSpec = NamedTuple('ArgSpec', [('args', List[str]),
\r
183 ('defaults', tuple),
\r
186 Arguments = NamedTuple('Arguments', [('args', List[str]),
\r
187 ('varargs', Optional[str]),
\r
188 ('varkw', Optional[str]),
\r
191 def getargs(co: CodeType) -> Arguments: ...
\r
192 def getargspec(func: object) -> ArgSpec: ...
\r
194 FullArgSpec = NamedTuple('FullArgSpec', [('args', List[str]),
\r
197 ('defaults', tuple),
\r
198 ('kwonlyargs', List[str]),
\r
199 ('kwonlydefaults', Dict[str, Any]),
\r
200 ('annotations', Dict[str, Any]),
\r
203 def getfullargspec(func: object) -> FullArgSpec: ...
\r
205 # TODO make the field types more specific here
\r
206 ArgInfo = NamedTuple('ArgInfo', [('args', List[str]),
\r
207 ('varargs', Optional[str]),
\r
208 ('keywords', Optional[str]),
\r
209 ('locals', Dict[str, Any]),
\r
212 def getargvalues(frame: FrameType) -> ArgInfo: ...
\r
213 def formatannotation(annotation: object, base_module: Optional[str] = ...) -> str: ...
\r
214 def formatannotationrelativeto(object: object) -> Callable[[object], str]: ...
\r
215 def formatargspec(args: List[str],
\r
216 varargs: Optional[str] = ...,
\r
217 varkw: Optional[str] = ...,
\r
218 defaults: Optional[Tuple[Any, ...]] = ...,
\r
219 kwonlyargs: Optional[List[str]] = ...,
\r
220 kwonlydefaults: Optional[Dict[str, Any]] = ...,
\r
221 annotations: Dict[str, Any] = ...,
\r
222 formatarg: Callable[[str], str] = ...,
\r
223 formatvarargs: Callable[[str], str] = ...,
\r
224 formatvarkw: Callable[[str], str] = ...,
\r
225 formatvalue: Callable[[Any], str] = ...,
\r
226 formatreturns: Callable[[Any], str] = ...,
\r
227 formatannotations: Callable[[Any], str] = ...,
\r
229 def formatargvalues(args: List[str],
\r
230 varargs: Optional[str] = ...,
\r
231 varkw: Optional[str] = ...,
\r
232 locals: Optional[Dict[str, Any]] = ...,
\r
233 formatarg: Optional[Callable[[str], str]] = ...,
\r
234 formatvarargs: Optional[Callable[[str], str]] = ...,
\r
235 formatvarkw: Optional[Callable[[str], str]] = ...,
\r
236 formatvalue: Optional[Callable[[Any], str]] = ...,
\r
238 def getmro(cls: type) -> Tuple[type, ...]: ...
\r
240 def getcallargs(func: Callable[..., Any],
\r
242 **kwds: Any) -> Dict[str, Any]: ...
\r
245 ClosureVars = NamedTuple('ClosureVars', [('nonlocals', Mapping[str, Any]),
\r
246 ('globals', Mapping[str, Any]),
\r
247 ('builtins', Mapping[str, Any]),
\r
248 ('unbound', AbstractSet[str]),
\r
250 def getclosurevars(func: Callable[..., Any]) -> ClosureVars: ...
\r
252 def unwrap(func: Callable[..., Any],
\r
254 stop: Callable[[Any], Any]) -> Any: ...
\r
258 # The interpreter stack
\r
261 Traceback = NamedTuple(
\r
267 ('code_context', List[str]),
\r
272 # Python 3.5+ (functions returning it used to return regular tuples)
\r
273 FrameInfo = NamedTuple('FrameInfo', [('frame', FrameType),
\r
277 ('code_context', List[str]),
\r
281 def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ...
\r
282 def getouterframes(frame: Any, context: int = ...) -> List[FrameInfo]: ...
\r
283 def getinnerframes(traceback: TracebackType, context: int = ...) -> List[FrameInfo]: ...
\r
284 def getlineno(frame: FrameType) -> int: ...
\r
285 def currentframe() -> Optional[FrameType]: ...
\r
286 def stack(context: int = ...) -> List[FrameInfo]: ...
\r
287 def trace(context: int = ...) -> List[FrameInfo]: ...
\r
290 # Fetching attributes statically
\r
293 def getattr_static(obj: object, attr: str, default: Optional[Any] = ...) -> Any: ...
\r
297 # Current State of Generators and Coroutines
\r
300 # TODO In the next two blocks of code, can we be more specific regarding the
\r
301 # type of the "enums"?
\r
307 def getgeneratorstate(generator: Generator[Any, Any, Any]) -> str: ...
\r
309 if sys.version_info >= (3, 5):
\r
312 CORO_SUSPENDED: str
\r
314 # TODO can we be more specific than "object"?
\r
315 def getcoroutinestate(coroutine: object) -> str: ...
\r
317 def getgeneratorlocals(generator: Generator[Any, Any, Any]) -> Dict[str, Any]: ...
\r
319 if sys.version_info >= (3, 5):
\r
320 # TODO can we be more specific than "object"?
\r
321 def getcoroutinelocals(coroutine: object) -> Dict[str, Any]: ...
\r
323 Attribute = NamedTuple('Attribute', [('name', str),
\r
325 ('defining_class', type),
\r
326 ('object', object),
\r
329 def classify_class_attrs(cls: type) -> List[Attribute]: ...
\r