o
    gg                 	   @   s  d Z ddlZddlmZmZ ddlmZmZ ddlZddlm	Z	 ddl
mZ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mZmZm Z m!Z! ddl"m#Z# dd	l$m%Z% d
Z&h dZ'ddhZ(e)ddZ*e)ddZ+dd Z,dd Z-dd Z.dd Z/dd Z0dd Z1dd Z2d ee	j3 d!ee	j3 d"ed#ee4 fd$d%Z5d e	j6d!e	j6d"ed#ee4 fd&d'Z7d(d) Z8d*d+ Z9d,d- Z:d.d/ Z;d0d1 Z<dd2d3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i dXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{iZ?d|d} Z@G d~d dZAG dd deZBG dd deZCdddZDdd ZEdS )z classes checker for Python code
    N)chainzip_longest)ListPattern)nodes)BaseCheckerutils)	PYMETHODSSPECIAL_METHODS_PARAMScheck_messagesclass_is_abstractdecorated_withdecorated_with_propertyhas_known_basesis_attr_privateis_attr_protectedis_builtin_objectis_comprehensionis_iterableis_overload_stubis_property_setteris_property_setter_or_deleteris_protocol_classnode_frame_classoverrides_a_method
safe_inferunimplemented_abstract_methods)IAstroidCheckerget_global_option__next__>   boolrangeslice
memoryviewbuiltins.propertyzbuiltins.classmethod_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
isinstancer   NameappendnameargsStarredr&   )callkwsr0   starred_kwsstarred_argskeywordr*   r+    r7   U/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/checkers/classes.py_signature_from_callc   s$   

r9   c                 C   sB   | j }| j}dd t| j| jD }dd | jD }t||||S )Nc                 S   s   g | ]
}|j d kr|j qS selfr/   .0r*   r7   r7   r8   
<listcomp>   s
    
z-_signature_from_arguments.<locals>.<listcomp>c                 S      g | ]}|j qS r7   r<   r=   r7   r7   r8   r?          )kwargvarargr   posonlyargsr0   
kwonlyargsr'   )	argumentsrB   rC   r0   rE   r7   r7   r8   _signature_from_arguments   s   rG   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(   )r3   )r>   kwr2   r7   r8   	<genexpr>       z1_definition_equivalent_to_call.<locals>.<genexpr>TF)kwargsr4   varargsr5   allrE   r0   r3   )

definitionr2   same_kw_variadicssame_args_variadicssame_kwonlyargs	same_argsno_additional_kwarg_argumentsr6   is_arg	is_kwonlyr7   rI   r8   _definition_equivalent_to_call   s2   


rW   c                 C   s"   | j j }| jdv r|dd  }|S )N)classmethodmethod   )r0   type)rY   
positionalr7   r7   r8   _positional_parameters   s   
r]   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,   )nodepotential_typespotential_typer7   r7   r8   _get_node_type   s
   
ra   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)node_anode_b	attr_namer7   r7   r8   _check_arg_equality   s   rf   c                    s0  | j du s
|j du rdS t| j | j}dd |D }t  |D ]v}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	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   r@   r7   r<   r>   paramr7   r7   r8   r?      rA   z;_has_different_parameters_default_value.<locals>.<listcomp>c                    s   g | ]}| kqS r7   r7   r=   default_missingr7   r8   r?      s    Tr+   r/   eltsitemsc                 s   s    | ]}|V  qd S r(   r7   )r>   astroid_typer7   r7   r8   rJ     s    
z:_has_different_parameters_default_value.<locals>.<genexpr>)r0   r   rE   objectdefault_valueastroid
exceptions	NoDefaultanyrN   r   ConstClassDefTupler   Dicttuplera   r,   rf   )original
overriddenall_argsoriginal_param_names
param_nameoriginal_defaultoverridden_defaultdefault_listastroid_type_compared_attrhandled_typesoriginal_typer7   ri   r8   '_has_different_parameters_default_value   sT   	


r   ry   rz   dummy_parameter_regexreturnc           	         s   g }t | |}|D ]8\}}||f}t|sdg  S dd |D }t fdd|D r-q	|j|jkrA|d|j d|j d q	|S )	NNumber of parameters c                 S   r@   r7   r<   rg   r7   r7   r8   r?   "  rA   z-_has_different_parameters.<locals>.<listcomp>c                 3   s    | ]}  |V  qd S r(   )match)r>   r/   r   r7   r8   rJ   #  rK   z,_has_different_parameters.<locals>.<genexpr>zParameter 'z' has been renamed to 'z' in)r   rN   rs   r/   r.   )	ry   rz   r   resultzippedoriginal_paramoverridden_paramparamsnamesr7   r   r8   _has_different_parameters  s"   


r   c                    sR  g }t | }t |}| jj}|jjr"dd |D   fdd|D }|jjr:dd |jjD   fdd| jjD }t|||}t||jj|}|rw|rwd|d v rnd|d v rn|d ||d	d
 7 }||d	d
 7 }n||7 }||7 }n|r}||7 }|r||7 }| jtv r|	  | jjo|jj }	| jjo|jj }
