ó
    Ð]jD  ã                   óˆ   • 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)ÚRecursionDetectoré5   c                 ó   • / U l         g ©N©Úpushed_nodes©Úselfs    ÚU/home/mande/repo/quber/.venv/lib/python3.13/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ÑB€LàÓÜ�ŠÐ6¸Ü˜d K°Ó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   ÚwrapperÚAexecution_recursion_decorator.<locals>.decorator.<locals>.wrapperP   sa   ø€ Ø×+Ñ+×HÑHˆHØ$×3Ñ3°DÓ9ˆMð)Þ Ø$‘Fá! $Ñ1¨&Ñ1�Fà×&Ñ&Ô(ØˆMøð ×&Ñ&Õ(ús   ªA ÁA!r   )r2   r3   r1   s   ` €r   Ú	decoratorÚ0execution_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Ü�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   )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   