MCPcopy Index your code
hub / github.com/ipython/ipython / extract_vars

Function extract_vars

IPython/utils/frame.py:27–55  ·  view source on GitHub ↗

Extract a set of variables by name from another frame. Parameters ---------- *names : str One or more variable names which will be extracted from the caller's frame. **kw : integer, optional How many frames in the stack to walk when looking for your variables

(*names: str, **kw: Any)

Source from the content-addressed store, hash-verified

25#-----------------------------------------------------------------------------
26
27def extract_vars(*names: str, **kw: Any) -> dict[str, Any]:
28 """Extract a set of variables by name from another frame.
29
30 Parameters
31 ----------
32 *names : str
33 One or more variable names which will be extracted from the caller's
34 frame.
35 **kw : integer, optional
36 How many frames in the stack to walk when looking for your variables.
37 The default is 0, which will use the frame where the call was made.
38
39 Examples
40 --------
41 ::
42
43 In [2]: def func(x):
44 ...: y = 1
45 ...: print(sorted(extract_vars('x','y').items()))
46 ...:
47
48 In [3]: func('hello')
49 [('x', 'hello'), ('y', 1)]
50 """
51
52 depth = kw.get('depth',0)
53
54 callerNS = sys._getframe(depth+1).f_locals
55 return dict((k,callerNS[k]) for k in names)
56
57
58def extract_vars_above(*names: str) -> dict[str, Any]:

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…