
    c%                        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dS )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          dDd'            Z e
j        dd          dEd)            ZdFd+Z e
j        d          dGd-            Z e
j        dd          dHd/            ZdId1ZdJd5ZdFd6ZdKd8ZdLd;ZdMd>ZdNdAZdDdBZdCS )O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_MESSAGEnode
nodes.CallreturnNonec                    |                      |           t          |j                  D ]}|                     ||           dS )z2Called when a :class:`nodes.Call` node is visited.N)check_deprecated_class_in_callr   funccheck_deprecated_method)selfr&   inferreds      :lib/python3.11/site-packages/pylint/checkers/deprecated.py
visit_callzDeprecatedMixin.visit_callO   sT     	++D111!$),, 	9 	9H((x8888	9 	9    nodes.Importc                    d |j         D             D ]M}|                     ||           d|v r1|                    dd          \  }}|                     |||f           NdS )z+Triggered when an import statement is seen.c              3      K   | ]	\  }}|V  
d S N .0name_s      r0   	<genexpr>z/DeprecatedMixin.visit_import.<locals>.<genexpr>a   s&      44gdAT444444r2   .   N)namescheck_deprecated_modulesplitcheck_deprecated_class)r.   r&   r:   mod_name
class_names        r0   visit_importzDeprecatedMixin.visit_import[   s     54444 	K 	KD((t444d{ K'+zz#q'9'9$*++D(ZMJJJ	K 	Kr2   Iterable[str]c                    dS )zCallback returning the deprecated decorators.

        Returns:
            collections.abc.Container of deprecated decorator names.
        r7   r7   r.   s    r0   deprecated_decoratorsz%DeprecatedMixin.deprecated_decoratorsh   	     rr2   nodes.Decoratorsc                   t          |                                          }|sdS t          |d         t          j                  rt          |d         j                  }nt          |d                   }|r|                                nd}||                                 v r| 	                    d||           dS dS )z-Triggered when a decorator statement is seen.Nr   r#   r&   args)
listget_children
isinstancer   Callr   r,   qnamerI   add_message)r.   r&   childreninfrS   s        r0   visit_decoratorsz DeprecatedMixin.visit_decoratorsp   s     ))++,, 	Fhqk5:.. 	*Xa[-..CCXa[))C",		D..000 	L3$UKKKKK	L 	Lr2   nodes.ImportFromc                    |j         }t          ||          }|                     ||           d |j        D             }|                     |||           dS )z(Triggered when a from statement is seen.c              3      K   | ]	\  }}|V  
d S r6   r7   r8   s      r0   r<   z3DeprecatedMixin.visit_importfrom.<locals>.<genexpr>   s&      66at666666r2   N)modnamer
   r@   r?   rB   )r.   r&   basenameclass_namess       r0   visit_importfromz DeprecatedMixin.visit_importfrom~   sc     <"422$$T8444664:666##D(K@@@@@r2   Container[str]c                    dS )zCallback returning the deprecated methods/functions.

        Returns:
            collections.abc.Container of deprecated function/method names.
        r7   r7   rH   s    r0   deprecated_methodsz"DeprecatedMixin.deprecated_methods   rJ   r2   methodstr Iterable[tuple[int | None, str]]c                    dS )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'))
        r7   r7   )r.   rb   s     r0   deprecated_argumentsz$DeprecatedMixin.deprecated_arguments   s	    0 rr2   c                    dS )zCallback returning the deprecated modules.

        Returns:
            collections.abc.Container of deprecated module names.
        r7   r7   rH   s    r0   deprecated_modulesz"DeprecatedMixin.deprecated_modules   rJ   r2   modulec                    dS )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.
        r7   r7   )r.   ri   s     r0   deprecated_classesz"DeprecatedMixin.deprecated_classes   s	     rr2   mod_path
