o
    b                     @   s|   d Z ddlZddlZddlmZ ddlmZ ddlmZ ejdd Z	G dd	 d	Z
d
d Zejdd Zejdd ZdS )z) A few useful function/method decorators.    N)context)
exceptions)utilc                 C   sV   t |dd}|du ri  |_}z||  W S  ty*   | |i | || < }| Y S w )z>Simple decorator to cache result of method calls without args.__cacheN)getattrr   KeyError)funcinstanceargskwargscacheresult r   Q/var/www/secure340b-portal/env/lib/python3.10/site-packages/astroid/decorators.pycached   s   

r   c                   @   s2   e Zd ZdZdZdd Zedd Zd
dd	ZdS )cachedpropertya   Provides a cached property equivalent to the stacking of
    @cached and @property, but more efficient.

    After first usage, the <property_name> becomes part of the object's
    __dict__. Doing:

      del obj.<property_name> empties the cache.

    Idea taken from the pyramid_ framework and the mercurial_ project.

    .. _pyramid: http://pypi.python.org/pypi/pyramid
    .. _mercurial: http://pypi.python.org/pypi/Mercurial
    )wrappedc              
   C   s<   z|j  W n ty } ztd| |d }~ww || _d S )Nz!%s must have a __name__ attribute)__name__AttributeError	TypeErrorr   )selfr   excr   r   r   __init__6   s   

zcachedproperty.__init__c                 C   s$   t | jdd }d|rd|  S d S )N__doc__z+<wrapped by the cachedproperty decorator>%sz
%s )r   r   )r   docr   r   r   r   =   s   
zcachedproperty.__doc__Nc                 C   s*   |d u r| S |  |}t|| j j| |S N)r   setattrr   )r   instobjtypevalr   r   r   __get__D   s
   
zcachedproperty.__get__r   )r   
__module____qualname__r   	__slots__r   propertyr!   r   r   r   r   r   %   s    
r   c                 C   s   t | d| fdd}|S )zreturn the given infer function wrapped to handle the path

    Used to stop inference if the node has already been looked
    at for a given `InferenceContext` to prevent infinite recursion
    Nc           	   
   {   s    |du r	t  }|| rdS t }|| |fi |}z	 t|}|jjdkr,|j}n|}||vr:|V  || q t	y[ } z|j
rP|j
d W  Y d}~S W Y d}~dS d}~ww )z!wrapper function handling contextNTInstancer   )
contextmodZInferenceContextpushsetnext	__class__r   Z_proxiedaddStopIterationr
   )	noder   Z_funcr   yielded	generatorresZareserrorr   r   r   r   S   s.   


zpath_wrapper.<locals>.wrapped)	functoolswraps)r   r   r   r   r   path_wrapperL   s   r5   c                 c   sJ    | |i |}zt |V  W n ty   tjV  Y d S w |E d H  d S r   )r*   r-   r   ZUninferable)r   r	   r
   r   r0   r   r   r   yes_if_nothing_inferredp   s   r6   c              
   c   sl    | |i |}zt |V  W n ty. } z|jr%tjdi |jd tdd }~ww |E d H  d S )Nr   z3StopIteration raised without any error information.r   )r*   r-   r
   r   ZInferenceError)r   r	   r
   r   r0   r2   r   r   r   raise_if_nothing_inferred~   s   	r7   )r   r3   ZwraptZastroidr   r'   r   r   	decoratorr   r   r5   r6   r7   r   r   r   r   <module>   s   
'$
