
    e%                        d Z ddlmZ ddlmZmZ ddlmZ ddlZddlm	Z	 ddl
mZ ddlmZ dd	lmZmZmZ dd
lmZ ej(                  ej*                  e	j,                  e	j.                  fZ G d de      Zy)z+Checker mixin for deprecated functionality.    )annotations)	ContainerIterable)chainN)nodes)utils)BaseChecker)get_import_name	infer_all
safe_infer)MessageDefinitionTuplec                     e Zd ZU dZdddddgddfiZd	ed
<   dddddgddfiZd	ed<   dddddgddfiZd	ed<   dddddgddfiZd	ed<   dddd d!gddfiZ	d	ed"<    e
j                  ddd      d1d#       Z e
j                  dd      d2d$       Zd3d%Z e
j                  d      d4d&       Z e
j                  dd      d5d'       Zd6d(Zd7d)Zd3d*Zd8d+Zd9d,Zd:d-Z	 	 	 	 	 	 	 	 d;d.Zd1d/Zy0)<DeprecatedMixinzA mixin implementing logic for checking deprecated symbols.

    A class implementing mixin must define "deprecated-method" Message.
    W4901zDeprecated module %rdeprecated-modulez*A module marked as deprecated is imported.)W0402zold-deprecated-moduleT)	old_namessharedz!dict[str, MessageDefinitionTuple]DEPRECATED_MODULE_MESSAGEW4902zUsing deprecated method %s()deprecated-methodzEThe method is marked as deprecated and will be removed in the future.)W1505zold-deprecated-methodDEPRECATED_METHOD_MESSAGEW4903z+Using deprecated argument %s of method %s()deprecated-argumentzGThe argument is marked as deprecated and will be removed in the future.)W1511zold-deprecated-argumentDEPRECATED_ARGUMENT_MESSAGEW4904z&Using deprecated class %s of module %sdeprecated-classzDThe class is marked as deprecated and will be removed in the future.)W1512zold-deprecated-classDEPRECATED_CLASS_MESSAGEW4905zUsing deprecated decorator %s()deprecated-decoratorzHThe decorator is marked as deprecated and will be removed in the future.)W1513zold-deprecated-decoratorDEPRECATED_DECORATOR_MESSAGEc                ~    | j                  |       t        |j                        D ]  }| j                  ||        y)z2Called when a :class:`nodes.Call` node is visited.N)check_deprecated_class_in_callr   funccheck_deprecated_method)selfnodeinferreds      </usr/lib/python3/dist-packages/pylint/checkers/deprecated.py
visit_callzDeprecatedMixin.visit_callO   s:     	++D1!$)), 	9H((x8	9    c                    d |j                   D        D ]B  }| j                  ||       d|v s|j                  dd      \  }}| j                  |||f       D y)z+Triggered when an import statement is seen.c              3  &   K   | ]	  \  }}|  y wN .0name_s      r-   	<genexpr>z/DeprecatedMixin.visit_import.<locals>.<genexpr>a   s     4gdAT4   .   N)namescheck_deprecated_modulesplitcheck_deprecated_class)r*   r+   r6   mod_name
class_names        r-   visit_importzDeprecatedMixin.visit_import[   s^     54 	KD((t4d{'+zz#q'9$*++D(ZMJ	Kr/   c                     y)zCallback returning the deprecated decorators.

        Returns:
            collections.abc.Container of deprecated decorator names.
        r3   r3   r*   s    r-   deprecated_decoratorsz%DeprecatedMixin.deprecated_decoratorsh        r/   c                :   t        |j                               }|syt        |d   t        j                        rt        |d   j                        }nt        |d         }|r|j                         nd}|| j                         v r| j                  d||       yy)z-Triggered when a decorator statement is seen.Nr   r#   r+   args)
listget_children
isinstancer   Callr   r(   qnamerE   add_message)r*   r+   childreninfrN   s        r-   visit_decoratorsz DeprecatedMixin.visit_decoratorsp   s     ))+,hqk5::.Xa[--.CXa[)C"		D..003$UK 1r/   c                    |j                   }t        ||      }| j                  ||       d |j                  D        }| j	                  |||       y)z(Triggered when a from statement is seen.c              3  &   K   | ]	  \  }}|  y wr2   r3   r4   s      r-   r8   z3DeprecatedMixin.visit_importfrom.<locals>.<genexpr>   s     6at6r9   N)modnamer
   r=   r<   r?   )r*   r+   basenameclass_namess       r-   visit_importfromz DeprecatedMixin.visit_importfrom~   sI     <<"42$$T8464::6##D(K@r/   c                     y)zCallback returning the deprecated methods/functions.

        Returns:
            collections.abc.Container of deprecated function/method names.
        r3   r3   rD   s    r-   deprecated_methodsz"DeprecatedMixin.deprecated_methods   rF   r/   c                     y)aP  Callback returning the deprecated arguments of method/function.

        Args:
            method (str): name of function/method checked for deprecated arguments

        Returns:
            collections.abc.Iterable in form:
                ((POSITION1, PARAM1), (POSITION2: PARAM2) ...)
            where
                * POSITIONX - position of deprecated argument PARAMX in function definition.
                  If argument is keyword-only, POSITIONX should be None.
                * PARAMX - name of the deprecated argument.
            E.g. suppose function:

            .. code-block:: python
                def bar(arg1, arg2, arg3, arg4, arg5='spam')

            with deprecated arguments `arg2` and `arg4`. `deprecated_arguments` should return:

            .. code-block:: python
                ((1, 'arg2'), (3, 'arg4'))
        r3   r3   )r*   methods     r-   deprecated_argumentsz$DeprecatedMixin.deprecated_arguments   s    0 r/   c                     y)zCallback returning the deprecated modules.

        Returns:
            collections.abc.Container of deprecated module names.
        r3   r3   rD   s    r-   deprecated_modulesz"DeprecatedMixin.deprecated_modules   rF   r/   c                     y)zCallback returning the deprecated classes of module.

        Args:
            module (str): name of module checked for deprecated classes

        Returns:
            collections.abc.Container of deprecated class names.
        r3   r3   )r*   modules     r-   deprecated_classesz"DeprecatedMixin.deprecated_classes   s     r/   c                    | j                         D ]3  }||k(  s|s|j                  |dz         s | j                  d||       5 y)z#Checks if the module is deprecated.r:   r   rH   N)r_   