|	s|
r|dg7 }|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.

    c                 S   r@   r7   r<   r>   vr7   r7   r8   r?   J  rA   z)_different_parameters.<locals>.<listcomp>c                       g | ]	}|j  v r|qS r7   r<   r   overidden_namesr7   r8   r?   K      c                 S   r@   r7   r<   r   r7   r7   r8   r?   P  rA   c                    r   r7   r<   r   r   r7   r8   r?   Q  r   zNumber r   r   rZ   NzVariadics removed in)
r]   r0   rE   rC   rB   r   r.   r/   r	   clear)ry   rz   r   output_messagesoriginal_parametersoverridden_parametersoriginal_kwonlyargsdifferent_positionaldifferent_kwonly
kwarg_lostvararg_lostr7   r   r8   _different_parameters.  sL   






r   c                 C   s   | j tv ot| S r(   )r/   INVALID_BASE_CLASSESr   clsr7   r7   r8   _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)rb   inferr,   rp   InstanceNotFoundErrorInferenceError)r   attr
attributes	attributeinferredr7   r7   r8   _has_data_descriptor  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 )zCheck if the func was called in any of the given methods,
    belonging to the *klass*. Returns True if so, False otherwise.
    FT)r,   r   FunctionDefrb   rp   r   nodes_of_classCallnextfuncr   r   StopIterationBoundMethod_proxiedUnboundMethodr/   )	r   klassmethodsrY   r   infer_methodr2   boundfunc_objr7   r7   r8   _called_in_methods  s4   
r   c              	   C   s   z| | }W n tjy   Y dS w d}|D ]<}|tju rqzt| }W n
 tjy1   Y qw t|tj	r?t
|r? dS | |krFqt|}|| krQq dS dS )a/  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.
    Fr%   T)rb   rp   r   Uninferabler   r   r   r,   r   r   r   pytyper   declared_metaclass)r/   r   r   property_namer   r   r   r7   r7   r8   _is_attribute_property  s2   

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-   r/   r0   )fundef_noder2   r   r7   r7   r8   _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 inferred value.
    )contextN)infer_call_resultr   rp   r   r   )r^   callerr   inferitr+   r7   r7   r8   _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>   
first_slotsecond_slotr7   r7   r8   rJ     s
    
z)_has_same_layout_slots.<locals>.<genexpr>TF)r   r   r,   r   ru   slotsrN   r   )r   assigned_valuer   other_slotsr7   r7   r8   _has_same_layout_slots  s   r   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.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.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.W0201)z%Attribute %r defined outside __init__attribute-defined-outside-initzGUsed when an instance attribute is defined outside the __init__ method.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.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.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!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.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.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.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.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.W0221)%s %s %r methodarguments-differztUsed when a method has a different number of arguments than in the implemented interface or in an overridden method.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.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.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.W0232)zClass has no __init__ methodno-initzEUsed when a class has no __init__ method, neither its parent classes.W0233)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.W0235)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.W0236)z7Method %r was expected to be %r, found it instead as %rinvalid-overridden-methodzUsed when we detect that a method was overridden in a way that does not match its base class which could result in potential bugs at runtime.W0237)r   arguments-renamedzoUsed when a method parameter has a different name than in the implemented interface or in an overridden method.W0238)zUnused private member `%s.%s`unused-private-memberzAEmitted when a private member of a class is defined but not used.E0236)zCInvalid object %r in __slots__, must contain only non empty stringsinvalid-slots-objectz=Used when an invalid (non-string) object occurs in __slots__.E0237)z4Assigning to attribute %r not defined in class slotsassigning-non-slotzCUsed when assigning to an attribute not defined in the class slots.E0238)zInvalid __slots__ objectinvalid-slotszhUsed when an invalid __slots__ is found in class. Only a string, an iterable or a sequence is permitted.E0239)z$Inheriting %r, which is not a class.inherit-non-classz?Used when a class inherits from something which is not a class.E0240)z1Inconsistent method resolution order for class %rinconsistent-mroz>Used when a class has an inconsistent method resolution order.E0241)zDuplicate bases for class %rduplicate-basesz&Used when a class has duplicate bases.E0242)z/Value %r in slots conflicts with class variableclass-variable-slots-conflictzSUsed when a value in __slots__ conflicts with a class variable, property or method.E0243)zInvalid __class__ objectinvalid-class-objectz[Used when an invalid object is assigned to a __class__ property. Only a class is permitted.R0202)z9Consider using a decorator instead of calling classmethodno-classmethod-decoratorzGUsed when a class method is defined without using the decorator syntax.R0203)z:Consider using a decorator instead of calling staticmethodno-staticmethod-decoratorzHUsed when a static method is defined without using the decorator syntax.C0205)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.R0205)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.R0206)z-Cannot have defined parameters for propertiesproperty-with-parameterszUsed when we detect that a property also has parameters, which are useless, given that properties cannot be called with additional arguments.c                   C   s
   t tS r(   )collectionsdefaultdictlistr7   r7   r7   r8   _scope_default  s   
r  c                   @   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 t| _d S r(   )r  r  r  _scopesr:   r7   r7   r8   __init__  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  attrnamer.   )r;   r^   framer7   r7   r8   set_accessed  s   zScopeAccessMap.set_accessedc                 C   s   | j |i S )z/Get the accessed variables for the given scope.)r  get)r;   scoper7   r7   r8   accessed     zScopeAccessMap.accessedN)__name__
__module____qualname____doc__r   r#  r&  r7   r7   r7   r8   r    s
    	r  c                   @   s  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dddddd	ffZ
