
    c&                       d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlZddlmZmZ ddlmZ ddlmZ ej        d	k    rdd
l
mZ ndd
lmZ  ed          Z ed          Zej        d             Z G d d          Zd Zej        d             Zej        d             Z ej                    r	 dddZ 	 dddZ!dS 	 dddZ 	 dddZ!dS )z(A few useful function/method decorators.    )annotationsN)Callable	Generator)TypeVar)_cacheutil)InferenceContext)InferenceError)   
   )	ParamSpec_R_Pc                    t          |dd          }|(i x|_        }t          j                            |           	 ||          S # t
          $ r  | |i |x|| <   }|cY S w xY w)z>Simple decorator to cache result of method calls without args.__cacheN)getattrr   r   CACHE_MANAGERadd_dict_cacheKeyError)funcinstanceargskwargscacheresults         2lib/python3.11/site-packages/astroid/decorators.pycachedr      s     Hi..E 3#%%5++E222T{   #tT4V444dfs   A A! A!c                  :    e Zd ZdZdZd Zed             Z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                    t           j        dk    rt          j        dt                     	 |j         n%# t          $ r}t          | d          |d }~ww xY w|| _        d S )N)r      z}cachedproperty has been deprecated and will be removed in astroid 3.0 for Python 3.8+. Use functools.cached_property instead.z must have a __name__ attribute)	sysversion_infowarningswarnDeprecationWarning__name__AttributeError	TypeErrorr    )selfr    excs      r   __init__zcachedproperty.__init__@   s    v% 	M9"  
	R 	R 	R 	RwGGGHHcQ	Rs   4 
AAAc                F    t          | j        dd           }d|rd|z  ndz  S )N__doc__z+<wrapped by the cachedproperty decorator>%sz
%s )r   r    )r+   docs     r   r/   zcachedproperty.__doc__M   s2    dlIt44<'FSLLR
 	
    Nc                n    || S |                      |          }t          || j         j        |           |S N)r    setattrr(   )r+   instobjtypevals       r   __get__zcachedproperty.__get__T   s<     	Kll4  dl+S111
r2   r4   )r(   
__module____qualname__r/   	__slots__r-   propertyr9    r2   r   r   r   /   sc          I   
 
 X
     r2   r   c                H    t          j        |           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
    NcontextInferenceContext | Nonereturnr   c              ;     K   |t                      }|                    |           rdS t                      } || |fi |D ]9}|j        j        dk    r|j        }n|}||vr|V  |                    |           :dS )z"Wrapper function handling context.NInstance)r	   pushset	__class__r(   _proxiedadd)noder@   _funcr   yieldedresaress          r   r    zpath_wrapper.<locals>.wrappedc   s      
  	)&((G<< 	F%%5w11&11 	" 	"C}%3 |7" "			D!!!	" 	"r2   )r@   rA   rB   r   	functoolswraps)r   r    s     r   path_wrapperrR   \   s>     _T15T" " " " "* Nr2   c              #     K    | |i |}	 t          |          V  n# t          $ r t          j        V  Y d S w xY w|E d {V  d S r4   )nextStopIterationr   Uninferable)r   r   r   r   	generators        r   yes_if_nothing_inferredrX   |   s      d%f%%I9oo   
 s    ::c              #  6  K    | |i |}	 t          |          V  ns# t          $ r4}|j        rt          di |j        d         |t          d          |d }~wt          $ r*}t          dt          j                     d          |d }~ww xY w|E d {V  d S )Nr   z3StopIteration raised without any error information.z!RecursionError raised with limit .r>   )rT   rU   r   r
   RecursionErrorr#   getrecursionlimit)r   r   r   r   rW   errors         r   raise_if_nothing_inferredr^      s      d%f%%I9oo   : 	= 115:a=11u<A
 
	    J0E0G0GJJJ
 
	
 s     
B/AB$%B		B3.0astroid_versionstr	argumentsrB   .Callable[[Callable[_P, _R]], Callable[_P, _R]]c                     d fd}|S )a  Decorator which emits a DeprecationWarning if any arguments specified
        are None or not passed at all.

        Arguments should be a key-value mapping, with the key being the argument to check
        and the value being a type annotation as string for the value of the argument.

        To improve performance, only used when DeprecationWarnings other than
        the default one are enabled.
        r   Callable[_P, _R]rB   c                N     t          j                   d fd            }|S )	Decorator function.r   _P.argsr   	_P.kwargsrB   r   c                 \   t          t          j                  j                                                  }                                D ]\  }}	 |                    |          }n5# t          $ r( t          d| d| d         j        j	         d          dw xY w||v r||         8||vrv|dk    s.t          |           |k    st          |           |k    rJ| |         Bt          j        d| d| d         j        j	         dj         d	 d
