o
    b                     @   sj  d Z ddlmZ ddlZddlmZmZ ddlZddlZddl	m
Z
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 ddlmZ ddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z) ej*dkr|dZ+ndZ+h dZ,e-ddZ.e-ddZ/dd Z0dd Z1dd Z2dd Z3dd Z4d d! Z5d"d# Z6d$d% Z7d&d' Z8d(d) Z9d*d+ Z:d,d- Z;d.d/ Z<d0d1 Z=dpd2d3Z>d4d5 Z?i d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcddZ@G dedf dfZAG dgdh dheZBG didj djeZCdqdldmZDdndo ZEdS )rz classes checker for Python code
    )
generatorsN)chainzip_longest)	GeneratorBUILTINS)InconsistentMroErrorDuplicateBasesError)
decorators)objects)function_to_method)IAstroidChecker)BaseChecker)	PYMETHODSSPECIAL_METHODS_PARAMSoverrides_a_methodcheck_messagesis_attr_privateis_attr_protectednode_frame_classis_builtin_objectdecorated_with_propertyunimplemented_abstract_methodsdecorated_withclass_is_abstract
safe_inferhas_known_basesis_iterableis_comprehensionget_global_option)   r   __next__next>   boolrangeslice
memoryview_CallSignaturez!args kws starred_args starred_kws_ParameterSignaturezargs kwonlyargs varargs kwargsc                 C   s   i }g }g }g }| j pg D ]*}|j|j}}|d u r't|tjr'||j qt|tjr3|j||< qd ||< q| jD ])}t|tj	rRt|jtjrR||jj q;t|tjr_||j q;|d  q;t
||||S N)keywordsargvalue
isinstanceastroidNameappendnameargsStarredr'   )callkwsr2   starred_kwsstarred_argskeywordr+   r,    r9   V/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/checkers/classes.py_signature_from_callU   s$   

r;   c                 C   s:   | j }| j}dd | jD }dd | jD }t||||S )Nc                 S   s   g | ]
}|j d kr|j qS selfr1   .0r+   r9   r9   r:   
<listcomp>u   s    z-_signature_from_arguments.<locals>.<listcomp>c                 S      g | ]}|j qS r9   r>   r?   r9   r9   r:   rA   v       )kwargvarargr2   
kwonlyargsr(   )	argumentsrD   rE   r2   rF   r9   r9   r:   _signature_from_argumentsr   s
   rH   c           
         s   | j r
| j  jv }n j }| jr| j jv }n j }t fdd| jD }| j jk}d} jrK jD ]}| jv }|| jv }	|sJ|	sJd} nq6t|||||fS )z8Check if a definition signature is equivalent to a call.c                 3   s    | ]}| j v V  qd S r)   )r5   )r@   kwr4   r9   r:   	<genexpr>       z1_definition_equivalent_to_call.<locals>.<genexpr>TF)kwargsr6   varargsr7   allrF   r2   r5   )
Z
definitionr4   Zsame_kw_variadicsZsame_args_variadicsZsame_kwonlyargsZ	same_argsZno_additional_kwarg_argumentsr8   Zis_argZ	is_kwonlyr9   rJ   r:   _definition_equivalent_to_callz   s2   


rP   c                 C   s"   | j j }| jdv r|dd  }|S )N)classmethodmethod   )r2   type)rR   
positionalr9   r9   r:   _positional_parameters   s   
rV   c                 C   s    |D ]}t | |r|  S qdS )z
    Return the type of the node if it exists in potential_types.

    Args:
        node (astroid.node): node to get the type of.
        potential_types (tuple): potential types of the node.

    Returns:
        type: type of the node or None.
    N)r-   )nodeZpotential_typesZpotential_typer9   r9   r:   _get_node_type   s
   
rX   c                 C   s   t | |t ||kS )a}  
    Check equality of nodes based on the comparison of their attributes named attr_name.

    Args:
        node_a (astroid.node): first node to compare.
        node_b (astroid.node): second node to compare.
        attr_name (str): name of the nodes attribute to use for comparison.

    Returns:
        bool: True if node_a.attr_name == node_b.attr_name, False otherwise.
    )getattr)Znode_aZnode_b	attr_namer9   r9   r:   _check_arg_equality   s   r[   c              	      s*  | j du s
|j du rdS t| j | j}dd |D }t  |D ]s}z| |}W n tjjy5    }Y nw z||}W n tjjyJ    }Y nw  fdd||fD }t|rat	|sa dS tj
dtjdtjd	tjd	i}td
d |D }	t||	}
|
rt||
s dS t||||
 s dS qdS )a0  
    Check if original and overridden methods arguments have different default values

    Return True if one of the overridden arguments has a default
    value different from the default value of the original argument
    If one of the method doesn't have argument (.args is None)
    return False
    NFc                 S   rB   r9   r>   r@   paramr9   r9   r:   rA      rC   z;_has_different_parameters_default_value.<locals>.<listcomp>c                    s   g | ]}| kqS r9   r9   r?   Zdefault_missingr9   r:   rA          Tr,   r1   eltsc                 s   s    | ]}|V  qd S r)   r9   )r@   Zastroid_typer9   r9   r:   rK      s    
