mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Add undocumented but occasionally used attributes to inspect.pyi. (#1864)
* Add attributes not in docs to 2/inspect.pyi. * Add attributes not in docs to 3/inspect.pyi. * Change list to List[Any] in 2/inspect.pyi
This commit is contained in:
@@ -1,7 +1,27 @@
|
||||
from types import TracebackType, FrameType, ModuleType
|
||||
from typing import Any, Dict, Callable, List, Optional, Tuple, Union, NamedTuple, Type
|
||||
from types import CodeType, TracebackType, FrameType, ModuleType
|
||||
from typing import Any, Dict, Callable, List, NamedTuple, Optional, Sequence, Tuple, Type, Union
|
||||
|
||||
# Types and members
|
||||
class EndOfBlock(Exception): ...
|
||||
|
||||
class BlockFinder:
|
||||
indent: int
|
||||
islambda: bool
|
||||
started: bool
|
||||
passline: bool
|
||||
last: int
|
||||
def tokeneater(self, type: int, token: str, srow_scol: Tuple[int, int],
|
||||
erow_ecol: Tuple[int, int], line: str) -> None: ...
|
||||
|
||||
CO_GENERATOR = ... # type: int
|
||||
CO_NESTED = ... # type: int
|
||||
CO_NEWLOCALS = ... # type: int
|
||||
CO_NOFREE = ... # type: int
|
||||
CO_OPTIMIZED = ... # type: int
|
||||
CO_VARARGS = ... # type: int
|
||||
CO_VARKEYWORDS = ... # type: int
|
||||
TPFLAGS_IS_ABSTRACT = ... # type: int
|
||||
|
||||
ModuleInfo = NamedTuple('ModuleInfo', [('name', str),
|
||||
('suffix', str),
|
||||
('mode', str),
|
||||
@@ -32,6 +52,9 @@ def isgetsetdescriptor(object: object) -> bool: ...
|
||||
def ismemberdescriptor(object: object) -> bool: ...
|
||||
|
||||
# Retrieving source code
|
||||
def findsource(object: object) -> Tuple[List[str], int]: ...
|
||||
def getabsfile(object: object) -> str: ...
|
||||
def getblock(lines: Sequence[str]) -> Sequence[str]: ...
|
||||
def getdoc(object: object) -> str: ...
|
||||
def getcomments(object: object) -> str: ...
|
||||
def getfile(object: object) -> str: ...
|
||||
@@ -44,6 +67,7 @@ def getsourcelines(object: object) -> Tuple[List[str], int]: ...
|
||||
# or code object"
|
||||
def getsource(object: object) -> str: ...
|
||||
def cleandoc(doc: str) -> str: ...
|
||||
def indentsize(line: str) -> int: ...
|
||||
|
||||
# Classes and functions
|
||||
def getclasstree(classes: List[type], unique: bool = ...) -> List[
|
||||
@@ -61,6 +85,12 @@ ArgInfo = NamedTuple('ArgInfo', [('args', List[str]),
|
||||
('locals', Dict[str, Any]),
|
||||
])
|
||||
|
||||
Arguments = NamedTuple('Arguments', [('args', List[Union[str, List[Any]]]),
|
||||
('varargs', Optional[str]),
|
||||
('keywords', Optional[str]),
|
||||
])
|
||||
|
||||
def getargs(co: CodeType) -> Arguments: ...
|
||||
def getargspec(func: object) -> ArgSpec: ...
|
||||
def getargvalues(frame: FrameType) -> ArgInfo: ...
|
||||
def formatargspec(args, varargs=..., varkw=..., defaults=...,
|
||||
@@ -90,7 +120,16 @@ _FrameInfo = Tuple[FrameType, str, int, str, List[str], int]
|
||||
def getouterframes(frame: FrameType, context: int = ...) -> List[_FrameInfo]: ...
|
||||
def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ...
|
||||
def getinnerframes(traceback: TracebackType, context: int = ...) -> List[_FrameInfo]: ...
|
||||
def getlineno(frame: FrameType) -> int: ...
|
||||
|
||||
def currentframe(depth: int = ...) -> FrameType: ...
|
||||
def stack(context: int = ...) -> List[_FrameInfo]: ...
|
||||
def trace(context: int = ...) -> List[_FrameInfo]: ...
|
||||
|
||||
Attribute = NamedTuple('Attribute', [('name', str),
|
||||
('kind', str),
|
||||
('defining_class', type),
|
||||
('object', object),
|
||||
])
|
||||
|
||||
def classify_class_attrs(cls: type) -> List[Attribute]: ...
|
||||
|
||||
@@ -1,12 +1,35 @@
|
||||
import sys
|
||||
from typing import (AbstractSet, Any, Tuple, List, Dict, Callable, Generator,
|
||||
Mapping, MutableMapping, NamedTuple, Optional, Sequence, Union,
|
||||
from typing import (AbstractSet, Any, Callable, Dict, Generator, List, Mapping,
|
||||
MutableMapping, NamedTuple, Optional, Sequence, Tuple,
|
||||
Union,
|
||||
)
|
||||
from types import FrameType, ModuleType, TracebackType
|
||||
from types import CodeType, FrameType, ModuleType, TracebackType
|
||||
|
||||
#
|
||||
# Types and members
|
||||
#
|
||||
class EndOfBlock(Exception): ...
|
||||
|
||||
class BlockFinder:
|
||||
indent: int
|
||||
islambda: bool
|
||||
started: bool
|
||||
passline: bool
|
||||
indecorator: bool
|
||||
decoratorhasargs: bool
|
||||
last: int
|
||||
def tokeneater(self, type: int, token: str, srow_scol: Tuple[int, int],
|
||||
erow_ecol: Tuple[int, int], line: str) -> None: ...
|
||||
|
||||
CO_GENERATOR = ... # type: int
|
||||
CO_NESTED = ... # type: int
|
||||
CO_NEWLOCALS = ... # type: int
|
||||
CO_NOFREE = ... # type: int
|
||||
CO_OPTIMIZED = ... # type: int
|
||||
CO_VARARGS = ... # type: int
|
||||
CO_VARKEYWORDS = ... # type: int
|
||||
TPFLAGS_IS_ABSTRACT = ... # type: int
|
||||
|
||||
if sys.version_info < (3, 6):
|
||||
ModuleInfo = NamedTuple('ModuleInfo', [('name', str),
|
||||
('suffix', str),
|
||||
@@ -47,6 +70,9 @@ def ismemberdescriptor(object: object) -> bool: ...
|
||||
#
|
||||
# Retrieving source code
|
||||
#
|
||||
def findsource(object: object) -> Tuple[List[str], int]: ...
|
||||
def getabsfile(object: object) -> str: ...
|
||||
def getblock(lines: Sequence[str]) -> Sequence[str]: ...
|
||||
def getdoc(object: object) -> str: ...
|
||||
def getcomments(object: object) -> str: ...
|
||||
def getfile(object: object) -> str: ...
|
||||
@@ -59,6 +85,7 @@ def getsourcelines(object: object) -> Tuple[List[str], int]: ...
|
||||
# or code object"
|
||||
def getsource(object: object) -> str: ...
|
||||
def cleandoc(doc: str) -> str: ...
|
||||
def indentsize(line: str) -> int: ...
|
||||
|
||||
|
||||
#
|
||||
@@ -149,6 +176,12 @@ ArgSpec = NamedTuple('ArgSpec', [('args', List[str]),
|
||||
('defaults', tuple),
|
||||
])
|
||||
|
||||
Arguments = NamedTuple('Arguments', [('args', List[str]),
|
||||
('varargs', Optional[str]),
|
||||
('varkw', Optional[str]),
|
||||
])
|
||||
|
||||
def getargs(co: CodeType) -> Arguments: ...
|
||||
def getargspec(func: object) -> ArgSpec: ...
|
||||
|
||||
FullArgSpec = NamedTuple('FullArgSpec', [('args', List[str]),
|
||||
@@ -170,6 +203,8 @@ ArgInfo = NamedTuple('ArgInfo', [('args', List[str]),
|
||||
])
|
||||
|
||||
def getargvalues(frame: FrameType) -> ArgInfo: ...
|
||||
def formatannotation(annotation: object, base_module: Optional[str] = None) -> str: ...
|
||||
def formatannotationrelativeto(object: object) -> Callable[[object], str]: ...
|
||||
def formatargspec(args: List[str],
|
||||
varargs: Optional[str] = ...,
|
||||
varkw: Optional[str] = ...,
|
||||
@@ -219,6 +254,17 @@ def unwrap(func: Callable[..., Any],
|
||||
# The interpreter stack
|
||||
#
|
||||
|
||||
Traceback = NamedTuple(
|
||||
'Traceback',
|
||||
[
|
||||
('filename', str),
|
||||
('lineno', int),
|
||||
('function', str),
|
||||
('code_context', List[str]),
|
||||
('index', int),
|
||||
]
|
||||
)
|
||||
|
||||
# Python 3.5+ (functions returning it used to return regular tuples)
|
||||
FrameInfo = NamedTuple('FrameInfo', [('frame', FrameType),
|
||||
('filename', str),
|
||||
@@ -228,11 +274,10 @@ FrameInfo = NamedTuple('FrameInfo', [('frame', FrameType),
|
||||
('index', int),
|
||||
])
|
||||
|
||||
# TODO make the frame type more specific
|
||||
def getframeinfo(frame: Any, context: int = ...) -> FrameInfo: ...
|
||||
def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ...
|
||||
def getouterframes(frame: Any, context: int = ...) -> List[FrameInfo]: ...
|
||||
def getinnerframes(traceback: TracebackType, context: int = ...) -> List[FrameInfo]:
|
||||
...
|
||||
def getinnerframes(traceback: TracebackType, context: int = ...) -> List[FrameInfo]: ...
|
||||
def getlineno(frame: FrameType) -> int: ...
|
||||
def currentframe() -> Optional[FrameType]: ...
|
||||
def stack(context: int = ...) -> List[FrameInfo]: ...
|
||||
def trace(context: int = ...) -> List[FrameInfo]: ...
|
||||
@@ -274,17 +319,10 @@ def getgeneratorlocals(generator: Generator[Any, Any, Any]) -> Dict[str, Any]: .
|
||||
# TODO can we be more specific than "object"?
|
||||
def getcoroutinelocals(coroutine: object) -> Dict[str, Any]: ...
|
||||
|
||||
|
||||
#
|
||||
# The following seems undocumented but it was already present in this file
|
||||
#
|
||||
_object = object
|
||||
|
||||
# namedtuple('Attribute', 'name kind defining_class object')
|
||||
class Attribute(tuple):
|
||||
name = ... # type: str
|
||||
kind = ... # type: str
|
||||
defining_class = ... # type: type
|
||||
object = ... # type: _object
|
||||
Attribute = NamedTuple('Attribute', [('name', str),
|
||||
('kind', str),
|
||||
('defining_class', type),
|
||||
('object', object),
|
||||
])
|
||||
|
||||
def classify_class_attrs(cls: type) -> List[Attribute]: ...
|
||||
|
||||
Reference in New Issue
Block a user