d~ddZejjdd Zejjdd Zed d!d"d#d$d%d&d'd(d)
d*ejd+dfd,d-Zd.d/ Zd0d1 Zed2d3d*ejd+dfd4d5Zd*ejd+dfd6d7Zd*ejd+dfd8d9Zd*ejd+dfd:d;Zd<ejd+dfd=d>Zd*ejd+dfd?d@ZeZdAdB ZdCdD Z dEdF Z!dGdH Z"dIdJ Z#d*ejd+dfdKdLZ$e$Z%d*ej&d+dfdMdNZ'edOdPd*ej(d+dfdQdRZ)d*ej(d+dfdSdTZ*dUdV Z+edWdXdYdZej,d+dfd[d\Z-d]d^ Z.d*ej&fd_d`Z/e0d*ej1d+e2fdadbZ3dcdd Z4e0dedf Z5e0dgdh Z6e0didj Z7d*ej8d+dfdkdlZ9dmdn Z:ddpdqZ;drds Z<dtdu Z=dvdw Z>dxdy Z?dzd{ Z@d|d} ZAd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__setUp__post_init__csvz<method names>zGList of method names used to declare (i.e. assign) instance attributes.)defaultr[   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.z)check-protected-access-in-special-methodsFynz<y or n>z<Warn about protected attribute access inside special methodsNc                 C   s$   t | | t | _g | _d | _d S r(   )r   r   r  	_accessed_first_attrs_meth_could_be_funcr;   linterr7   r7   r8   r   9  s   
zClassChecker.__init__c                 C   s   t | dd dS )Nzdummy-variables-rgxr3  r   r:   r7   r7   r8   
_dummy_rgx?  r'  zClassChecker._dummy_rgxc                 C   s   t | dddS )Nzignore-mixin-membersTrA  r   r:   r7   r7   r8   _ignore_mixinC  r'  zClassChecker._ignore_mixinr   r   r  r  r  r  r  r  r	  r  r^   r   c                 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   r0   r^   N)
_check_bases_classesr[   r   
local_attrrp   r   add_message_check_slots_check_proper_bases_check_consistent_mror;   r^   r7   r7   r8   visit_classdefG  s   


zClassChecker.visit_classdefc                 C   sp   z|   W dS  tjy   | jd|j|d Y dS  tjy.   | jd|j|d Y dS  ty7   Y dS w )z<Detect that a class has a consistent mro or duplicate bases.r	  rE  r  N)mrorp   InconsistentMroErrorrH  r/   DuplicateBasesErrorNotImplementedErrorrL  r7   r7   r8   rK  `  s   z"ClassChecker._check_consistent_mroc                 C   s|   |j D ]8}t|}|sqt|tjr|drqt|tjr"t|r,| j	d|
 |d |jtjkr;| j	d|j|d qdS )z`
        Detect that a class inherits something which is not
        a class or a type.
        zbuiltins.typer  rE  r  N)basesr   r,   rp   r   is_subtype_ofr   ru   r   rH  	as_stringr/   rn   r(  )r;   r^   baseancestorr7   r7   r8   rJ  l  s$   
z ClassChecker._check_proper_basesr   r   c                 C   s,   |  | | | | | | | dS )zclose a class node:
        check that instance attributes are defined in __init__ and check
        access to existent members
        N)_check_unused_private_functions_check_unused_private_variables _check_unused_private_attributes%_check_attribute_defined_outside_initrL  r7   r7   r8   leave_classdef  s   


zClassChecker.leave_classdefc           
      C   sT  | tjD ]}t|jsq|j }t|tjr(|jdd | tjD v r(q| tj	D ]<}|j
|jks<| |kr=q.t|jtjrP|jjdd|jfv rP nWt|jtjrjt|j}t|tjrj|j|jkrj n=q.g }|}||kr||j |j }||kssdt| }| d|j d|j  d}	| jd||j|	dfd	 qd S )
Nc                 s   s    | ]}|j V  qd S r(   r<   r>   nr7   r7   r8   rJ     s    
z?ClassChecker._check_unused_private_functions.<locals>.<genexpr>r;   r   .()r   r^   r0   )r   r   r   r   r/   parentr%  r,   r-   	Attributer!  exprr   r   ru   r.   joinreversedr0   rT  rH  lstrip)
r;   r^   function_defparent_scoper   r   
name_stackcurrouter_level_namesfunction_reprr7   r7   r8   rW    sR   






z,ClassChecker._check_unused_private_functionsc                 C   s   | tjD ]P}t|jtjrqt|jsq| tjtj	fD ](}t|tjr/|j|jkr/ n't|tj	rG|j
|jkrG|jjdd|jfv rG nq|j|jf}| jd||d qd S )Nr;   r   r   ra  )r   r   
AssignNamer,   rb  	Argumentsr   r/   r-   rc  r!  rd  rH  )r;   r^   assign_namechildr0   r7   r7   r8   rX    s$   

z,ClassChecker._check_unused_private_variablesc                 C   s  | tjD ]}t|jrt|jtjsqdg}| }t|tj	r5|j
dkr5|dd | tjD  | tjD ]?}|j|jkrDq;|jj
d|j
fv rY|jj
dd|j
fv rY n0|jj
|v rg|jj
dkrg n"|jj
|jj
  krv|j
