
    e!                    z   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mZ ddl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d Z	 	 	 	 ddZ	 	 	 	 ddZ ej8                         r	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZy	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZy)z(A few useful function/method decorators.    )annotationsN)Callable	Generator)TypeVar)util)InferenceContext)InferenceError)InferenceResult)   
   )	ParamSpec_R_Pc                J    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
    Nc              ;     K   |
t               }|j                  |       ryt               } || |fi |D ]D  }|j                  j                  dk(  r|j
                  }n|}||vs0| |j                  |       F yw)z"Wrapper function handling context.NInstance)r   pushset	__class____name___proxiedadd)nodecontext_funckwargsyieldedresaress          4/usr/lib/python3/dist-packages/astroid/decorators.pywrappedzpath_wrapper.<locals>.wrapped%   s     
 ?&(G<<%w1&1 	"C}}%%3||7"	D!	"s   A"A=%A=)r   zInferenceContext | Nonereturnr   	functoolswraps)funcr!   s     r    path_wrapperr'      s;     __T15T"."	" "* N    c                      	 	 	 	 	 	 d fd}|S )Nc               ?     K    | i |}	 t        |       |E d {    y # t        $ r t        j                   Y y w xY w7 &w)N)nextStopIterationr   Uninferable)argsr   	generatorr&   s      r    innerz&yes_if_nothing_inferred.<locals>.innerA   sW      $)&)		y/!   	"""	
 	s/   	A% AAAA AAAr.   _P.argsr   	_P.kwargsr"   z&Generator[InferenceResult, None, None] r&   r0   s   ` r    yes_if_nothing_inferredr6   >   s'    "+	/ Lr(   c                      	 	 	 	 	 	 d fd}|S )Nc               ?  2  K    | i |}	 t        |       |E d {    y # t        $ r6}|j                  rt        di |j                  d   |t        d      |d }~wt        $ r'}t        dt        j                          d      |d }~ww xY w7 uw)Nr   z3StopIteration raised without any error information.z!RecursionError raised with limit .r4   )r+   r,   r.   r	   RecursionErrorsysgetrecursionlimit)r.   r   r/   errorr&   s       r    r0   z(raise_if_nothing_inferred.<locals>.innerU   s      $)&)		y/!   	zz$5uzz!}55@ E  	 3C4I4I4K3LAN	
 	s:   	B% BBB	B1AB+"BBBr1   r4   r5   s   ` r    raise_if_nothing_inferredr>   R   s'    "+	/( Lr(   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.
        c                J     t        j                         d fd       }|S )Decorator function.c                 N   t        t        j                        j                  j	                               }j                         D ]  \  }}	 |j                  |      }||v r||   -||vs&|dk(  s#t        |       |k  st        |       |kD  sH| |   Nt        j                  d| d| d   j                  j                   dj                   d	 d
| d| dt        d         | i |S # t        $ r+ t        d| d| d   j                  j                   d      dw xY w)z/Emit DeprecationWarnings if conditions are met.Can't find argument '' for 'r   'Nz#' will be a required argument for 'r9   z' in astroid z ('z' should be of type: 'z')   
stacklevellistinspect	signature
parameterskeysitemsindex
ValueErrorr   __qualname__lenwarningswarnr   DeprecationWarning)	r.   r   rO   argtype_annotationrQ   	argumentsastroid_versionr&   s	         r    wrapperz@deprecate_default_argument_values.<locals>.deco.<locals>.wrapper   sY    G--d3>>CCEF,5OO,= (C$ $

3 6#;+> f,!RK"4yE1 #D	E 1d5k6I !u %  $Q 1 1 > >?q P++:*; <!!$%;O;LBP /'(/> T,V,,9 & $(3C5Q@Q@Q@^@^?__`a#$$s   C004D$r.   r2   r   r3   r"   r   r#   r&   r\   rZ   r[   s   ` r    decoz/deprecate_default_argument_values.<locals>.deco   s(     __T"#- ##-J Nr(   r&   Callable[_P, _R]r"   ra   r4   r[   rZ   r_   s   `` r    !deprecate_default_argument_valuesrc   q   s     )	V r(   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.
        c                J     t        j                         d fd       }|S )Nc                    t        t        j                        j                  j	                               }j                         D ]w  \  }}	 |j                  |      }||v st        |       |kD  s+t        j                  d| d| d   j                  j                   dj                   d d| d	t        d
       y  | i |S # t        $ r+ t        d| d| d   j                  j                   d      d w xY w)NrC   rD   r   rE   zThe argument 'r9   z/' is deprecated and will be removed in astroid z ()rG   rH   rJ   )	r.   r   rO   rX   noterQ   rZ   r[   r&   s	         r    r\   z2deprecate_arguments.<locals>.deco.<locals>.wrapper   s   G--d3>>CCEF!*!2 IC$ $

3
 f}D	E(9 ,SE 2  $Q 1 1 > >?q P>>M=NbQUPVVWY /'( T,V,, & $(3C5Q@Q@Q@^@^?__`a#$$s   C

4C>r]   r#   r^   s   ` r    r_   z!deprecate_arguments.<locals>.deco   s%    __T"- #-& Nr(   r`   r4   rb   s   `` r    deprecate_argumentsri      s    	. r(   c                    dd}|S )bPassthrough decorator to improve performance if DeprecationWarnings are
        disabled.
        c                    | S rA   r4   r&   s    r    r_   z/deprecate_default_argument_values.<locals>.deco       Kr(   r`   r4   rb   s      r    rc   rc          	 r(   c                    dd}|S )rk   c                    | S rm   r4   rn   s    r    r_   z!deprecate_arguments.<locals>.deco   ro   r(   r`   r4   rb   s      r    ri   ri      rp   r(   )r&   4Callable[_P, Generator[InferenceResult, None, None]]r"   rs   )z3.0)r[   strrZ   rt   r"   z.Callable[[Callable[_P, _R]], Callable[_P, _R]])__doc__
__future__r   r$   rL   r;   rU   collections.abcr   r   typingr   astroidr   astroid.contextr   astroid.exceptionsr	   astroid.typingr
   version_infor   typing_extensionsr   r   r'   r6   r>   check_warnings_filterrc   ri   r4   r(   r    <module>r      s  
 / "   
  /   , - *w +T]t_@
>9(
>9: 4  %;;36;	7;|  %$$36$	7$R  %36	7  %36	7r(   