z:_has_different_parameters_default_value.<locals>.<genexpr>)r2   r   rF   objectdefault_valuer.   
exceptionsZ	NoDefaultanyrO   ConstClassDefTupleListtuplerX   r-   r[   )original
overriddenall_argsZoriginal_param_names
param_nameZoriginal_defaultZoverridden_defaultZdefault_listZastroid_type_compared_attrZhandled_typesZoriginal_typer9   r^   r:   '_has_different_parameters_default_value   sR   	


rn   c                 C   sd   t | |}|D ](\}}||f}t|s dS dd |D }tt|j|r&q|j|jkr/ dS qdS )NTc                 S   rB   r9   r>   r\   r9   r9   r:   rA   	  rC   z-_has_different_parameters.<locals>.<listcomp>F)r   rO   rd   mapmatchr1   )rj   rk   dummy_parameter_regexZzippedZoriginal_paramZoverridden_paramparamsnamesr9   r9   r:   _has_different_parameters  s   
rt   c           	      C   s   t | }t |}t|||}t| jj|jj|}| jtv r!d }}tdd | jj|jjfD dk}tdd | jj|jjfD dk}t	||||fS )aE  Determine if the two methods have different parameters

    They are considered to have different parameters if:

       * they have different positional parameters, including different names

       * one of the methods is having variadics, while the other is not

       * they have different keyword only parameters.

    Fc                 s       | ]}|sd V  qdS rS   Nr9   r\   r9   r9   r:   rK   2      z(_different_parameters.<locals>.<genexpr>rS   c                 s   ru   rv   r9   r\   r9   r9   r:   rK   6  rw   )
rV   rt   r2   rF   r1   r   sumrD   rE   rd   )	rj   rk   rq   Zoriginal_parametersZoverridden_parametersZdifferent_positionalZdifferent_kwonlyZdifferent_kwargZdifferent_varargr9   r9   r:   _different_parameters  s*   

ry   c                 C   s   | j tv ot| S r)   )r1   INVALID_BASE_CLASSESr   clsr9   r9   r:   _is_invalid_base_class?  s   r}   c              
   C   s   |  |}|D ]9}z+| D ]$}t|tjr2z| d | d W n
 tjy,   Y qw  W  dS qW q tjy@   Y  dS w dS )N__get____set__TF)rY   inferr-   r.   InstanceNotFoundErrorInferenceError)r|   attr
attributes	attributeinferredr9   r9   r:   _has_data_descriptorC  s$   


	r   c           	      C   s   t | tjsdS |D ]V}z||}W n
 tjy   Y q
w |D ]?}|tjD ]6}z	t|j	 }W n tj
tfy?   Y q(w t |tjsGq(|j}t |tjrS|j}|j| jkr^   dS q(q q
dS )z Check if the func was called in any of the given methods,
    belonging to the *klass*. Returns True if so, False otherwise.
    FT)r-   r.   FunctionDefrY   r   nodes_of_classCallr"   funcr   r   StopIterationZBoundMethod_proxiedZUnboundMethodr1   )	r   klassmethodsrR   inferedZinfer_methodr4   boundZfunc_objr9   r9   r:   _called_in_methodsV  s4   
r   c              	   C   s   z| | }W n tjy   Y dS w dt}|D ]1}|tju r"qzt| }W n
 tjy4   Y qw t	|tj
rBt|rB dS | |krK dS qdS )a4   Check if the given attribute *name* is a property
    in the given *klass*.

    It will look for `property` calls or for functions
    with the given name, decorated by `property` or `property`
    subclasses.
    Returns ``True`` if the name is a property in the given klass,
    ``False`` otherwise.
    Fz{}.propertyT)rY   r.   r   formatr   Uninferabler"   r   r   r-   r   r   Zpytype)r1   r   r   Zproperty_namer   r   r9   r9   r:   _is_attribute_propertyq  s,   

r   c                 C   s>   |  tjD ]}|j}t|tjr|jdkr|js dS qdS )NsuperTF)r   r.   r   r   r-   r/   r1   r2   )Zfundef_noder4   r   r9   r9   r:   _has_bare_super_call  s   r   c                 C   s~   z| j ||d}t|}W n tjy   Y dS  ty!   Y dS w zt| W dS  tjy4   Y dS  ty>   | Y S w )z
    Safely infer the return value of a function.

    Returns None if inference failed or if there is some ambiguity (more than
    one node has been inferred). Otherwise returns infered value.
    )contextN)infer_call_resultr"   r.   r   r   )rW   Zcallerr   Zinferitr,   r9   r9   r:   _safe_infer_call_result  s    r   c                 C   s@   t | }t|tjr| }tdd t| |D rdS dS )Nc                 s   s(    | ]\}}|o|o|j |j kV  qd S r)   r,   )r@   Z
