Format: application/x-python-code
⬇ Download File (4.4 KB)
   1  o
   2  
   3  �hD�@sxdZddlmZddlmZddlmZdZ	dZ	dZ		dZ
   4  	Gd	d
   5  �d
   6  �Zedd��Zefd
   7  d�Z
   8  Gdd�d�ZdS)a
   9  Recursions are the recipe of |jedi| to conquer Python code. However, someone
  10  must stop recursions going mad. Some settings are here to make |jedi| stop at
  11  the right time. You can read more about them :ref:`here <settings-recursion>`.
  12  
  13  Next to the internal ``jedi.inference.cache`` this module also makes |jedi| not
  14  thread-safe, because ``execution_recursion_decorator`` uses class variables to
  15  count the function calls.
  16  
  17  .. _settings-recursion:
  18  
  19  Settings
  20  ~~~~~~~~~~
  21  
  22  Recursion settings are important if you don't want extremely
  23  recursive python code to go absolutely crazy.
  24  
  25  The default values are based on experiments while completing the |jedi| library
  26  itself (inception!). But I don't think there's any other Python library that
  27  uses recursion in a similarly extreme way. Completion should also be fast and
  28  therefore the quality might not always be maximal.
  29  
  30  .. autodata:: recursion_limit
  31  .. autodata:: total_function_execution_limit
  32  .. autodata:: per_function_execution_limit
  33  .. autodata:: per_function_recursion_limit
  34  �)�contextmanager)�debug)�	NO_VALUES�����c@seZdZdd�ZdS)�RecursionDetectorcCs
  35  g|_dS�N)�pushed_nodes��self�r�Nc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/recursion.py�__init__6s
  36  zRecursionDetector.__init__N)�__name__�
  37  __module__�__qualname__rrrrrr	5sr	ccs\�|jj}||vrt�d|t|dd��dVdSz|�|�dVW|��dS|��w)z�
  38      A decorator to detect recursions in statements. In a recursion a statement
  39      at the same place, in the same module may not be executed two times.
  40      zcatched stmt recursion: %s @%s�	start_posNFT)Zrecursion_detectorrr�warning�getattr�append�pop)�inference_state�noderrrr�execution_allowed:s�
  41  �
  42  
  43  rcs�fdd�}|S)Ncs��fdd�}|S)NcsT|jj}|�|�}z|r�}n�|fi|��}W|��|SW|��|S|��wr
  44  )rZexecution_recursion_detector�push_execution�
  45  pop_execution)r
  46  �kwargs�detectorZ
  47  limit_reached�result)�default�funcrr�wrapperPs
  48  �
  49  �zAexecution_recursion_decorator.<locals>.decorator.<locals>.wrapperr)r"r#�r!)r"r�	decoratorOsz0execution_recursion_decorator.<locals>.decoratorr)r!r%rr$r�execution_recursion_decoratorNs
  50  r&c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ExecutionRecursionDetectorz+
  51      Catches recursions of executions.
  52      cCs"||_d|_g|_i|_d|_dS)Nr)Z_inference_state�_recursion_level�_parent_execution_funcs�_funcdef_execution_counts�_execution_count)r
  53  rrrrrcs
  54  
  55  z#ExecutionRecursionDetector.__init__cCs|j��|jd8_dS)N�)r)rr(rrrrrks
  56  z(ExecutionRecursionDetector.pop_executioncCs�|j}|jd7_|j�|�|��}|��rdS|jtkr't�dt�dS|j	t
  57  kr4t�dt
  58  �dS|j	d7_	|j�|d�t
  59  krU|��dkrLdSt�dt
  60  |�dS|j|d7<|j�|�tkrot�d	t|�dSdS)
  61  Nr,FzRecursion limit (%s) reachedTz%Function execution limit (%s) reachedr�typingz-Per function execution limit (%s) reached: %sz-Per function recursion limit (%s) reached: %s)Z	tree_noder(r)rZget_root_contextZis_builtins_module�recursion_limitrrr+�total_function_execution_limitr*�
  62  setdefault�per_function_execution_limitZ
  63  py__name__�count�per_function_recursion_limit)r
  64  Z	executionZfuncdefZmodule_contextrrrros>
  65  
  66  ��z)ExecutionRecursionDetector.push_executionN)rrr�__doc__rrrrrrrr'_s
  67  r'N)r4�
  68  contextlibrZjedirZjedi.inference.base_valuerr.r/r1r3r	rr&r'rrrr�<module>s"
  69