o
    g#                     @   s   d Z ddlmZ ddlmZmZmZmZ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 e	je	je
je
jfZG d	d
 d
eZdS )z+Checker mixin for deprecated functionality.    )chain)Any	ContainerIterableTupleUnionN)nodes)utils)BaseChecker)get_import_name	infer_all
safe_inferc                   @   s0  e Zd ZU dZddddddZeed< ed	d
dde	j
ddfddZeddde	jddfddZdefddZedde	jddfddZeddde	jddfddZdee fddZdedeeeedf ef  fddZdefd d!Zd"edefd#d$Zd%d& Zd'd( Zd)d* Zd+d, Z dS )-DeprecatedMixinzA mixin implementing logic for checking deprecated symbols.
    A class implementing mixin must define "deprecated-method" Message.
    )zUsing deprecated method %s()deprecated-methodzEThe method is marked as deprecated and will be removed in the future.)z+Using deprecated argument %s of method %s()deprecated-argumentzGThe argument is marked as deprecated and will be removed in the future.)zUses of a deprecated module %rdeprecated-modulez*A module marked as deprecated is imported.)z&Using deprecated class %s of module %sdeprecated-classzDThe class is marked as deprecated and will be removed in the future.)zUsing deprecated decorator %s()deprecated-decoratorzHThe decorator is marked as deprecated and will be removed in the future.)W1505W1511W0402W1512W1513msgsr   r   r   nodereturnNc                 C   s*   |  | t|jD ]}| || q
dS )z2Called when a :class:`nodes.Call` node is visited.N)check_deprecated_class_in_callr   funccheck_deprecated_method)selfr   inferred r!   X/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/checkers/deprecated.py
visit_call8   s   
zDeprecatedMixin.visit_callr   c                 C   sN   dd |j D D ]}| || d|v r$|dd\}}| |||f qdS )z*triggered when an import statement is seenc                 s       | ]\}}|V  qd S Nr!   .0name_r!   r!   r"   	<genexpr>J       z/DeprecatedMixin.visit_import.<locals>.<genexpr>.   N)namescheck_deprecated_modulesplitcheck_deprecated_class)r   r   r(   mod_name
class_namer!   r!   r"   visit_importD   s   zDeprecatedMixin.visit_importc                 C      dS )zCallback returning the deprecated decorators.

        Returns:
            collections.abc.Container of deprecated decorator names.
        r!   r!   r   r!   r!   r"   deprecated_decoratorsQ      z%DeprecatedMixin.deprecated_decoratorsr   c                 C   st   t | }|s
dS t|d tjrt|d j}nt|d }|r&| nd}||  v r8| j	d||d dS dS )z,Triggered when a decorator statement is seenNr   r   r   args)
listget_children
isinstancer   Callr   r   qnamer7   add_message)r   r   childreninfr?   r!   r!   r"   visit_decoratorsZ   s   z DeprecatedMixin.visit_decoratorsc                 C   s>   |j }t||}| || dd |jD }| ||| dS )z'triggered when a from statement is seenc                 s   r$   r%   r!   r&   r!   r!   r"   r*   q   r+   z3DeprecatedMixin.visit_importfrom.<locals>.<genexpr>N)modnamer   r/   r.   r1   )r   r   basenameclass_namesr!   r!   r"   visit_importfromh   s
   
z DeprecatedMixin.visit_importfromc                 C   r5   )zCallback returning the deprecated methods/functions.

        Returns:
            collections.abc.Container of deprecated function/method names.
        r!   r!   r6   r!   r!   r"   deprecated_methodst   r8   z"DeprecatedMixin.deprecated_methodsmethodc                 C   r5   )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!   )r   rI   r!   r!   r"   deprecated_arguments}   s   z$DeprecatedMixin.deprecated_argumentsc                 C   r5   )zCallback returning the deprecated modules.

        Returns:
            collections.abc.Container of deprecated module names.
        r!   r!   r6   r!   r!   r"   deprecated_modules   r8   z"DeprecatedMixin.deprecated_modulesmodulec                 C   r5   )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!   )r   rL   r!   r!   r"   deprecated_classes   s   z"DeprecatedMixin.deprecated_classesc                 C   s8   |   D ]}||ks||d r| jd||d qdS )z"Checks if the module is deprecatedr,   r   r9   N)rK   
startswithr@   )r   r   mod_pathr2   r!   r!   r"   r/      s
   z'DeprecatedMixin.check_deprecated_modulec           
         s>  t |tsdS t |jtjr|jj}nt |jtjr|jj}ndS t|j	dr<|j	
 r<|
 |j	
  d| |h}n|
 |h}t fdd|D rX jd||fd dS t|j}|jrhdd	 |jD ni } fd
d|D }t| D ]%\}}	|	|v r jd||	|fd qw|dur||k r jd||	|fd qwdS )zExecutes the checker for the given node. This method should
        be called from the checker implementing this mixin.
        Nr?   r,   c                 3   s    | ]	}|   v V  qd S r%   )rH   )r'   r(   r6   r!   r"   r*      s    z:DeprecatedMixin.check_deprecated_method.<locals>.<genexpr>r   r9   c                 S   s   h | ]}|j qS r!   )arg)r'   kwr!   r!   r"   	<setcomp>   s    z:DeprecatedMixin.check_deprecated_method.<locals>.<setcomp>c                 3   s    | ]}  |V  qd S r%   )rJ   )r'   qnr6   r!   r"   r*      s    r   )r=   ACCEPTABLE_NODESr   r   	AttributeattrnameNamer(   hasattrparentr?   anyr@   lenr:   keywordsr   )
r   r   r    	func_nameqnamesnum_of_argskwargsrJ   positionarg_namer!   r6   r"   r      s<   





z'DeprecatedMixin.check_deprecated_methodc                 C   s0   |D ]}||  |v r| jd|||fd qdS )z!Checks if the class is deprecatedr   r9   N)rM   r@   )r   r   r2   rF   r3   r!   r!   r"   r1      s   
z&DeprecatedMixin.check_deprecated_classc                 C   sL   t |jtjr"t |jjtjr$|jjj}|jj}| |||f dS dS dS )z#Checks if call the deprecated classN)	r=   r   r   rU   exprrW   r(   rV   r1   )r   r   r2   r3   r!   r!   r"   r      s   

z.DeprecatedMixin.check_deprecated_class_in_call)!__name__
__module____qualname____doc__r   r   __annotations__r	   check_messagesr   r>   r#   Importr4   r   r7   
DecoratorsrC   
ImportFromrG   r   strrH   r   r   intrJ   rK   rM   r/   r   r1   r   r!   r!   r!   r"   r      sN   
 			
	-	r   )rg   	itertoolsr   typingr   r   r   r   r   astroidr   pylint.checkersr	   pylint.checkers.base_checkerr
   pylint.checkers.utilsr   r   r   BoundMethodUnboundMethodFunctionDefClassDefrT   r   r!   r!   r!   r"   <module>   s   