
    -hD                         S r SSKJr  SSKJr  SSKJr  Sr Sr Sr	 Sr
  " S	 S
5      r\S 5       r\4S jr " S S5      rg)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                       \ rS rSrS rSrg)RecursionDetector5   c                     / U l         g Npushed_nodesselfs    kC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\jedi/inference/recursion.py__init__RecursionDetector.__init__6   s
        r   N)__name__
__module____qualname____firstlineno__r   __static_attributes__ r   r   r   r   5   s    r   r   c           	   #     #    U R                   R                  nX;   a(  [        R                  " SU[	        USS5      5        Sv   g UR                  U5        Sv   UR                  5         g! UR                  5         f = f7f)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&   :   sp      #55BBL6dK6	8	%JLs   ABA- B-A??Bc                    ^  U 4S jnU$ )Nc                    >^  UU 4S jnU$ )Nc                    > U R                   R                  nUR                  U 5      n U(       a  TnO	T" U 40 UD6nUR                  5         U$ ! UR                  5         f = fr   )r$   execution_recursion_detectorpush_executionpop_execution)r   kwargsdetectorlimit_reachedresultdefaultfuncs        r   wrapperAexecution_recursion_decorator.<locals>.decorator.<locals>.wrapperP   sa    ++HHH$33D9M) $F!$1&1F&&(M &&(s   A A!r   )r2   r3   r1   s   ` r   	decorator0execution_recursion_decorator.<locals>.decoratorO   s    
	 r   r   )r1   r5   s   ` r   execution_recursion_decoratorr7   N   s     r   c                   *    \ rS rSrSrS rS rS rSrg)ExecutionRecursionDetector_   z#
Catches recursions of executions.
c                 H    Xl         SU l        / U l        0 U l        SU l        g )Nr   )_inference_state_recursion_level_parent_execution_funcs_funcdef_execution_counts_execution_count)r   r$   s     r   r   #ExecutionRecursionDetector.__init__c   s(     / !')$)+& !r   c                 b    U R                   R                  5         U =R                  S-  sl        g )N   )r>   r#   r=   r   s    r   r,   (ExecutionRecursionDetector.pop_executionk   s%    $$((*"r   c                    UR                   nU =R                  S-  sl        U R                  R                  U5        UR	                  5       nUR                  5       (       a  gU R                  [        :  a  [        R                  " S[        5        gU R                  [        :  a  [        R                  " S[        5        gU =R                  S-  sl	        U R                  R                  US5      [        :  a2  UR                  5       S:X  a  g[        R                  " S[        U5        gU R                  U==   S-  ss'   U R                  R                  U5      [         :  a  [        R                  " S	[         U5        gg)
NrC   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_noder=   r>   r"   get_root_contextis_builtins_modulerecursion_limitr   r    r@   total_function_execution_limitr?   
setdefaultper_function_execution_limit
py__name__countper_function_recursion_limit)r   	executionfuncdefmodule_contexts       r   r+   )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   )r@   r?   r<   r>   r=   N)	r   r   r   r   __doc__r   r,   r+   r   r   r   r   r9   r9   _   s    "#*r   r9   N)rU   
contextlibr   jedir   jedi.inference.base_valuer   rJ   rK   rM   rP   r   r&   r7   r9   r   r   r   <module>rY      sz   8 &  /  "%   !   ! 
 
  & +4 ": :r   