
    MhD                         d Z ddlmZ ddlmZ ddlmZ dZ	 dZ	 dZ		 dZ
	  G d	 d
          Zed             ZefdZ G d d          ZdS )a   
Recursions are the recipe of |jedi| to conquer Python code. However, someone
must stop recursions going mad. Some settings are here to make |jedi| stop at
the right time. You can read more about them :ref:`here <settings-recursion>`.

Next to the internal ``jedi.inference.cache`` this module also makes |jedi| not
thread-safe, because ``execution_recursion_decorator`` uses class variables to
count the function calls.

.. _settings-recursion:

Settings
~~~~~~~~~~

Recursion settings are important if you don't want extremely
recursive python code to go absolutely crazy.

The default values are based on experiments while completing the |jedi| library
itself (inception!). But I don't think there's any other Python library that
uses recursion in a similarly extreme way. Completion should also be fast and
therefore the quality might not always be maximal.

.. autodata:: recursion_limit
.. autodata:: total_function_execution_limit
.. autodata:: per_function_execution_limit
.. autodata:: per_function_recursion_limit
    )contextmanager)debug)	NO_VALUES            c                       e Zd Zd ZdS )RecursionDetectorc                     g | _         d S N)pushed_nodesselfs    X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jedi/inference/recursion.py__init__zRecursionDetector.__init__6   s        N)__name__
__module____qualname__r    r   r   r   r   5   s#            r   r   c           	   #     K   | j         j        }||v r+t          j        d|t	          |dd                     dV  dS 	 |                    |           dV  |                                 dS # |                                 w xY w)z
    A decorator to detect recursions in statements. In a recursion a statement
    at the same place, in the same module may not be executed two times.
    zcatched stmt recursion: %s @%s	start_posNFT)recursion_detectorr   r   warninggetattrappendpop)inference_statenoder   s      r   execution_allowedr!   :   s       #5BL|6dK66	8 	8 	8	%%%JJJLs   A. .Bc                       fd}|S )Nc                       fd}|S )Nc                     | j         j        }|                    |           }	 |r}n	 | fi |}|                                 n# |                                 w xY w|S r   )r   execution_recursion_detectorpush_executionpop_execution)r   kwargsdetectorlimit_reachedresultdefaultfuncs        r   wrapperzAexecution_recursion_decorator.<locals>.decorator.<locals>.wrapperP   s~    +HH$33D99M)  2$FF!T$11&11F&&((((&&((((Ms   A Ar   )r-   r.   r,   s   ` r   	decoratorz0execution_recursion_decorator.<locals>.decoratorO   s)    
	 
	 
	 
	 
	 
	 r   r   )r,   r/   s   ` r   execution_recursion_decoratorr0   N   s$         r   c                   $    e Zd ZdZd Zd Zd ZdS )ExecutionRecursionDetectorz+
    Catches recursions of executions.
    c                 L    || _         d| _        g | _        i | _        d| _        d S )Nr   )_inference_state_recursion_level_parent_execution_funcs_funcdef_execution_counts_execution_count)r   r   s     r   r   z#ExecutionRecursionDetector.__init__c   s0     / !')$)+& !r   c                 X    | j                                          | xj        dz  c_        d S )N   )r6   r   r5   r   s    r   r'   z(ExecutionRecursionDetector.pop_executionk   s1    $((***"r   c                    |j         }| xj        dz  c_        | j                            |           |                                }|                                rdS | j        t          k    rt          j        dt                     dS | j	        t          k    rt          j        dt                     dS | xj	        dz  c_	        | j                            |d          t          k    r7|                                dk    rdS t          j        dt          |           dS | j        |xx         dz  cc<   | j                            |          t           k    rt          j        d	t           |           dS dS )
Nr:   FzRecursion limit (%s) reachedTz%Function execution limit (%s) reachedr   typingz-Per function execution limit (%s) reached: %sz-Per function recursion limit (%s) reached: %s)	tree_noder5   r6   r   get_root_contextis_builtins_modulerecursion_limitr   r   r8   total_function_execution_limitr7   
setdefaultper_function_execution_limit
py__name__countper_function_recursion_limit)r   	executionfuncdefmodule_contexts       r   r&   z)ExecutionRecursionDetector.push_executiono   s   % 	"$++G444"3355,,.. 	 5 ?22M8/JJJ4 $BBBMACabbb4")44Wa@@D```((**h66uM?,  
 4&w///14///'--g669UUUM?,  
 4ur   N)r   r   r   __doc__r   r'   r&   r   r   r   r2   r2   _   sK         " " "# # #* * * * *r   r2   N)rJ   
contextlibr   jedir   jedi.inference.base_valuer   r@   rA   rC   rF   r   r!   r0   r2   r   r   r   <module>rN      s   8 & % % % % %       / / / / / /  "%   !   ! 
       
   & +4    ": : : : : : : : : :r   