§
    ŒŸ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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    úe/var/www/finuniver-perm.ru/html/student/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ÔB€Làˆ|ÐÐÝŒÐ6¸Ý˜d K°Ñ6Ô6ñ	8ô 	8ð 	8àˆˆˆˆˆð	Ø×Ò Ñ%Ô%Ð%ØˆJˆJˆJà×ÒÑÔÐÐÐøˆ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~   ø€ ØÔ+ÔHˆHØ$×3Ò3°DÑ9Ô9ˆMð)Ø ð 2Ø$�F�Fà!˜T $Ð1Ð1¨&Ð1Ð1�Fà×&Ò&Ñ(Ô(Ð(Ð(ø�×&Ò&Ñ(Ô(Ð(Ð(øøøØˆ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ÐAÕCaÑbÔbÐbØ�4ØÐÔ Ñ"ÐÔàÔ)×4Ò4°W¸aÑ@Ô@ÕD`Ò`Ð`Ø×(Ò(Ñ*Ô*¨hÒ6Ð6Ø�uÝŒMØ?Ý,Øñô ð ð
 �4ØÔ& wÐ/Ð/Ô/°1Ñ4Ð/Ð/Ñ/àÔ'×-Ò-¨gÑ6Ô6Õ9UÒ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   