krzn q; nq;|j
|jf}| jd||d qd S )Nr;   r/  c                 S   s"   g | ]}t |jtjr|jjqS r7   )r,   r+   r   r-   r/   )r>   return_noder7   r7   r8   r?     s    zAClassChecker._check_unused_private_attributes.<locals>.<listcomp>r   r   ra  )r   r   
AssignAttrr   r!  r,   rd  r-   r%  r   r/   extendReturnrc  rH  )r;   r^   assign_attracceptable_obj_namesr%  r   r0   r7   r7   r8   rY    sB   
"z-ClassChecker._check_unused_private_attributescnodec           	   
      s^  | j r|jdd   dkrd S | j|}|jdkr!| || | jds)d S | j	j
|  |j D ]v\}}|dkr?q6 fdd|D }|sKq6dd	 |D }tfd
d	|D r^q6||D ]}d}|j| D ]}| jv rwd}ql|r| n0qcz|| W q6 tjy   |D ]}| jvrt| |rq| jd||d qY q6w q6d S )Nmixin	metaclassr   __dict__c                    s2   g | ]}t | tjtjfs|  u r|qS r7   )r,   	statementr   Delete	AugAssignrootr\  )current_moduler7   r8   r?     s    zFClassChecker._check_attribute_defined_outside_init.<locals>.<listcomp>c                 s   s    | ]}|  V  qd S r(   )r"  )r>   r^   r7   r7   r8   rJ   *      zEClassChecker._check_attribute_defined_outside_init.<locals>.<genexpr>c                 3   s"    | ]}|j  v pt|V  qd S r(   )r/   r   )r>   r"  )defining_methodsr7   r8   rJ   +  s
    
FTrE  )rC  r/   lowerr<  r&  r[   _check_accessed_membersr@  is_message_enabledconfigdefining_attr_methodsr  instance_attrsrl   rs   instance_attr_ancestorsr"  rG  rp   r   r   rH  )	r;   rx  r&  r   	nodes_lstframesrb  attr_definedr^   r7   )r  r  r8   rZ    s`   


z2ClassChecker._check_attribute_defined_outside_initc              	   C   s  |  sdS | | | | |j }d| _| ||jdk |jdkr-| 	| dS |
|jD ](}z||j }W n	 tyE   Y q3w t|tjsMq3| ||d| | ||  |jr|jjD ]f}t|tjrs|jdv rs dS t|tjr|jdkr 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 qc tjy   Y qcw zo||jd
 }| }t|tjr|jdkr|j }t|tjr||  sW dS |! D ]+}|j|j"v rt#|jr W dS |$|jd D ]}	t|	tjr$  W dS qq|% j|j&f}
| j'd|
|d W dS  tj(yE   Y dS w )z"check method arguments, overridingNTr{  r   rz   )gettersetterdeleterpropertyr   r   r   rY   rZ   r   rE  ))	is_method_check_useless_super_delegation_check_property_with_parametersrb  r"  r>  _check_first_arg_for_typer[   r/   _check_initlocal_attr_ancestorsKeyErrorr,   r   r   _check_signature _check_invalid_overridden_method
decoratorsrc  r!  r-   r   r   r   rp   r   r   ru   rb   AttributeInferenceErrorinstance_attrrS  qname	ancestorsr  r   lookupr  
fromlinenorH  r   )r;   r^   r   rz   parent_function	decoratorr   overridden_framerV  objr0   r7   r7   r8   visit_functiondefM  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jsTdS |j
j|jkr]dS |j }|j|ksut|jtjru|jj|jkrwd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}|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.
        NrZ   r   c                 S   s    t | jpg | j}dd |D S )Nc                 S   s   g | ]
}|d ur|  qS r(   )rT  )r>   annr7   r7   r8   r?     s    zZClassChecker._check_useless_super_delegation.<locals>.form_annotations.<locals>.<listcomp>)r   posonlyargs_annotationsannotations)rF   r  r7   r7   r8   form_annotations  s   zFClassChecker._check_useless_super_delegation.<locals>.form_annotationsr   ra  )$r  r  bodylenr,   r   Exprru  r+   r   r   rc  r   rd  r   rp   r   objectsSuperr!  r/   rb  r%  mro_pointerr[   r   r"  r  r  r   r   r0   rG   r9   rW   rH  )r;   functionr  r}  r2   
super_callcurrent_scoper   	meth_noderz   r   r0   r  called_annotationsoverridden_annotationsr7   r7   r8   r    s|   










z,ClassChecker._check_useless_super_delegationc                 C   sJ   |j j rt|j j dkrt|r!t|s#| jd|d d S d S d S d S d S )NrZ   r  r^   )r0   r  r   r   rH  rL  r7   r7   r8   r    s   z,ClassChecker._check_property_with_parametersc                 C   s   t |pt|}t |pt|}|r"|s"| jd|jd|jf|d n|s2|r2| jd|jddf|d t|tj}t|tj}|rP|sP| jd|jddf|d d S |sb|rd| jd|jddf|d d S d S d S )Nr   r  rE  rY   asyncz	non-async)r   r   rH  r/   r[   r,   r   AsyncFunctionDef)r;   function_nodeparent_function_nodeparent_is_propertycurrent_is_propertyparent_is_asynccurrent_is_asyncr7   r7   r8   r  !  sJ   




z-ClassChecker._check_invalid_overridden_methodc              
   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yi   Y qUw qd S )N	__slots__r  r  r  iteredc                 S   s   g | ]}|d  qS r   r7   )r>   itemr7   r7   r8   r?   Z  s    z-ClassChecker._check_slots.<locals>.<listcomp>)localsigetattrrp   r   r   r   rH  r,   r   rt   hasattrrw   rl   r  _check_slots_eltr   )r;   r^   r   valueseltr7   r7   r8   rI  F  s4   