| d| dt                      | i |S )z/Emit DeprecationWarnings if conditions are met.Can't find argument '' for 'r   'Nz#' will be a required argument for 'rZ   z' in astroid z ('z' should be of type: 'z')listinspect	signature
parameterskeysitemsindex
ValueErrorrG   r;   lenr%   r&   r(   r'   )	r   r   rt   argtype_annotationrv   rb   r`   r   s	         r   wrapperz@deprecate_default_argument_values.<locals>.deco.<locals>.wrapper   s    G-d33>CCEEFF,5OO,=,=  (C$ $

3% $ $ $(aCaaQ@Q@^aaa #$$  ,2#; f, "RK  #4yyE1 !$D		E 1 7;5k  !P P P $Q 1 >P PAEP P+:P P "%P P =LP P P /   tT,V,,,   A**2Br   rh   r   ri   rB   r   rO   r   r{   rb   r`   s   ` r   decoz/deprecate_default_argument_values.<locals>.deco   sK     _T"""- "- "- "- "- "- "- #""-H Nr2   r   re   rB   re   r>   r`   rb   r   s   `` r   !deprecate_default_argument_valuesr      s/     (	 (	 (	 (	 (	 (	 (	T r2   c                     d fd}|S )a  Decorator which emits a DeprecationWarning if any arguments specified
        are passed.

        Arguments should be a key-value mapping, with the key being the argument to check
        and the value being a string that explains what to do instead of passing the argument.

        To improve performance, only used when DeprecationWarnings other than
        the default one are enabled.
        r   re   rB   c                N     t          j                   d fd            }|S )	Nr   rh   r   ri   rB   r   c                    t          t          j                  j                                                  }                                D ]\  }}	 |                    |          }n5# t          $ r( t          d| d| d         j        j	         d          d w xY w||v st          |           |k    r?t          j        d| d| d         j        j	         dj         d d| d	t                      | i |S )
Nrk   rl   r   rm   zThe argument 'rZ   z/' is deprecated and will be removed in astroid z ()ro   )	r   r   rt   ry   noterv   rb   r`   r   s	         r   r{   z2deprecate_arguments.<locals>.deco.<locals>.wrapper   s`   G-d33>CCEEFF!*!2!2  IC$ $

3% $ $ $(aCaaQ@Q@^aaa #$$ f} D		E(9  YS Y Y $Q 1 >Y YAEY Y>MY YQUY Y Y /	   tT,V,,,r|   r}   rO   r~   s   ` r   r   z!deprecate_arguments.<locals>.deco   sH    _T""- - - - - - - #"-$ Nr2   r   r>   r   s   `` r   deprecate_argumentsr      s.    	 	 	 	 	 	 	, r2   c                    dd}|S )bPassthrough decorator to improve performance if DeprecationWarnings are
        disabled.
        r   re   rB   c                    | S rg   r>   r   s    r   r   z/deprecate_default_argument_values.<locals>.deco      Kr2   r   r>   r   s      r   r   r         	 	 	 	 r2   c                    dd}|S )r   r   re   rB   c                    | S r   r>   r   s    r   r   z!deprecate_arguments.<locals>.deco  r   r2   r   r>   r   s      r   r   r     r   r2   )r_   )r`   ra   rb   ra   rB   rc   )"r/   
__future__r   rP   rq   r#   r%   collections.abcr   r   typingr   wraptastroidr   r   astroid.contextr	   astroid.exceptionsr
   r$   r   typing_extensionsr   r   	decoratorr   r   rR   rX   r^   check_warnings_filterr   r   r>   r2   r   <module>r      s:  
 / . " " " " " "      



  / / / / / / / /                        , , , , , , - - - - - -w ,       ++++++WT]]Yt__ 
 
 
* * * * * * * *Z  @ 
 
 
   . 4 }  %: : : : :z  %# # # # # # #P  %      %      r2   