Ë
    ¬;jD  ã                   ó†   — 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    úi/workspace/moltex-experiments/.pixi/envs/default/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ÑB€Làˆ|ÑÜ�‰Ð6¸Ü˜d K°Ó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ÑHˆHØ$×3Ñ3°DÓ9ˆMð)Ù Ø$‘Fá! $Ñ1¨&Ñ1�Fà×&Ñ&Ô(Øˆ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Ü�M‰MÐ8¼/ÔJØà× Ñ Ô$BÒBÜ�M‰MÐAÔCaÔbØØ×Ò Ñ"Õà×)Ñ)×4Ñ4°W¸aÓ@ÔD`Ò`Ø×(Ñ(Ó*¨hÒ6ØÜ�M‰MØ?Ü,Øôð
 Ø×&Ñ& wÓ/°1Ñ4Ó/à×'Ñ'×-Ñ-¨gÓ6Ô9UÒUÜ�M‰MØ?Ü,Øôð
 Ø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   