zClassChecker._check_slotsc                 C   s   |  D ]X}|tju rqt|tjrt|jts#| jd|	 |d q|js0| jd|	 |d |j
|j}|r\t|dkrR|d j}t|tjrR|jd u rR d S | jd|jf|d qd S )Nr  rE  rZ   r   r  )r   rp   r   r,   r   rt   r+   strrH  rT  r  r$  r  rb  	AnnAssign)r;   r  r^   r   class_variablerb  r7   r7   r8   r  e  s2   




zClassChecker._check_slots_eltc                 C   s   |  rL|jjdur| j  | jdsdS |j }| jrN|j	dkrP|j
tvrR| sTt||j
sVt|sXt|sZt|s\t|s^| jd|d dS dS 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   rY   r  )r  r0   r=  popr@  r  rb  r"  r>  r[   r/   r	   is_abstractr   r   r   r   r   rH  )r;   r^   
class_noder7   r7   r8   leave_functiondef  s6   





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_accessrL  r7   r7   r8   visit_attribute  s   
zClassChecker.visit_attributer  r  c                 C   s>   t | tjr| |r| j| | | | | d S r(   )	r,   assign_typer   r  r  r<  r#  _check_in_slots_check_invalid_class_objectrL  r7   r7   r8   visit_assignattr  s   

zClassChecker.visit_assignattrc                 C   sF   |j dksd S t|jj}t|tjs|tju rd S | j	d|d d S )N	__class__r  r  )
r!  r   rb  r+   r,   r   ru   rp   r   rH  r;   r^   r   r7   r7   r8   r    s   
z(ClassChecker._check_invalid_class_objectc                    s<  t  j}t|tjsdS |j}t|sdS d|jvs|js dS t	dd |
 D r?t|dd}|r?||jdur?||j= | }|du rIdS t	dd | D rVdS t	 fdd|D st	dd |D st j|rrdS  j|jv rt| jrdS  jd	krt| jjrdS | jd
 jf d dS dS dS )zTCheck that the given AssignAttr node
        is defined in the class slots.
        Nr  c                 s   s    | ]	}|  d kV  qdS )ztyping.GenericN)r  )r>   rU  r7   r7   r8   rJ         z/ClassChecker._check_in_slots.<locals>.<genexpr>__cachec                 s   s$    | ]}d |j vo|jdkV  qdS )r  rn   N)r  r/   )r>   rV  r7   r7   r8   rJ     s
    
