Format: application/x-python-code
⬇ Download File (2.9 KB)
   1  o
   2  
   3  ��h2�@sfdZddlZddlmZdd�Zdeefdd�Zdd
   4  edefdd
   5  �Zdde	de
   6  eeffdd�ZdS)z*
   7  Utilities for working with stack frames.
   8  �N)�Anycs2|�dd�}t�|d�j�t�fdd�|D��S)akExtract a set of variables by name from another frame.
   9  
  10      Parameters
  11      ----------
  12      *names : str
  13          One or more variable names which will be extracted from the caller's
  14          frame.
  15      **kw : integer, optional
  16          How many frames in the stack to walk when looking for your variables.
  17          The default is 0, which will use the frame where the call was made.
  18  
  19      Examples
  20      --------
  21      ::
  22  
  23          In [2]: def func(x):
  24             ...:     y = 1
  25             ...:     print(sorted(extract_vars('x','y').items()))
  26             ...:
  27  
  28          In [3]: func('hello')
  29          [('x', 'hello'), ('y', 1)]
  30      �depthr�c3��|]	}|�|fVqdS�N���.0�k�ZcallerNSr�Ic:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/frame.py�	<genexpr>4��zextract_vars.<locals>.<genexpr>)�get�sys�	_getframe�f_locals�dict)�names�kwrrrr�extract_varssrrcs"t�d�j�t�fdd�|D��S)ahExtract a set of variables by name from another frame.
  31  
  32      Similar to extractVars(), but with a specified depth of 1, so that names
  33      are extracted exactly from above the caller.
  34  
  35      This is simply a convenience function so that the very common case (for us)
  36      of skipping exactly 1 frame doesn't have to construct a special dict for
  37      keyword passing.�c3rrrrrrrr
  38  Brz%extract_vars_above.<locals>.<genexpr>)rrrr)rrrr�extract_vars_above7s
  39  r��expr�pre_msgc	Cs2t�d�}td|jj||t||j|j�f�dS)a�Print the value of an expression from the caller's frame.
  40  
  41      Takes an expression, evaluates it in the caller's frame and prints both
  42      the given expression and the resulting value (as well as a debug mark
  43      indicating the name of the calling function.  The input must be of a form
  44      suitable for eval().
  45  
  46      An optional message can be passed, which will be prepended to the printed
  47      expr->value pair.rz[DBG:%s] %s%s -> %rN)rr�print�f_code�co_name�eval�	f_globalsr)rr�cfrrr�debugxEs
  48  �r"r�returncCs,t�|d�}|j}tj|d}||jfS)zLReturns (module, locals) of the function `depth` frames away from the callerr�__name__)rrr �modulesr)r�f�	global_ns�modulerrr�extract_module_localsYs
  49  r))r)r)�__doc__r�typingrr�list�strrr"�int�tupler)rrrr�<module>s