
    fD                         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y)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y)RecursionDetectorc                     g | _         y N)pushed_nodesselfs    S/var/www/cvtools/html/venv/lib/python3.12/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 y	 |j                  |       d |j                          y# |j                          w xY w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!   :   ss      #55BBL|6dK6	8	%JLs   AB A+ B +A==B c                       fd}|S )Nc                       fd}|S )Nc                     | j                   j                  }|j                  |       }	 |r}n	 | fi |}|j                          |S # |j                          w xY w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   sa    ++HHH$33D9M) $F!$1&1F&&(M &&(s   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y)ExecutionRecursionDetectorz+
    Catches recursions of executions.
    c                 J    || _         d| _        g | _        i | _        d| _        y )Nr   )_inference_state_recursion_level_parent_execution_funcs_funcdef_execution_counts_execution_count)r   r   s     r   r   z#ExecutionRecursionDetector.__init__c   s*     / !')$)+& !r   c                 b    | j                   j                          | xj                  dz  c_        y )N   )r6   r   r5   r   s    r   r'   z(ExecutionRecursionDetector.pop_executionk   s%    $$((*"r   c                    |j                   }| xj                  dz  c_        | j                  j                  |       |j	                         }|j                         ry| j                  t        kD  rt        j                  dt               y| j                  t        k\  rt        j                  dt               y| xj                  dz  c_	        | j                  j                  |d      t        k\  r0|j                         dk(  ryt        j                  dt        |       y| j                  |xx   dz  cc<   | j                  j                  |      t         kD  rt        j                  d	t         |       yy)
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"335,,.   ?2MM8/J  $BBMMACab"))44Wa@D``((*h6MM?,
 &&w/14/''--g69UUMM?,
 r   N)r   r   r   __doc__r   r'   r&   r   r   r   r2   r2   _   s    "#*r   r2   N)rJ   
contextlibr   jedir   jedi.inference.base_valuer   r@   rA   rC   rF   r   r!   r0   r2   r   r   r   <module>rN      sz   8 &  /  "%   !   ! 
 
  & +4 ": :r   