From 630f7183762c96833a306629289c7e9e67cdce27 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Wed, 9 Mar 2016 02:24:15 +0100 Subject: [PATCH] Improve Python 2.7 inspect stub This patch consists of: * Splitting and reordering the content into sections corresponding to the module's documentation sections * Implementing some missing functions * Adding TODOs for missing stuff (I may've missed something) The signature of isgenerator() (was: Any argument, is: argument of type object) is changed for consistency with other is* functions I added here, after some considerations I couldn't decide whether it should be object or Any - if object is not advised please let me know. --- stdlib/2.7/inspect.pyi | 73 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/stdlib/2.7/inspect.pyi b/stdlib/2.7/inspect.pyi index 1ea9fa4c5..0166966c4 100644 --- a/stdlib/2.7/inspect.pyi +++ b/stdlib/2.7/inspect.pyi @@ -1,14 +1,53 @@ # TODO incomplete -from typing import Any, List, Tuple, NamedTuple +from types import TracebackType, FrameType, ModuleType +from typing import Any, Callable, List, Optional, Tuple, NamedTuple -def isgenerator(object: Any) -> bool: ... +# Types and members +ModuleInfo = NamedTuple('ModuleInfo', [('name', str), + ('suffix', str), + ('mode', str), + ('module_type', int), + ]) +def getmembers(object: object, + predicate: Callable[[Any], bool] = ..., + ) -> List[Tuple[str, object]]: ... +def getmoduleinfo(path: str) -> Optional[ModuleInfo]: ... +def getmodulename(path: str) -> Optional[str]: ... -class _Frame: - ... -_FrameRecord = Tuple[_Frame, str, int, str, List[str], int] +def ismodule(object: object) -> bool: ... +def isclass(object: object) -> bool: ... +def ismethod(object: object) -> bool: ... +def isfunction(object: object) -> bool: ... +def isisgeneratorfunction(object: object) -> bool: ... +def isgenerator(object: object) -> bool: ... +def istraceback(object: object) -> bool: ... +def isframe(object: object) -> bool: ... +def iscode(object: object) -> bool: ... +def isbuiltin(object: object) -> bool: ... +def isroutine(object: object) -> bool: ... +def isabstract(object: object) -> bool: ... +def ismethoddescriptor(object: object) -> bool: ... +def isdatadescriptor(object: object) -> bool: ... +def isgetsetdescriptor(object: object) -> bool: ... +def ismemberdescriptor(object: object) -> bool: ... -def currentframe() -> _FrameRecord: ... -def stack(context: int = ...) -> List[_FrameRecord]: ... +# Retrieving source code +def getdoc(object: object) -> str: ... +def getcomments(object: object) -> str: ... +def getfile(object: object) -> str: ... +def getmodule(object: object) -> ModuleType: ... +def getsourcefile(object: object) -> str: ... +# TODO restrict to "module, class, method, function, traceback, frame, +# or code object" +def getsourcelines(object: object) -> Tuple[List[str], int]: ... +# TODO restrict to "a module, class, method, function, traceback, frame, +# or code object" +def getsource(object: object) -> str: ... +def cleandoc(doc: str) -> str: ... + +# Classes and functions +# TODO make the return type more specific +def getclasstree(classes: List[type], unique: bool = ...) -> Any: ... ArgSpec = NamedTuple('ArgSpec', [('args', List[str]), ('varargs', str), @@ -17,3 +56,23 @@ ArgSpec = NamedTuple('ArgSpec', [('args', List[str]), ]) def getargspec(func: object) -> ArgSpec: ... +# TODO make the return type more specific +def getargvalues(frame: FrameType) -> Any: ... +# TODO formatargspec +# TODO formatargvalues +def getmro(cls: type) -> Tuple[type, ...]: ... +# TODO getcallargs + +# The interpreter stack +# TODO getframeinfo +# TODO getouterframes +def getinnerframes(traceback: TracebackType, context: int = ...) -> List[FrameType]: + ... + +class _Frame: + ... +_FrameRecord = Tuple[_Frame, str, int, str, List[str], int] + +def currentframe() -> _FrameRecord: ... +def stack(context: int = ...) -> List[_FrameRecord]: ... +def trace(context: int = ...) -> List[_FrameRecord]: ...