first_slotZsecond_slotr9   r9   r:   rK     s
    
z)_has_same_layout_slots.<locals>.<genexpr>TF)r"   r   r-   r.   rf   slotsrO   r   )r   Zassigned_valuer   Zother_slotsr9   r9   r:   _has_same_layout_slots  s   r   ZF0202)z+Unable to check methods signature (%s / %s)method-check-failedzUsed when Pylint has been unable to check methods signature compatibility for an unexpected reason. Please report this kind if you don't make sense of it.ZE0202)z4An attribute defined in %s line %s hides this methodmethod-hiddenz~Used when a class defines a method which is hidden by an instance attribute from an ancestor class or set by some client code.ZE0203)z1Access to member %r before its definition line %saccess-member-before-definitionzGUsed when an instance member is accessed before it's actually assigned.ZW0201)z%Attribute %r defined outside __init__attribute-defined-outside-initzGUsed when an instance attribute is defined outside the __init__ method.ZW0212)z1Access to a protected member %s of a client classprotected-accesszUsed when a protected member (i.e. class member with a name beginning with an underscore) is access outside the class or a descendant of the class where it's defined.ZE0211)zMethod has no argumentno-method-argumentzbUsed when a method which should have the bound instance as first argument has no argument defined.ZE0213)z+Method should have "self" as first argumentno-self-argumentzUsed when a method has an attribute different the "self" as first argument. This is considered as an error since this is a so common convention that you shouldn't break it!ZC0202)z0Class method %s should have %s as first argumentbad-classmethod-argumentzUsed when a class method has a first argument named differently than the value specified in valid-classmethod-first-arg option (default to "cls"), recommended to easily differentiate them from regular instance methods.ZC0203)z4Metaclass method %s should have %s as first argumentbad-mcs-method-argumentzUsed when a metaclass method has a first argument named differently than the value specified in valid-classmethod-first-arg option (default to "cls"), recommended to easily differentiate them from regular instance methods.ZC0204)z:Metaclass class method %s should have %s as first argumentbad-mcs-classmethod-argumentzUsed when a metaclass class method has a first argument named differently than the value specified in valid-metaclass-classmethod-first-arg option (default to "mcs"), recommended to easily differentiate them from regular instance methods.ZW0211)z'Static method with %r as first argumentbad-staticmethod-argumentzUsed when a static method has "self" or a value specified in valid-classmethod-first-arg option or valid-metaclass-classmethod-first-arg option as first argument.ZR0201)zMethod could be a functionno-self-usezYUsed when a method doesn't use its bound instance, and so could be written as a function.ZW0221)z#Parameters differ from %s %r methodarguments-differztUsed when a method has a different number of arguments than in the implemented interface or in an overridden method.ZW0222)z#Signature differs from %s %r methodsignature-differszgUsed when a method signature is different than in the implemented interface or in an overridden method.ZW0223)z7Method %r is abstract in class %r but is not overriddenabstract-methodzbUsed when an abstract method (i.e. raise NotImplementedError) is not overridden in concrete class.ZW0231)z0__init__ method from base class %r is not calledsuper-init-not-calledzaUsed when an ancestor class method has an __init__ method which is not called by a derived class.ZW0232)zClass has no __init__ methodno-initzEUsed when a class has no __init__ method, neither its parent classes.)z9__init__ method from a non direct base class %r is callednon-parent-init-calledznUsed when an __init__ method is called on a class which is not in the direct ancestors for the analysed class.)z%Useless super delegation in method %ruseless-super-delegationzUsed whenever we can detect that an overridden method is useless, relying on super() delegation to do the same thing as another method from the MRO.)zCInvalid object %r in __slots__, must contain only non empty stringsinvalid-slots-objectz=Used when an invalid (non-string) object occurs in __slots__.)z4Assigning to attribute %r not defined in class slotsassigning-non-slotzCUsed when assigning to an attribute not defined in the class slots.)zInvalid __slots__ objectinvalid-slotszhUsed when an invalid __slots__ is found in class. Only a string, an iterable or a sequence is permitted.)z$Inheriting %r, which is not a class.inherit-non-classz?Used when a class inherits from something which is not a class.)z1Inconsistent method resolution order for class %rinconsistent-mroz>Used when a class has an inconsistent method resolution order.)zDuplicate bases for class %rduplicate-basesz&Used when a class has duplicate bases.)z9Consider using a decorator instead of calling classmethodno-classmethod-decoratorzGUsed when a class method is defined without using the decorator syntax.)z:Consider using a decorator instead of calling staticmethodno-staticmethod-decoratorzHUsed when a static method is defined without using the decorator syntax.)z/Class __slots__ should be a non-string iterablesingle-string-used-for-slotszHUsed when a class __slots__ is a simple string, rather than an iterable.)zJClass %r inherits from object, can be safely removed from bases in python3useless-object-inheritancezoUsed when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases.)ZW0233ZW0235ZE0236ZE0237ZE0238ZE0239ZE0240ZE0241ZR0202ZR0203ZC0205ZR0205c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ScopeAccessMapz'Store the accessed variables per scope.c                 C   s   t dd | _d S )Nc                   S   s
   t tS r)   )collectionsdefaultdictlistr9   r9   r9   r:   <lambda>s  s   
 z)ScopeAccessMap.__init__.<locals>.<lambda>)r   r   _scopesr<   r9   r9   r:   __init__r  s   zScopeAccessMap.__init__c                 C   s.   t |}|du r