c                 3   s    | ]	}|j  jkV  qd S r(   )r+   r!  r>   slotr  r7   r8   rJ     r  c                 s   s    | ]}|j d kV  qdS )r|  Nr   r  r7   r7   r8   rJ     rK   r  r  rE  )r   rd  r,   rp   r   r   r   r  newstylers   rN  rb   r$  r   r  r   r!  r   r   rb  r+   rH  )r;   r^   r   r   cacher   r7   r  r8   r    sD   
zClassChecker._check_in_slotsr   r  r  assign_nodec                 C   s@   |  | |jd }t|tjsd S | |rd S | | d S Nr   )_check_classmethod_declarationtargetsr,   r   rs  r  r  )r;   r  r^   r7   r7   r8   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)rX   staticmethodrX   r  r  r   c                 3   s    | ]} |j kV  qd S r(   r<   )r>   membermethod_namer7   r8   rJ   #  rK   z>ClassChecker._check_classmethod_declaration.<locals>.<genexpr>r  )r,   r+   r   r   r   r-   r/   r%  ru   r0   rs   	mymethodsrH  r  )r;   r^   r   msgparent_classclassmeth_argr7   r  r8   r    s&   	
z+ClassChecker._check_classmethod_declarationc                 C   sp  |j }t|r|| jjvrt|}|j }t|rdS |du r+| j	d||d dS t
|jtjrCt
|jjtjrC|jjjdkrCdS | |jrKdS ||jks||jv s|j }t
|tjr}t|jdkr}t
|jd tjr}|jd j}t||r}dS | | r| |j|r| ||rdS |d }| jjs|r| |rd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   ra  r   rZ   r   __) r!  r   r  exclude_protectedr   rd  rT  r   "is_node_in_type_annotation_contextrH  r,   r   r   r   r-   r/   _is_type_self_call	basenamesrb  r}  Assignr  r  rn  r   _is_classmethodr"  _is_inferred_instance_is_class_attribute
startswith)check_protected_access_in_special_methods _is_called_inside_special_method)r;   r^   r!  r   calleestmtr/   licit_protected_memberr7   r7   r8   r  &  s`   






 z.ClassChecker._check_protected_attribute_accessc                 C   s0   z|   j}W n
 ty   Y dS w |o|tv S )zZ
        Returns true if the node is located inside a special (aka dunder) method
        F)r"  r/   AttributeErrorr	   )r^   
frame_namer7   r7   r8   r  v  s   z-ClassChecker._is_called_inside_special_methodc                 C   sD   t |tjo!t |jtjo!|jjdko!t|jdko!| |jd S )Nr[   rZ   r   )	r,   r   r   r   r-   r/   r  r0   _is_mandatory_method_param)r;   rd  r7   r7   r8   r    s   
zClassChecker._is_type_self_callc                 C   s    t | tjo| jdkp| jdkS )z1Check if the given *func* node is a class method.rX   __class_getitem__)r,   r   r   r[   r/   )r   r7   r7   r8   r    s   zClassChecker._is_classmethodc                 C   s"   t | }t|tjsdS |j|u S )zJCheck if the inferred value of the given *expr* is an instance of *klass*.F)r   r,   rp   r   r   )rd  r   r   r7   r7   r8   r    s   
z"ClassChecker._is_inferred_instancec                 C   sN   z| |  W dS  tjy   Y nw z||  W dS  tjy&   Y dS w )zCheck if the given attribute *name* is a class or instance member of the given *klass*.

        Returns ``True`` if the name is a property in the given klass,
        ``False`` otherwise.
        TF)rb   rp   r   r  )r/   r   r7   r7   r8   r    s   

z ClassChecker._is_class_attributec                 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=  r/   r>  rL  r7   r7   r8   
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)r  	ExceptionBaseExceptionc                    s   g | ]}| vr|qS r7   r7   )r>   r  )r  r7   r8   r?     s    z8ClassChecker._check_accessed_members.<locals>.<listcomp>r   c                    s(   g | ]\}}|d ks|   ur|qS r  r%  )r>   ir  r  r7   r8   r?     s
    rZ   r   ra  N)rl   rG  rp   r   r   r  r   r  r%  	enumerater  r"  r  are_exclusiver}  rH  )
r;   r^   r&  excsr   defstmtsdefstmtr"  lno_noder7   )r  r%  r8   r    sX   



z$ClassChecker._check_accessed_membersr   c                 C   sZ  |j j du rdS |j jr|j jd j}n|j j r| d }nd}| j| | jd }|jdkrR|dksA|| jjv sA|| jj	v rK| j
d||d dS d| jd< dS |j j sc|j jsc| j
d|d	 dS |r|jd
krx| || 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   r   r  r;   r   rE  r   r  rX   r   r   r  r   r   )r0   rD   r/   argnamesr=  r.   r[   r  valid_classmethod_first_arg%valid_metaclass_classmethod_first_argrH  _check_first_arg_config)r;   r^   r{  	first_argfirstr7   r7   r8   r    sZ   


	
z&ClassChecker._check_first_arg_for_typec                 C   sl   ||vr4t |dkrt|d }nddd |d d D }| d|d }| j|||f|d d S d S )	NrZ   r   z, c                 s   s    | ]}t |V  qd S r(   )reprr   r7   r7   r8   rJ   ?  r  z7ClassChecker._check_first_arg_config.<locals>.<genexpr>r   z or rE  )r  r  re  rH  )r;   r  r  r^   messager  validr7   r7   r8   r  :  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)pass_is_abstract)r  )rY   r7   r7   r8   r  H  s   z6ClassChecker._check_bases_classes.<locals>.is_abstractNc                 S   s   | d S r  r7   )r  r7   r7   r8   <lambda>Q  s    z3ClassChecker._check_bases_classes.<locals>.<lambda>)keyr   ra  )	r   sortedr   rl   rb  r"  r  rH  r/   )r;   r^   r  r   r/   rY   ownerr7   r7   r8   rF  C  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 zT|j D ]L}|tju rYqQt
|tjrvt
|jtjrvt|jrv|jjdkrv W  dS t
|tj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|dgrqt|}	|jdks|	r|	jdkrq| jd|j|d	 qdS )
zcheck that the __init__ method call super or ancestors'__init__
        method (unless it is used for type hinting with `typing.overload`)
        r   r   Nr   r   ra  ztyping.overloadrn   rE  )r@  r  rb  r"  _ancestors_to_calldictr   r   r   r   r,   rc  r!  rd  r-   r/   r   rp   r   r   r   ru   r   r  r  r  rH  r   rl   r   r   )
r;   r^   
klass_nodeto_callnot_called_yetr  rd  r   rY   r   r7   r7   r8   r  ^  sl   



	


zClassChecker._check_initc                 C   s$  t |tjrt |tjs| jd||f|d dS | }tj||}tj||}|jjdu s6|jjdu r8dS t	|j
r?dS t|rEdS t||| jd}t|dkr|D ]}d|v rt|jj}|jjri|d7 }|jjrq|d7 }|jjr}|t|jj7 }t|jj}	|jjr|	d7 }	|jjr|	d7 }	|jjr|	t|jj7 }	d}
|d	|	 d
|jj
 d|j
 d| d	 ||jj
 d|j
 f}n#d|v rd}
|||jj
 d|j
 f}nd}
|||jj
 d|j
 f}| j|
||d qUdS t|jjt|jjk r|jjs| jd||j
f|d dS dS dS )z7check that the signature of the two given methods matchr   rE  Nr   r   NumberrZ   r   zwas z in 'r^  z' and is now z inrenamedr   r   )r,   r   r   rH  instantiate_classrp   scoped_nodesfunction_to_methodr0   r   r/   r   r   rB  r  rC   rB   rE   rb  defaults)r;   method1	refmethod
class_typer   instancearg_differ_outputr  total_args_method1total_args_refmethod
error_typemsg_argsr7   r7   r8   r    s   



(
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.
        )r  rd  rL  r7   r7   r8   r    s   z)ClassChecker._uses_mandatory_method_paramc                 C   s"   | j ot|tjo|j| j d kS )zCheck if nodes.Name corresponds to first attribute variable name

        Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.
        r   )r=  r,   r   r-   r/   rL  r7   r7   r8   r    s
   
z'ClassChecker._is_mandatory_method_paramr(   r  )Br(  r)  r*  r+  r   __implements__r/   MSGSmsgspriorityoptionsr   rp   r  cachedpropertyrB  rC  r   r   ru   rM  rK  rJ  r[  rW  rX  rY  rZ  r   r  visit_asyncfunctiondefr  r  r  rI  r  r  leave_asyncfunctiondefrc  r  rs  r  r  r  r  r  r  r  r  NodeNGr!   r  r  r  r  r  r-   r  r  r  r  rF  r  r  r  r  r7   r7   r7   r8   r,    s    
=


24E^k	%	3
'P
	

	
	
<E	;Nr,  c                   @   sn  e Zd ZdZefZdZddde dddd	gifd
ddddgifddddddddddddZdZ	dWddZ
eddddd d!d"d#d$d%d&d'd(d)ejd*dfd+d,ZeZd-d. Zed/d0 Zed1d2 Zed3d4 Zed5d6 Zed7d8 Zed9d: Zed;d< Zed=d> Zd?d@ ZdAdB ZdCdD ZdEdF ZdGdH ZdIdJ ZdKdL Z dMdN Z!dOdP Z"dQdR Z#dSdT Z$dUdV Z%dS )XSpecialMethodsCheckerzOChecker which verifies that special methods
    are implemented correctly.
    r-  z__iter__ returns non-iteratornon-iterator-returnedzVUsed when an __iter__ method returns something which is not an iterable (i.e. has no `z	` method)	old_names)W0234zold-non-iterator-returned-1)E0234zold-non-iterator-returned-2z6The 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.)E0235zbad-context-manager)z,__len__ does not return non-negative integerinvalid-length-returnedzPUsed when a __len__ method returns something which is not a non-negative integer)z__bool__ does not return boolinvalid-bool-returnedzAUsed when a __bool__ method returns something which is not a bool)z__index__ does not return intinvalid-index-returnedzGUsed when an __index__ method returns something which is not an integer)z__repr__ does not return strinvalid-repr-returnedzCUsed when a __repr__ method returns something which is not a string)z__str__ does not return strinvalid-str-returnedzBUsed when a __str__ method returns something which is not a string)z__bytes__ does not return bytesinvalid-bytes-returnedzAUsed when a __bytes__ method returns something which is not bytes)z__hash__ does not return intinvalid-hash-returnedzEUsed when a __hash__ method returns something which is not an integer)z4__length_hint__ does not return non-negative integerinvalid-length-hint-returnedzXUsed when a __length_hint__ method returns something which is not a non-negative integer)z__format__ does not return strinvalid-format-returnedzEUsed when a __format__ method returns something which is not a string)z&__getnewargs__ does not return a tupleinvalid-getnewargs-returnedzHUsed when a __getnewargs__ method returns something which is not a tuple)zB__getnewargs_ex__ does not return a tuple containing (tuple, dict)invalid-getnewargs-ex-returnedzbUsed when a __getnewargs_ex__ method returns something which is not of the form tuple(tuple, dict))E0301E0302E0303E0304E0305E0306E0307E0308E0309E0310E0311E0312E0313r.  Nc                 C   sH   t | | | j| j| j| j| j| j| j| j	| j
| j| j| jd| _d S )N)__iter____len____bool__	__index____repr____str__	__bytes____hash____length_hint__
__format____getnewargs____getnewargs_ex__)r   r   _check_iter
_check_len_check_bool_check_index_check_repr
_check_str_check_bytes_check_hash_check_length_hint_check_format_check_getnewargs_check_getnewargs_ex_protocol_mapr?  r7   r7   r8   r   U  s   zSpecialMethodsChecker.__init__r?  r@  rA  rB  rC  rD  rE  rF  rG  rH  rI  r^   r   c                 C   sT   |  sd S t||}|r|j| jv r| j|j || |jtv r(| | d S d S r(   )r  r   r/   ro  r	   "_check_unexpected_method_signaturer  r7   r7   r8   r  f  s   

z'SpecialMethodsChecker.visit_functiondefc           
      C   s  t |j }|d u rd S |jjs|jjsd S t|dgr |jj}n|jjdd  }t|t|jj }t|jj}|| }t|trJ||v}d| }n!|| }|dkrUd}n|dk r\d}n|dkrk|| dkpi|jj }|r|dkrsdnd}	| j	d	|j|||	f|d
 d S d S )Nzbuiltins.staticmethodrZ   zbetween %d or %dr   FTwaswerer=  rE  )
r
   r/   r0   rC   r   r  r%  r,   rx   rH  )
r;   r^   expected_paramsr{   	mandatoryoptionalcurrent_paramsemitrestverbr7   r7   r8   rp    s:   




z8SpecialMethodsChecker._check_unexpected_method_signaturec                 C   s$   t | tjo| j|kot | tj S r(   )r,   rp   r   r/   r   rt   )r^   type_r7   r7   r8   _is_wrapped_type  s
   z&SpecialMethodsChecker._is_wrapped_typec                 C   (   t | drdS t| tjot| jtS )NintT)r8  r{  r,   r   rt   r+   r}  r  r7   r7   r8   _is_int     zSpecialMethodsChecker._is_intc                 C   r|  )Nr  T)r8  r{  r,   r   rt   r+   r  r  r7   r7   r8   _is_str  r  zSpecialMethodsChecker._is_strc                 C   r|  )Nr!   T)r8  r{  r,   r   rt   r+   r!   r  r7   r7   r8   _is_bool  r  zSpecialMethodsChecker._is_boolc                 C   r|  )NbytesT)r8  r{  r,   r   rt   r+   r  r  r7   r7   r8   	_is_bytes  r  zSpecialMethodsChecker._is_bytesc                 C   r|  )Nrx   T)r8  r{  r,   r   rt   r+   rx   r  r7   r7   r8   	_is_tuple  r  zSpecialMethodsChecker._is_tuplec                 C   r|  )Nr  T)r8  r{  r,   r   rt   r+   r  r  r7   r7   r8   _is_dict  r  zSpecialMethodsChecker._is_dictc                 C   s   | t ju rdS t| t jjrdS t| t jr*z| t W dS  t jy)   Y dS w t| t	j
rP|  }|rPt|t	j
rPz|t W dS  t jyO   Y dS w dS )NTF)rp   r   r,   rR  	Generatorr   rG  NEXT_METHODr   r   ru   r{  )r^   r{  r7   r7   r8   _is_iterator  s.   

	
z"SpecialMethodsChecker._is_iteratorc                 C       |  |s| jd|d d S d S )Nr9  r  )r  rH  r  r7   r7   r8   rc       
z!SpecialMethodsChecker._check_iterc                 C   L   |  |s| jd|d d S t|tjr"|jdk r$| jd|d d S d S d S )Nr?  r  r   r~  rH  r,   r   rt   r+   r  r7   r7   r8   rd  	  
   
z SpecialMethodsChecker._check_lenc                 C   r  )Nr@  r  )r  rH  r  r7   r7   r8   re  	  r  z!SpecialMethodsChecker._check_boolc                 C   r  )NrA  r  r~  rH  r  r7   r7   r8   rf  	  r  z"SpecialMethodsChecker._check_indexc                 C   r  )NrB  r  r  rH  r  r7   r7   r8   rg  	  r  z!SpecialMethodsChecker._check_reprc                 C   r  )NrC  r  r  r  r7   r7   r8   rh  	  r  z SpecialMethodsChecker._check_strc                 C   r  )NrD  r  )r  rH  r  r7   r7   r8   ri  	  r  z"SpecialMethodsChecker._check_bytesc                 C   r  )NrE  r  r  r  r7   r7   r8   rj  	  r  z!SpecialMethodsChecker._check_hashc                 C   r  )NrF  r  r   r  r  r7   r7   r8   rk   	  r  z(SpecialMethodsChecker._check_length_hintc                 C   r  )NrG  r  r  r  r7   r7   r8   rl  &	  r  z#SpecialMethodsChecker._check_formatc                 C   r  )NrH  r  )r  rH  r  r7   r7   r8   rm  *	  r  z'SpecialMethodsChecker._check_getnewargsc                 C   s   |  |s| jd|d d S t|tjsd S d}t|jdkr"d}n.|jd | j f|jd | jffD ]\}}t|tjr@t	|}|rO|t
jurO||sOd} nq2|r[| jd|d d S d S )NrI  r  F   Tr   rZ   )r  rH  r,   r   rv   r  rk   r  r   r   rp   r   )r;   r^   r   found_errorr*   checkr7   r7   r8   rn  .	  s*   
z*SpecialMethodsChecker._check_getnewargs_exr(   )&r(  r)  r*  r+  r   r/  r/   r  r1  r2  r   r   r   r   r  r5  rp  r  r{  r~  r  r  r  r  r  r  rc  rd  re  rf  rg  rh  ri  rj  rk  rl  rm  rn  r7   r7   r7   r8   r8    s    R
0







r8  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)recurs)r  r   r  rp   r   )r  rY   r  	base_noder7   r7   r8   r  M	  s   r  c                 C   s    |  t|  |  t|  dS )z-required method to auto register this checkerN)register_checkerr,  r8  )r@  r7   r7   r8   registerZ	  s   r  r(   )r   )Fr+  r  	itertoolsr   r   typingr   r   rp   r   pylint.checkersr   r   pylint.checkers.utilsr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   pylint.interfacesr   pylint.utilsr   r  r   BUILTIN_DECORATORS
namedtupler&   r'   r9   rG   rW   r]   ra   rf   r   rn  r  r   r   r   r   r   r   r   r   r   r   r0  r  r  r,  r8  r  r  r7   r7   r7   r8   <module>   sV  0X(:

N$
 &-5=ELRX^djou|   
          $  )  .  3  9  >  C  H  N  W            
U