str | Nonec                    |                                  D ]:}||k    s|r0|                    |dz             r|                     d||           ;dS )z#Checks if the module is deprecated.r=   r   rM   N)rh   
startswithrT   )r.   r&   rl   rC   s       r0   r@   z'DeprecatedMixin.check_deprecated_module   sy    //11 	P 	PH8# Px PH4G4GSV4W4W P  !44h OOO	P 	Pr2   r/   nodes.NodeNGc                    t          |t                    sdS t          |j        t          j                  r|j        j        }n.t          |j        t          j                  r|j        j        }ndS |                                |h}t           fd|D                       r 
                    d||f           dS t          |j                  }|j        rd |j        D             ni } fd|D             }t          | D ]F\  }}	|	|v r 
                    d||	|f           $| ||k     r 
                    d||	|f           GdS )zExecutes the checker for the given node.

        This method should be called from the checker implementing this mixin.
        Nc              3  D   K   | ]}|                                 v V  d S r6   )ra   )r9   r:   r.   s     r0   r<   z:DeprecatedMixin.check_deprecated_method.<locals>.<genexpr>   s4      DDTtt..000DDDDDDr2   r   rM   c                    h | ]	}|j         
S r7   )arg)r9   kws     r0   	<setcomp>z:DeprecatedMixin.check_deprecated_method.<locals>.<setcomp>   s    111R"&111r2   c              3  B   K   | ]}                     |          V  d S r6   )rf   )r9   qnr.   s     r0   r<   z:DeprecatedMixin.check_deprecated_method.<locals>.<genexpr>   s1      OO" 9 9" = =OOOOOOr2   r   )rQ   ACCEPTABLE_NODESr,   r   	AttributeattrnameNamer:   rS   anyrT   lenrN   keywordsr   )
r.   r&   r/   	func_nameqnamesnum_of_argskwargsrf   positionarg_names
   `         r0   r-   z'DeprecatedMixin.check_deprecated_method   s    ($455 	Fdi11 		*II	5:.. 		II F..""I.DDDDVDDDDD 	0t9,OOOF$)nn59]J114=1111OOOOOOO"')="> 
	 
	Hh6! 	  )Hi;P !      ([*@   )Hi;P !   
	 
	r2   rC   r]   c                r    |D ]3}||                      |          v r|                     d|||f           4dS )z"Checks if the class is deprecated.r   rM   N)rk   rT   )r.   r&   rC   r]   rD   s        r0   rB   z&DeprecatedMixin.check_deprecated_class   sb    
 & 	 	JT44X>>>   &TX8N !   	 	r2   c                    t          |j        t          j                  r[t          |j        j        t          j                  r9|j        j        j        }|j        j        }|                     |||f           dS dS dS )z$Checks if call the deprecated class.N)	rQ   r,   r   rz   exprr|   r:   r{   rB   )r.   r&   rC   rD   s       r0   r+   z.DeprecatedMixin.check_deprecated_class_in_call   s     di11 	GjINEJ7
 7
 	G y~*H+J''hFFFFF	G 	G 	G 	Gr2   N)r&   r'   r(   r)   )r&   r3   r(   r)   )r(   rF   )r&   rK   r(   r)   )r&   rX   r(   r)   )r(   r_   )rb   rc   r(   rd   )ri   rc   r(   rF   )r&   r3   rl   rm   r(   r)   )r&   r'   r/   rp   r(   r)   )r&   rp   rC   rc   r]   rF   r(   r)   )__name__
__module____qualname____doc__r   __annotations__r   r   r!   r%   r   only_required_for_messagesr1   rE   rI   rW   r^   ra   rf   rh   rk   r@   r-   rB   r+   r7   r2   r0   r   r      s          	"8=>$OO	
D     	*S=>$OO	
D     	9!U?@DQQ	
F     	4R<=NN	
C     	-"V@ATRR	
G      &U% 
9 9 9 
9 &U% K K K	 K    &U%&<==L L L >=L &U% A A A	 A      4   
 
 
 
P P P P# # # #J	 	 	 	G G G G G Gr2   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ClassDefry   r   r7   r2   r0   <module>r      s!  
 2 1 " " " " " " / / / / / / / /              ! ! ! ! ! ! 4 4 4 4 4 4 H H H H H H H H H H 0 0 0 0 0 0 		N	 bG bG bG bG bGk bG bG bG bG bGr2   