dS | j| |j | dS )zSet the given node as accessed.N)r   r   attrnamer0   )r=   rW   framer9   r9   r:   set_accessedu  s   zScopeAccessMap.set_accessedc                 C   s   | j |i S )z/Get the accessed variables for the given scope.)r   get)r=   scoper9   r9   r:   accessed~     zScopeAccessMap.accessedN)__name__
__module____qualname____doc__r   r   r   r9   r9   r9   r:   r   o  s
    	r   c                	   @   sf  e Zd ZdZefZdZeZdZ	dddddd	fd
ddddd	fdddddd	fdddddd	ffZ
dQddZejdd Zejdd Zdd Zdd Zdd  Zd!d" Zd#d$ ZeZd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zed3d4d5d6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dRdCdDZ$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dS )SClassCheckerzchecks for :
    * methods without self as first argument
    * overridden methods signature
    * access only to existent members via self
    * attributes not defined in the __init__ method
    * unreachable code
    classeszdefining-attr-methods)r   __new__ZsetUpcsvz<method names>zGList of method names used to declare (i.e. assign) instance attributes.)defaultrT   metavarhelpzvalid-classmethod-first-argr{   z<argument names>z=List of valid names for the first argument in a class method.z%valid-metaclass-classmethod-first-argzGList of valid names for the first argument in a metaclass class method.zexclude-protected)_asdict_fields_replace_source_makez<protected access exclusions>zQList of member names, which should be excluded from the protected access warning.Nc                 C   s$   t | | t | _g | _d | _d S r)   )r   r   r   	_accessed_first_attrs_meth_could_be_func)r=   linterr9   r9   r:   r     s   
zClassChecker.__init__c                 C   s   t | dd dS )Nzdummy-variables-rgxr   r   r<   r9   r9   r:   
_dummy_rgx  r   zClassChecker._dummy_rgxc                 C   s   t | dddS )Nzignore-mixin-membersTr   r   r<   r9   r9   r:   _ignore_mixin  r   zClassChecker._ignore_mixinc                 C   sr   |  | |jdkr(t|r(z|d W n tjy'   | jd||d Y nw | | | | | 	| dS )z&init visit variable _accessed
        classr   r   r2   rW   N)
_check_bases_classesrT   r   
local_attrr.   r   add_message_check_slots_check_proper_bases_check_consistent_mror=   rW   r9   r9   r:   visit_classdef  s   


zClassChecker.visit_classdefc                 C   sl   z|   W dS  ty   | jd|j|d Y dS  ty,   | jd|j|d Y dS  ty5   Y dS w )z<Detect that a class has a consistent mro or duplicate bases.r   r   r   N)mror   r   r1   r   NotImplementedErrorr   r9   r9   r:   r     s   z"ClassChecker._check_consistent_mroc                 C   s   |j D ]@}t|}|tjdfv rqt|tjr |dtf r qt|tjr*t	|r4| j
d| |d |jtjkrC| j
d|j|d qdS )z`
        Detect that a class inherits something which is not
        a class or a type.
        Nz%s.typer   r   r   )basesr   r.   r   r-   r   is_subtype_ofr   rf   r}   r   	as_stringr1   ra   r   )r=   rW   baseancestorr9   r9   r:   r     s$   
z ClassChecker._check_proper_basesc              
      sF  | j r|jdd  dkrdS | j|}|jdkr!| || | jds)dS | j	j
|  |j D ]j\}} fdd|D }|sFq6tfdd	|D rRq6||D ]}d
}|j| D ]}| jv rkd}q`|rp n0qWz|| W q6 tjy   |D ]}| jvrt| |rq| jd||d qY q6w q6dS )zclose a class node:
        check that instance attributes are defined in __init__ and check
        access to existent members
        NZmixin	metaclassr   c                    s2   g | ]}t | tjtjfs|  u r|qS r9   )r-   	statementr.   Delete	AugAssignroot)r@   n)current_moduler9   r:   rA     s    
z/ClassChecker.leave_classdef.<locals>.<listcomp>c                 3   s    | ]
}|  j v V  qd S r)   )r   r1   )r@   rW   )defining_methodsr9   r:   rK   (  s    z.ClassChecker.leave_classdef.<locals>.<genexpr>FTr   )r   r1   lowerr   r   rT   _check_accessed_membersr   is_message_enabledconfigZdefining_attr_methodsr   Zinstance_attrsitemsrd   instance_attr_ancestorsr   r   r.   r   r   r   )r=   Zcnoder   r   nodesparentZattr_definedrW   r9   )r   r   r:   leave_classdef  sV   


