
    eV                        d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ erd d	lmZ  G d
 de
      ZddZy)    )annotations)TYPE_CHECKING)Instancenodes)UninferableBase)BaseChecker)
safe_infer)DUNDER_METHODS)UNNECESSARY_DUNDER_CALL_LAMBDA_EXCEPTIONS)HIGH)PyLinterc                  X    e Zd ZdZdZdZddiZdZddZe	dd       Z
e	dd	       Zdd
Zy)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/pylint-dev/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. c                    i | _         t        j                         D ]D  \  }}|| j                  j                  j
                  k  s*| j                   j                  |       F y N)_dunder_methodsr
   itemslinterconfig
py_versionupdate)self
since_versdunder_methodss      @/usr/lib/python3/dist-packages/pylint/checkers/dunder_methods.pyopenzDunderCallChecker.open0   sS    /1*8*>*>*@ 	<&JT[[//:::$$++N;	<    c                   | j                   }|vt        |t        j                        r6|j                  j                  d      r|j                  j                  d      st        j                  ||       ry|j                   }|vy)zACheck if dunder method call is within a dunder method definition.__TF)	parent
isinstancer   FunctionDefname
startswithendswithr   is_lambda_rule_exception)noder$   s     r   within_dunder_or_lambda_defz-DunderCallChecker.within_dunder_or_lambda_def6   sp      65#4#45KK**40KK((.$==fdK]]F   r!   c                r    t        | t        j                        xr |j                  j                  t
        v S r   )r%   r   Lambdafuncattrnamer   )ancestorr+   s     r   r*   z*DunderCallChecker.is_lambda_rule_exceptionE   s0     x. P		""&OO	
r!   c                   t        |j                  t        j                        rT|j                  j                  | j
                  v r0| j                  |      st        |j                  j                  t        j                        ret        |j                  j                  j                  t        j                        r-|j                  j                  j                  j                  dk(  st        |j                  j                        }|t        |t        t        f      sy| j                  d||j                  j                  | j
                  |j                  j                     ft               yyyyy)z=Check if method being called is an unnecessary dunder method.superNr   )r+   args
confidence)r%   r/   r   	Attributer0   r   r,   exprCallNamer'   r	   r   r   add_messager   )r   r+   inf_exprs      r   
visit_callzDunderCallChecker.visit_callL   s    tyy%//2		""d&:&::44T:499>>5::6tyy~~22EJJ?IINN'',,7 "$))..1H Jx(O9T$U )ii(($*>*>tyy?Q?Q*RS	   8	 ; ; 3r!   N)returnNone)r+   nodes.NodeNGr=   bool)r1   r?   r+   r?   r=   r@   )r+   z
nodes.Callr=   r>   )__name__
__module____qualname____doc__r'   prioritymsgsoptionsr    staticmethodr,   r*   r<   r   r!   r   r   r      s[     %DH 
D G<   
 
r!   r   c                8    | j                  t        |              y r   )register_checkerr   )r   s    r   registerrK   g   s    
-f56r!   N)r   r   r=   r>   )
__future__r   typingr   astroidr   r   astroid.utilr   pylint.checkersr   pylint.checkers.utilsr	   pylint.constantsr
   r   pylint.interfacesr   pylint.lintr   r   rK   r   r!   r   <module>rU      s9   
 #   # ( ' , V "$O Od7r!   