
    c{                        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 d dlmZ d dlmZ erd dlmZ  G d	 d
e	          ZddZdS )    )annotations)TYPE_CHECKING)InstanceUninferablenodes)BaseChecker)
safe_infer)DUNDER_METHODS)HIGH)PyLinterc                  N    e Zd ZdZdZdZddiZdZdd	Ze	dd            Z
ddZdS )DunderCallCheckera  Check for unnecessary dunder method calls.

    Docs: https://docs.python.org/3/reference/datamodel.html#basic-customization
    We exclude names in list pylint.constants.EXTRA_DUNDER_METHODS such as
    __index__ (see https://github.com/PyCQA/pylint/issues/6795)
    since these either have no alternative method of being called or
    have a genuine use case for being called manually.

    Additionally, we exclude classes that are not instantiated since these
    might be used to access the dunder methods of a base class of an instance.
    We also exclude dunder method calls on super() since
    these can't be written in an alternative manner.
    unnecessary-dunder-callC2801)z)Unnecessarily calls dunder method %s. %s.r   ziUsed when a dunder method is manually called instead of using the corresponding function/method/operator. returnNonec                    i | _         t          j                    D ]4\  }}|| j        j        j        k    r| j                             |           5d S N)_dunder_methodsr
   itemslinterconfig
py_versionupdate)self
since_versdunder_methodss      >lib/python3.11/site-packages/pylint/checkers/dunder_methods.pyopenzDunderCallChecker.open/   s^    /1*8*>*@*@ 	< 	<&JT[/:: <$++N;;;	< 	<    nodenodes.NodeNGboolc                    | j         }|Yt          |t          j                  r6|j                            d          r|j                            d          rdS |j         }|YdS )zACheck if dunder method call is within a dunder method definition.N__TF)parent
isinstancer   FunctionDefname
startswithendswith)r#   r(   s     r    within_dunder_defz#DunderCallChecker.within_dunder_def5   sy      	#65#455K**400 K((..
 t]F  	# ur"   
nodes.Callc                h   t          |j        t          j                  r|j        j        | j        v r|                     |          st          |j        j        t          j                  rCt          |j        j        j        t          j	                  r|j        j        j        j
        dk    st          |j        j                  }|dt          hv st          |t                    sdS |                     d||j        j        | j        |j        j                 ft                     dS dS dS dS dS )z=Check if method being called is an unnecessary dunder method.superNr   )r#   args
confidence)r)   funcr   	Attributeattrnamer   r.   exprCallNamer+   r	   r   r   add_messager   )r   r#   inf_exprs      r    
visit_callzDunderCallChecker.visit_callC   sD    ty%/22		"d&::	 **400	
 49>5:66	 ty~2EJ??	 IN',7	 "$).11H{ 33 z(H7U7U )i($*>ty?Q*RS	      	 	 	 	 	 	 	 	r"   N)r   r   )r#   r$   r   r%   )r#   r/   r   r   )__name__
__module____qualname____doc__r+   prioritymsgsoptionsr!   staticmethodr.   r<   r   r"   r    r   r      s          %DH 
D G< < < <    \     r"   r   r   r   r   r   c                J    |                      t          |                      d S r   )register_checkerr   )r   s    r    registerrG   \   s%    
-f5566666r"   N)r   r   r   r   )
__future__r   typingr   astroidr   r   r   pylint.checkersr   pylint.checkers.utilsr	   pylint.constantsr
   pylint.interfacesr   pylint.lintr   r   rG   r   r"   r    <module>rP      s   
 # " " " " "             0 0 0 0 0 0 0 0 0 0 ' ' ' ' ' ' , , , , , , + + + + + + " " " " " " %$$$$$$E E E E E E E EP7 7 7 7 7 7r"   