zClassChecker.leave_classdefc           	   	   C   s  |  sdS | | |j }d| _| ||jdk |jdkr(| | dS |	|jD ]"}z||j }W n	 t
y@   Y q.w t|tjsHq.| ||d|  |jr|jjD ]f}t|tjrh|jdv rh dS t|tjrv|jdkrv dS t|}|s dS t|tjrz	t||}W n tjy   Y  dS w zt|tjtjfr|dr|d	rW  dS W qX tjy   Y qXw zB||jd
 }| }t|tjr|jdkr|j }t|tjr|| r| j|j f}| j!d||d W dS W dS W dS  tj"y   Y dS w )z"check method arguments, overridingNTr   r   rk   )gettersetterdeleterpropertyr~   r   r   rR   r   r   )#	is_method_check_useless_super_delegationr  r   r   _check_first_arg_for_typerT   r1   _check_initlocal_attr_ancestorsKeyErrorr-   r.   r   _check_signaturer	   r  	Attributer   r/   r   r"   r   r   r   rf   rY   ZAttributeInferenceErrorinstance_attrr   qnamer   
fromlinenor   r   )	r=   rW   r   rk   	meth_node	decoratorr   Zoverridden_framer2   r9   r9   r:   visit_functiondefG  s   






zClassChecker.visit_functiondefc              	   C   s  |  r|jr	dS |j}t|dkrdS |d }t|tjtjfs#dS |j}t|tj	r3t|j
tjs5dS z
t|j
j }W n tjyJ   Y dS w t|tjsSdS |j
j|jkr\dS |j }|j|kstt|jtjrt|jj|jkrvdS |j }d}||jD ]#}	z|	|j }W n	 ty   Y qw t|tjrt|j|jr dS  t|j}
t |}|durdd }||jj!}||jj!}|r|r||krdS t"|
|r| j#d||jfd dS dS )aQ  Check if the given function node is an useless method override

        We consider it *useless* if it uses the super() builtin, but having
        nothing additional whatsoever than not implementing the method at all.
        If the method uses super() to delegate an operation to the rest of the MRO,
        and if the method called is the same as the current one, the arguments
        passed to super() are the same as the parameters that were passed to
        this method, then the method could be removed altogether, by letting
        other implementation to take precedence.
        NrS   r   c                 S   s   dd t d | D S )Nc                 S   s   g | ]}|  qS r9   )r   )r@   
annotationr9   r9   r:   rA     r_   zZClassChecker._check_useless_super_delegation.<locals>.form_annotations.<locals>.<listcomp>)filter)annotationsr9   r9   r:   form_annotations  s   zFClassChecker._check_useless_super_delegation.<locals>.form_annotationsr   rW   r2   )$r	  r	   bodylenr-   r.   ExprReturnr,   r   r   r  r"   exprr   r   r
   Superr   r1   r  r   Zmro_pointerrT   r   r   r  r  r   rn   r2   rH   r;   r  rP   r   )r=   functionr  r   r4   Z
super_callZcurrent_scoper   r  rk   rr   r2   r  Zcalled_annotationsZoverridden_annotationsr9   r9   r:   r
    s   







z,ClassChecker._check_useless_super_delegationc              
   C   s   d|j vrd S |dD ]]}|tju rqt|s$t|s$| jd|d qt|tjr2| jd|d qt	|ds8qt|tj
rGdd |jD }n| }|tju rS d S |D ]}z| | W qU tjyh   Y qUw qd S )N	__slots__r   rW   r   iteredc                 S   s   g | ]}|d  qS r   r9   )r@   itemr9   r9   r:   rA     s    z-ClassChecker._check_slots.<locals>.<listcomp>)localsigetattrr.   r   r   r   r   r-   re   hasattrDictr   r%  _check_slots_eltr   )r=   rW   r   valueseltr9   r9   r:   r     s4   



zClassChecker._check_slotsc                 C   sf   |  D ],}|tju rqt|tjrt|jts#| jd| |d q|js0| jd| |d qd S )Nr   r   )	r   r.   r   r-   re   r,   strr   r   )r=   r.  r   r9   r9   r:   r,  $  s    


zClassChecker._check_slots_eltc                 C   s   |  rD|jjdur| j  | jdsdS |j }| jrF|j	dkrH|j
tvrJ| sLt||j
sNt|sPt|sR| jd|d dS dS dS dS dS dS dS dS dS )zon method node, check if this method couldn't be a function

        ignore class, static and abstract methods, initializer,
        methods overridden from a parent class.
        Nr   rR   r$  )r	  r2   r   popr   r   r  r   r   rT   r1   r   is_abstractr   r   r   r   )r=   rW   Z
class_noder9   r9   r:   leave_functiondef4  s.   