startswithrO   )r*   r+   mod_pathr@   s       r-   r=   z'DeprecatedMixin.check_deprecated_module   sN    //1 	PH8#xH4G4GSV4W  !44h O	Pr/   c                    t        |t              syt        |j                  t        j                        r|j                  j
                  }n<t        |j                  t        j                        r|j                  j                  }ny|j                         |h}t         fd|D              r j                  d||f       yt        |j                        }|j                  r$|j                  D ch c]  }|j                   c}ni } fd|D        }t        | D ]?  \  }	}
|
|v r j                  d||
|f       !|	$|	|k  s* j                  d||
|f       A yc c}w )zExecutes the checker for the given node.

        This method should be called from the checker implementing this mixin.
        Nc              3  B   K   | ]  }|j                         v   y wr2   )rZ   )r5   r6   r*   s     r-   r8   z:DeprecatedMixin.check_deprecated_method.<locals>.<genexpr>   s     DTtt..00Ds   r   rH   c              3  @   K   | ]  }j                  |        y wr2   )r]   )r5   qnr*   s     r-   r8   z:DeprecatedMixin.check_deprecated_method.<locals>.<genexpr>   s     O" 9 9" =Os   r   )rL   ACCEPTABLE_NODESr(   r   	AttributeattrnameNamer6   rN   anyrO   lenrI   keywordsargr   )r*   r+   r,   	func_nameqnamesnum_of_argskwkwargsr]   positionarg_names   `          r-   r)   z'DeprecatedMixin.check_deprecated_method   s>    ($45dii1		**I		5::.		I .."I.DVDD0t9,O$))n59]]4==1R"&&1OO"')="> 
	Hh6!  )Hi;P !  %([*@  )Hi;P ! 
	 2s   5E#c                f    |D ],  }|| j                  |      v s| j                  d|||f       . y)z"Checks if the class is deprecated.r   rH   N)rb   rO   )r*   r+   r@   rW   rA   s        r-   r?   z&DeprecatedMixin.check_deprecated_class   sE    
 & 	JT44X>>  &TX8N ! 	r/   c                @   t        |j                  t        j                        rzt        |j                  j                  t        j
                        rK|j                  j                  j                  }|j                  j                  }| j                  |||f       yyy)z$Checks if call the deprecated class.N)	rL   r(   r   rk   exprrm   r6   rl   r?   )r*   r+   r@   rA   s       r-   r'   z.DeprecatedMixin.check_deprecated_class_in_call   sn     dii1jIINNEJJ7
 yy~~**H++J''hF7
1r/   N)r+   
nodes.CallreturnNone)r+   nodes.Importr}   r~   )r}   Iterable[str])r+   znodes.Decoratorsr}   r~   )r+   znodes.ImportFromr}   r~   )r}   zContainer[str])r\   strr}   z Iterable[tuple[int | None, str]])ra   r   r}   r   )r+   r   re   z
str | Noner}   r~   )r+   r|   r,   nodes.NodeNGr}   r~   )r+   r   r@   r   rW   r   r}   r~   )__name__
__module____qualname____doc__r   __annotations__r   r   r!   r%   r   only_required_for_messagesr.   rB   rE   rR   rX   rZ   r]   r_   rb   r=   r)   r?   r'   r3   r/   r-   r   r      s    	"8=>$O	
D@  	*S=>$O	
D@  	9!U?@DQ	
F!B  	4R<=N	
C?  	-"V@ATR	
G "C  &U%%
9
9 &U%%K	K &U%%&<=L >L &U%%A	A4
P#J	 	,/	>K			Gr/   r   )r   
__future__r   collections.abcr   r   	itertoolsr   astroidr   pylint.checkersr   pylint.checkers.base_checkerr	   pylint.checkers.utilsr
   r   r   pylint.typingr   BoundMethodUnboundMethodFunctionDefClassDefrj   r   r3   r/   r-   <module>r      sd   
 2 " /    ! 4 H H 0 		NN	 bGk bGr/   