
    yIfD                        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dS )    )annotations)TYPE_CHECKING)Instancenodes)UninferableBase)BaseChecker)
safe_infer)DUNDER_METHODS)UNNECESSARY_DUNDER_CALL_LAMBDA_EXCEPTIONS)HIGH)PyLinterc                  b    e 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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/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. 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      R/var/www/piapp/venv/lib/python3.11/site-packages/pylint/checkers/dunder_methods.pyopenzDunderCallChecker.open/   s\    /1*8*>*@*@ 	< 	<&JT[/:::$++N;;;	< 	<    nodenodes.NodeNGboolc                    | j         }|tt          |t          j                  r4|j                            d          r|j                            d          st                              ||           rdS |j         }|tdS )zACheck if dunder method call is within a dunder method definition.N__TF)	parent
isinstancer   FunctionDefname
startswithendswithr   is_lambda_rule_exception)r#   r(   s     r    within_dunder_or_lambda_defz-DunderCallChecker.within_dunder_or_lambda_def5   s      65#455K**400 K((.. %==fdKK	 t]F   ur"   ancestorc                \    t          | t          j                  o|j        j        t
          v S r   )r)   r   Lambdafuncattrnamer   )r0   r#   s     r    r.   z*DunderCallChecker.is_lambda_rule_exceptionD   s,     x.. P	"&OO	
r"   
nodes.Callc                d   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                  }|t          |t          t          f          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)   r3   r   	Attributer4   r   r/   exprCallNamer+   r	   r   r   add_messager   )r   r#   inf_exprs      r    
visit_callzDunderCallChecker.visit_callK   s-    ty%/22		"d&:::44T:: ; 49>5:66 ; ty~2EJ??	 ;
 IN',77 "$).11H Jx(O9T$U$U  )i($*>ty?Q*RS	      #	 	::::
 87r"   N)r   r   )r#   r$   r   r%   )r0   r$   r#   r$   r   r%   )r#   r5   r   r   )__name__
__module____qualname____doc__r+   msgsoptionsr!   staticmethodr/   r.   r@   r   r"   r    r   r      s          %D 
D G< < < <    \ 
 
 
 \
     r"   r   r   r   r   r   c                J    |                      t          |                      d S r   )register_checkerr   )r   s    r    registerrJ   f   s%    
-f556666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   rJ   r   r"   r    <module>rT      s  
 # " " " " "             # # # # # # # # ( ( ( ( ( ( ' ' ' ' ' ' , , , , , , V V V V V V V V " " " " " " %$$$$$$N N N N N N N Nb7 7 7 7 7 7r"   