zClassChecker.leave_functiondefc                 C   s8   |  |r| j| dS | jdsdS | | dS )zcheck if the getattr is an access to a class member
        if so, register it. Also check for access to protected
        class member from outside its class (but ignore __special__
        methods)
        Nr   )_uses_mandatory_method_paramr   r   r   r   !_check_protected_attribute_accessr   r9   r9   r:   visit_attributeM  s   
zClassChecker.visit_attributec                 C   s4   t | tjr| |r| j| | | d S r)   )r-   Zassign_typer.   r   r3  r   r   _check_in_slotsr   r9   r9   r:   visit_assignattr\  s   
zClassChecker.visit_assignattrc                    s   t  j}|rut|tjrw|j}d|jvs|jsdS | }|du r$dS t	dd |
 D r1dS t	 fdd|D syt	dd |D s{t j|rMdS  j|jv r[t| jr[dS  jdkrit| jjridS | jd jf d	 dS dS dS dS dS )
zU Check that the given AssignAttr node
        is defined in the class slots.
        r#  Nc                 s   s$    | ]}d |j vo|jdkV  qdS )r#  ra   N)r(  r1   )r@   r   r9   r9   r:   rK   r  s
    
z/ClassChecker._check_in_slots.<locals>.<genexpr>c                 3   s    | ]	}|j  jkV  qd S r)   )r,   r   r@   Zslotr$  r9   r:   rK   x  s    c                 s   s    | ]}|j d kV  qdS )__dict__Nr   r8  r9   r9   r:   rK   {  rL   	__class__r   r   )r   r   r-   r.   r   r   r(  Znewstyler   rd   	ancestorsr   r   r   r   r  r,   r   )r=   rW   r   r   r   r9   r$  r:   r6  c  s<   


zClassChecker._check_in_slotsr   r   r   c                 C   s@   |  | |jd }t|tjsd S | |rd S | | d S Nr   )_check_classmethod_declarationtargetsr-   r.   Z
AssignAttrr3  r4  )r=   Zassign_noderW   r9   r9   r:   visit_assign  s   


zClassChecker.visit_assignc                    s   t |jtjs	dS |jj}t |tjr|jdvrdS |jdkr!dnd}| }t |tjs/dS |jj	d }t |tjs=dS |j t
 fdd| D rY| j||jd d	 dS dS )
a[  Checks for uses of classmethod() or staticmethod()

        When a @classmethod or @staticmethod decorator should be used instead.
        A message will be emitted only if the assignment is at a class scope
        and only if the classmethod's argument belongs to the class where it
        is defined.
        `node` is an assign node.
        N)rQ   staticmethodrQ   r   r   r   c                 3   s    | ]} |j kV  qd S r)   r>   )r@   membermethod_namer9   r:   rK     rL   z>ClassChecker._check_classmethod_declaration.<locals>.<genexpr>r$  )r-   r,   r.   r   r   r/   r1   r   rf   r2   rd   Z	mymethodsr   r>  )r=   rW   r   msgZparent_classZclassmeth_argr9   rB  r:   r=    s&   	z+ClassChecker._check_classmethod_declarationc                 C   s  |j }t|r|| jjvrt|}|j }|du r$| jd||d dS t|jt	j
r<t|jjt	jr<|jjjdkr<dS | |jrDdS ||jks||jv s|j }t|t	jrvt|jdkrvt|jd t	jrv|jd j}t||rvdS | jd||d dS dS dS dS dS )a  Given an attribute access node (set or get), check if attribute
        access is legitimate. Call _check_first_attr with node before calling
        this method. Valid cases are:
        * self._attr in a method or cls._attr in a classmethod. Checked by
        _check_first_attr.
        * Klass._attr inside "Klass" class.
        * Klass2._attr inside "Klass" class when Klass2 is a base class of
            Klass.
        Nr   r  r   rS   r   )r   r   r   Zexclude_protectedr   r   r   r   r-   r.   r   r   r/   r1   _is_type_self_call	basenamesr  r   Assignr  r>  Z
AssignNamer   )r=   rW   r   r   Zcalleestmtr1   r9   r9   r:   r4    sB   





z.ClassChecker._check_protected_attribute_accessc                 C   sD   t |tjo!t |jtjo!|jjdko!t|jdko!| |jd S )NrT   rS   r   )	r-   r.   r   r   r/   r1   r  r2   _is_mandatory_method_param)r=   r   r9   r9   r:   rE    s   
zClassChecker._is_type_self_callc                 C   s2   | j r|j| j d ks| j d sd| _dS dS dS )zXcheck if the name handle an access to a class member
        if so, register it
        FN)r   r1   r   r   r9   r9   r:   
visit_name  s   
zClassChecker.visit_namec           
   	      s*  d}|  D ]\} z|| W q tjy   Y nw z	t|| W q ty.   Y nw z||}W n
 tjy@   Y qw  fdd|D }|sMq|d  fddt	|D }t
