
    yIfx+                        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 dd
lmZmZmZ ddlmZ ddlmZ ej        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)Instance)utils)BaseChecker)get_import_name	infer_all
safe_infer)	INFERENCE)MessageDefinitionTuplec                  @   e Zd ZU dZddddddi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"<   d#d$d%d&d'gddfiZ
ded(<    ej        d          dNd-            Z ej        ddd          dOd/            Z ej        dd          dPd1            ZdQd3Z ej        d%          dRd5            Z ej        dd          dSd7            ZdTd9ZdUd=ZdQd>ZdVd@ZdQdAZdNdBZdWdEZdXdHZdYdKZdOdLZdMS )ZDeprecatedMixinzA mixin implementing logic for checking deprecated symbols.

    A class implementing mixin must define "deprecated-method" Message.
    W4906zUsing deprecated attribute %rdeprecated-attributezHThe attribute is marked as deprecated and will be removed in the future.sharedTz!dict[str, MessageDefinitionTuple]DEPRECATED_ATTRIBUTE_MESSAGEW4901zDeprecated module %rdeprecated-modulez*A module marked as deprecated is imported.)W0402zold-deprecated-module)	old_namesr   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astroid.AttributereturnNonec                0    |                      |           dS )z3Called when an `astroid.Attribute` node is visited.N)check_deprecated_attribute)selfr+   s     N/var/www/piapp/venv/lib/python3.11/site-packages/pylint/checkers/deprecated.pyvisit_attributezDeprecatedMixin.visit_attribute[   s     	''-----    
nodes.Callc                    |                      |           t          |j                  D ]}|                     ||           dS )z2Called when a :class:`nodes.Call` node is visited.N)check_deprecated_class_in_callr   funccheck_deprecated_method)r1   r+   inferreds      r2   
visit_callzDeprecatedMixin.visit_call`   sT     	++D111!$),, 	9 	9H((x8888	9 	9r4   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      r2   	<genexpr>z/DeprecatedMixin.visit_import.<locals>.<genexpr>r   s&      44gdAT444444r4   .   N)namescheck_deprecated_modulesplitcheck_deprecated_class)r1   r+   rC   mod_name
class_names        r2   visit_importzDeprecatedMixin.visit_importl   s     54444 	K 	KD((t444d{{'+zz#q'9'9$*++D(ZMJJJ	K 	Kr4   Iterable[str]c                    dS )zCallback returning the deprecated decorators.

        Returns:
            collections.abc.Container of deprecated decorator names.
        r@   r@   r1   s    r2   deprecated_decoratorsz%DeprecatedMixin.deprecated_decoratorsy   	     rr4   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   r8   qnamerR   add_message)r1   r+   childreninfr\   s        r2   visit_decoratorsz DeprecatedMixin.visit_decorators   s     ))++,, 	Fhqk5:.. 	*Xa[-..CCXa[))C",		D..00003$UKKKKK 10r4   nodes.ImportFromc                    |j         }t          ||          }|                     ||           d |j        D             }|                     |||           dS )z(Triggered when a from statement is seen.c              3      K   | ]	\  }}|V  
d S r?   r@   rA   s      r2   rE   z3DeprecatedMixin.visit_importfrom.<locals>.<genexpr>   s&      66at666666r4   N)modnamer   rI   rH   rK   )r1   r+   basenameclass_namess       r2   visit_importfromz DeprecatedMixin.visit_importfrom   sc     <"422$$T8444664:666##D(K@@@@@r4   Container[str]c                    dS )zCallback returning the deprecated methods/functions.

        Returns:
            collections.abc.Container of deprecated function/method names.
        r@   r@   rQ   s    r2   deprecated_methodsz"DeprecatedMixin.deprecated_methods   rS   r4   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'))
        r@   r@   )r1   rk   s     r2   deprecated_argumentsz$DeprecatedMixin.deprecated_arguments   s	    0 rr4   c                    dS )zCallback returning the deprecated modules.

        Returns:
            collections.abc.Container of deprecated module names.
        r@   r@   rQ   s    r2   deprecated_modulesz"DeprecatedMixin.deprecated_modules   rS   r4   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.
        r@   r@   )r1   rr   s     r2   deprecated_classesz"DeprecatedMixin.deprecated_classes   s	     rr4   c                    dS )z-Callback returning the deprecated attributes.r@   r@   rQ   s    r2   deprecated_attributesz%DeprecatedMixin.deprecated_attributes   s    rr4   c                ^   t          |j                  }t          |t          j        t
          t          j        f          sdS d                    |                                |j	        f          }| 
                                D ]'}||k    r|                     d||ft                     (dS )z&Checks if the attribute is deprecated.NrF   r   )r+   rW   
confidence)r   exprrZ   r   ClassDefr   Modulejoinr\   attrnamerv   r]   r   )r1   r+   inferred_exprattribute_qnamedeprecated_names        r2   r0   z*DeprecatedMixin.check_deprecated_attribute   s    "49---%.(EL)QRR 	F((M$7$7$9$94=#IJJ#99;; 	 	O/11  *)+(	 !   	 	r4   mod_path
str | Nonec                    |                                  D ]:}||k    s|r0|                    |dz             r|                     d||           ;dS )z#Checks if the module is deprecated.rF   r   rV   N)rq   
startswithr]   )r1   r+   r   rL   s       r2   rI   z'DeprecatedMixin.check_deprecated_module   sp    //11 	P 	PH8##x#H4G4GSV4W4W#  !44h OOO	P 	Pr4   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 r?   )rj   )rB   rC   r1   s     r2   rE   z:DeprecatedMixin.check_deprecated_method.<locals>.<genexpr>   s4      DDTtt..000DDDDDDr4   r   rV   c                    h | ]	}|j         
S r@   )arg)rB   kws     r2   	<setcomp>z:DeprecatedMixin.check_deprecated_method.<locals>.<setcomp>  s    111R"&111r4   c              3  B   K   | ]}                     |          V  d S r?   )ro   )rB   qnr1   s     r2   rE   z:DeprecatedMixin.check_deprecated_method.<locals>.<genexpr>  s1      OO" 9 9" = =OOOOOOr4   r    )rZ   ACCEPTABLE_NODESr8   r   	Attributer}   NamerC   r\   anyr]   lenrW   keywordsr   )
r1   r+   r:   	func_nameqnamesnum_of_argskwargsro   positionarg_names
   `         r2   r9   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 !   
	 
	r4   rL   rf   c                r    |D ]3}||                      |          v r|                     d|||f           4dS )z"Checks if the class is deprecated.r$   rV   N)rt   r]   )r1   r+   rL   rf   rM   s        r2   rK   z&DeprecatedMixin.check_deprecated_class  s`    
 & 	 	JT44X>>>>  &TX8N !   	 	r4   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)	rZ   r8   r   r   ry   r   rC   r}   rK   )r1   r+   rL   rM   s       r2   r7   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r4   N)r+   r,   r-   r.   )r+   r5   r-   r.   )r+   r<   r-   r.   )r-   rO   )r+   rT   r-   r.   )r+   ra   r-   r.   )r-   rh   )rk   rl   r-   rm   )rr   rl   r-   rO   )r+   r<   r   r   r-   r.   )r+   r5   r:   r   r-   r.   )r+   r   rL   rl   rf   rO   r-   r.   )__name__
__module____qualname____doc__r   __annotations__r   r   r"   r&   r*   r	   only_required_for_messagesr3   r;   rN   rR   r`   rg   rj   ro   rq   rt   rv   r0   rI   r9   rK   r7   r@   r4   r2   r   r      s          	+"Vt	
G      	"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%&<==. . . >=. &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r4   r   )r   
__future__r   collections.abcr   r   	itertoolsr   astroidr   astroid.basesr   pylint.checkersr	   pylint.checkers.base_checkerr
   pylint.checkers.utilsr   r   r   pylint.interfacesr   pylint.typingr   BoundMethodUnboundMethodFunctionDefrz   r   r   r   r@   r4   r2   <module>r      sK  
 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 CG CG CG CG CGk CG CG CG CG CGr4   