Skip to content

Commit d470573

Browse files
committed
Stub for inspect.stack() and related classes
1 parent 520ae8c commit d470573

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

stubs/3.2/inspect.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Stubs for inspect
22

33
from typing import Any, Tuple, List, Callable
4+
from types import FrameType
45

56
_object = object
67

@@ -29,3 +30,5 @@ class ArgSpec(tuple):
2930
defaults = ... # type: tuple
3031

3132
def getargspec(func: object) -> ArgSpec: ...
33+
34+
def stack() -> List[Tuple[FrameType, str, int, str, List[str], int]]: ...

stubs/3.2/types.pyi

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# TODO this is work in progress
44

5-
from typing import Any
5+
from typing import Any, Callable, Dict, Sequence
66

77
class ModuleType:
88
__name__ = ... # type: str
@@ -12,8 +12,55 @@ class ModuleType:
1212
class MethodType: ...
1313
class BuiltinMethodType: ...
1414

15+
class CodeType:
16+
"""Create a code object. Not for the faint of heart."""
17+
def __init__(self,
18+
argcount: int,
19+
kwonlyargcount: int,
20+
nlocals: int,
21+
stacksize: int,
22+
flags: int,
23+
codestring: bytes,
24+
constants: Sequence[Any],
25+
names: Sequence[str],
26+
varnames: Sequence[str],
27+
filename: str,
28+
name: str,
29+
firstlineno: int,
30+
lnotab: bytes,
31+
freevars: Sequence[str] = (),
32+
cellvars: Sequence[str] = (),
33+
) -> None:
34+
self.co_argcount = argcount
35+
self.co_kwonlyargcount = kwonlyargcount
36+
self.co_nlocals = nlocals
37+
self.co_stacksize = stacksize
38+
self.co_flags = flags
39+
self.co_code = codestring
40+
self.co_consts = constants
41+
self.co_names = names
42+
self.co_varnames = varnames
43+
self.co_filename = filename
44+
self.co_name = name
45+
self.co_firstlineno = firstlineno
46+
self.co_lnotab = lnotab
47+
self.co_freevars = freevars
48+
self.co_cellvars = cellvars
49+
50+
class FrameType:
51+
f_back = ... # type: FrameType
52+
f_builtins = ... # type: Dict[str, Any]
53+
f_code = ... # type: CodeType
54+
f_globals = ... # type: Dict[str, Any]
55+
f_lasti = ... # type: int
56+
f_lineno = ... # type: int
57+
f_locals = ... # type: Dict[str, Any]
58+
f_trace = ... # type: Callable[[], None]
59+
60+
def clear(self) -> None: pass
61+
1562
class TracebackType:
16-
tb_frame = ... # type: Any
63+
tb_frame = ... # type: FrameType
1764
tb_lasti = ... # type: int
1865
tb_lineno = ... # type: int
19-
tb_next = ... # type: Any
66+
tb_next = ... # type: TracebackType

0 commit comments

Comments
 (0)