|dkr|d }| }|j} D ] }	|	 |u r|	j|k rt|	 ||s| jd|	||fd qqqd	S )
z'check that accessed members are defined)AttributeError	ExceptionBaseExceptionc                    s   g | ]}| vr|qS r9   r9   )r@   rH  )r  r9   r:   rA   +  s    z8ClassChecker._check_accessed_members.<locals>.<listcomp>r   c                    s(   g | ]\}}|d ks|   ur|qS r&  r   )r@   irH  rO  r9   r:   rA   3  s    
rS   r   r  N)r   r   r.   r   r"   r  r   r  r   	enumerater  r   r  Zare_exclusiver   r   )
r=   rW   r   Zexcsr   ZdefstmtsZdefstmtr   lno_noder9   )r  r   r:   r     s\   



z$ClassChecker._check_accessed_membersr   c                 C   s4  |j j du rdS |j j o| d }| j| | jd }|jdkrC|dks2|| jjv s2|| jjv r<| jd||d dS d| jd< dS |j j sP| jd|d	 dS |rs|jd
kre| 	|| jj|d|j
 dS | 	|| jj|d|j
 dS |jd
ks}|j
dkr| 	|| jj|d|j
 dS |dkr| jd|d	 dS dS )al  check the name of first argument, expect:

        * 'self' for a regular method
        * 'cls' for a class method or a metaclass regular method (actually
          valid-classmethod-first-arg value)
        * 'mcs' for a metaclass class method (actually
          valid-metaclass-classmethod-first-arg)
        * not one of the above for a static method
        Nr   rJ  r@  r=   r   r   r   r$  rQ   r   r   __class_getitem__r   r   )r2   argnamesr   r0   rT   r   Zvalid_classmethod_first_argZ%valid_metaclass_classmethod_first_argr   _check_first_arg_configr1   )r=   rW   r   Z	first_argfirstr9   r9   r:   r  N  sX   




	
z&ClassChecker._check_first_arg_for_typec                 C   sj   ||vr3t |dkrt|d }nddd |d d D }d||d f }| j|||f|d d S d S )	NrS   r   z, c                 s   s    | ]}t |V  qd S r)   )repr)r@   vr9   r9   r:   rK     rw   z7ClassChecker._check_first_arg_config.<locals>.<genexpr>rJ  z%s or %rr   )r  rX  joinr   )r=   rW  r   rW   messagerC  Zvalidr9   r9   r:   rV    s   z$ClassChecker._check_first_arg_configc                 C   sv   dd }t |r
dS tt|| dd d}|D ]\}}|j }||u r'q||jv r-q| jd|||jfd qdS )	z^check that the given class node implements abstract methods from
        base classes
        c                 S   s   | j ddS )NF)Zpass_is_abstract)r1  )rR   r9   r9   r:   r1    s   z6ClassChecker._check_bases_classes.<locals>.is_abstractNc                 S   s   | d S r<  r9   )r'  r9   r9   r:   r     s    z3ClassChecker._check_bases_classes.<locals>.<lambda>)keyr   r  )	r   sortedr   r   r  r   r(  r   r1   )r=   rW   r1  r   r1   rR   ownerr9   r9   r:   r     s   

z!ClassChecker._check_bases_classesc           
   
   C   s  | j ds| j dsdS |j }t|}t|}|tjD ]}|j	}t
|tjr1|jdkr2q!t
|jtjrKt
|jj	tjrK|jj	jdkrK dS zS|j D ]K}|tju rYqQt
|tjrvt
|jtjrvt|jrv|jjdkrv W  dS t
|tjr W  dS z||= W qQ ty   ||vr| jd||jd Y qQw W q! tjy   Y q!w | D ]\}}t|}	|jdks|	r|	jdkrq| jd|j|d qdS )	zWcheck that the __init__ method call super or ancestors'__init__
        method
        r   r   Nr   r   r  ra   r   )r   r   r  r   _ancestors_to_calldictr   r.   r   r   r-   r  r   r   r/   r1   r   r   r   r   rf   r   r
   r!  r  r   r   r   r   )
r=   rW   
klass_nodeto_callZnot_called_yetrH  r   r   rR   r|   r9   r9   r:   r    sl   



	



zClassChecker._check_initc                 C   s  t |tjrt |tjs| jd||f|d dS | }t||}t||}|jjdu s2|jjdu r4dS t|jr;dS |j	rS|j	j
D ]}t |tjrR|jdkrR dS qBt||| jdrh| jd||jf|d dS t|jjt|jjk r| jd||jf|d dS dS )z@check that the signature of the two given methods match
        r   r   Nr  )rq   r   r   )r-   r.   r   r   Zinstantiate_classr   r2   r   r1   r	   r  r  r   ry   r   r  defaults)r=   Zmethod1Z	refmethodZ
class_typer|   instancer  r9   r9   r:   r    sD   








zClassChecker._check_signaturec                 C   s   |  |jS )zCheck that attribute lookup name use first attribute variable name

        Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.
        )rI  r   r   r9   r9   r:   r3    s   z)ClassChecker._uses_mandatory_method_paramc                 C   s"   | j ot|tjo|j| j d kS )zCheck if astroid.Name corresponds to first attribute variable name

        Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.
        rJ  )r   r-   r.   r/   r1   r   r9   r9   r:   rI    s
   
z'ClassChecker._is_mandatory_method_paramr)   r&  )+r   r   r   r   r   __implements__r1   MSGSmsgspriorityoptionsr   r	   Zcachedpropertyr   r   r   r   r   r  r  visit_asyncfunctiondefr
  r   r,  r2  r5  r7  r6  r   r?  r=  r4  rE  rK  r   r  rV  r   r  r  r3  rI  r9   r9   r9   r:   r     s    
4

?Qj *

'>		
=@	9,r   c                   @   s   e Zd ZdZefZdZddde dddgifd	d
dddgifdddi fdZdZ	e
d
dddd ZeZdd Zedd Zdd Zdd ZdS )SpecialMethodsCheckerzOChecker which verifies that special methods
    are implemented correctly.
    r   z__iter__ returns non-iteratornon-iterator-returnedzaUsed when an __iter__ method returns something which is not an iterable (i.e. has no `%s` method)Z	old_names)ZW0234rl  )ZE0234rl  z6The special method %r expects %s param(s), %d %s given#unexpected-special-method-signaturezEmitted when a special method was defined with an invalid number of parameters. If it has too few or too many, it might not work at all.)ZE0235zbad-context-managerz,__len__ does not return non-negative integerinvalid-length-returnedzPUsed when a __len__ method returns something which is not a non-negative integer)ZE0301ZE0302ZE0303r   c                 C   sP   |  sd S |jdkr| | |jdkr| | |jtv r&| | d S d S )N__iter____len__)r	  r1   _check_iter
_check_lenr   "_check_unexpected_method_signaturer   r9   r9   r:   r  P  s   




z'SpecialMethodsChecker.visit_functiondefc           
      C   s  t |j }|d u rd S |jjs|jjsd S t|td gr"|jj}n|jjdd  }t|t|jj }t|jj}|| }t|t	rL||v}d| }n!|| }|dkrWd}n|dk r^d}n|dkrm|| dkpk|jj }|r|dkrudnd}	| j
d	|j|||	f|d
 d S d S )Nz.staticmethodrS   zbetween %d or %dr   FTwaswererm  r   )r   r1   r2   rE   r   r   r  rc  r-   ri   r   )
r=   rW   Zexpected_paramsrl   	mandatoryoptionalZcurrent_paramsemitrestverbr9   r9   r:   rs  a  s:   




z8SpecialMethodsChecker._check_unexpected_method_signaturec                 C   s   | t ju rdS t| trdS t| t jr(z| t W dS  t jy'   Y dS w t| t jrN| 	 }|rNt|t jrNz|t W dS  t jyM   Y dS w dS )NTF)
r.   r   r-   r   r   r   NEXT_METHODr   rf   r   )rW   r   r9   r9   r:   _is_iterator  s.   


	
z"SpecialMethodsChecker._is_iteratorc                 C   s6   t ||}|d ur| |s| jd|d d S d S d S )Nrl  r$  )r   r|  r   )r=   rW   r   r9   r9   r:   rq    s   

z!SpecialMethodsChecker._check_iterc                 C   s   t ||}|r|tju rd S t|tjr!|jdkr!t|tjs!d S t|tjs0| jd|d d S |j}t|t	r<|dk rE| jd|d d S d S )Nintrn  r$  r   )
r   r.   r   r-   r   r1   re   r   r,   r}  )r=   rW   r   r,   r9   r9   r:   rr    s"   


z SpecialMethodsChecker._check_lenN)r   r   r   r   r   re  r1   r{  rg  rh  r   r  rj  rs  r@  r|  rq  rr  r9   r9   r9   r:   rk  *  sN    	

/
rk  r   c              	   C   sD   i }| j ddD ]}zt||||< W q tjy   Y qw |S )zreturn a dictionary where keys are the list of base classes providing
    the queried method, and so that should/may be called from the method node
    F)Zrecurs)r;  r"   r)  r.   r   )ra  rR   rb  Z	base_noder9   r9   r:   r_    s   r_  c                 C   s    |  t|  |  t|  dS )z.required method to auto register this checker N)Zregister_checkerr   rk  )r   r9   r9   r:   register  s   r~  r)   )r   )Fr   
__future__r   r   	itertoolsr   r   sysr.   Zastroid.basesr   r   Zastroid.exceptionsr   r   r	   r
   Zastroid.scoped_nodesr   Zpylint.interfacesr   Zpylint.checkersr   Zpylint.checkers.utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zpylint.utilsr   version_infor{  rz   
namedtupler'   r(   r;   rH   rP   rV   rX   r[   rn   rt   ry   r}   r   r   r   r   r   r   rf  r   r   rk  r_  r~  r9   r9   r9   r:   <module>   s   H
(9. 
 &-5=ELRX^djo  4       . 
