o
    g                    @   s  d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZ ddlZddlmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZmZmZmZ ddlmZ ddlmZ G d	d
 d
ZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#ee e!e"e#dZ$e%dZ&dZ'dZ(e(e'ffZ)e*dZ+ej,ejej-ej.fZ/dZ0dZ1ddhZ2ddhZ3e4e5d d! d"D g d#fi d$d% d&D Z6d'd(d)d*d+Z7e*d,Z8e*d-Z9d.Z:d/d0 Z;d1d2 Z<d3d4 Z=d5d6 Z>d7d8 Z?d9d: Z@d;ZAd<d= ZBdpd>ejCfd?d@ZDdAdB ZEdCedDefdEdFZFdGdH ZGG dIdJ dJejHZIG dKdL dLeIZJG dMdN dNeIZKh dOZLdPdQdRdSdTdUdVdWdXdYdZd[ZMd\d]d^d\d\d\d\d\d_d]d_d[ZNd`da ZOG dbdc dceIZPG ddde deeIZQG dfdg dgeIZRdhdi ZSdjdk ZTG dldm dmeIZUdndo ZVdS )qzbasic checker for Python code    N)AnyDictIteratorOptionalPatternUnion)nodes)checkers
exceptions
interfaces)utils)	infer_allis_overload_stubis_property_deleteris_property_setter)CheckerStatsc                   @   s   e Zd ZU dZedZee e	d< eZ
ee e	d< eZee e	d< eZee e	d< eZee e	d< eZee e	d< eZee e	d	< ed
d ZdS )NamingStylezIt may seem counterintuitive that single naming style has multiple "accepted"
    forms of regular expressions, but we need to special-case stuff like dunder names
    in method names.z.*ANYCLASS_NAME_RGXMOD_NAME_RGXCONST_NAME_RGXCOMP_VAR_RGXDEFAULT_NAME_RGXCLASS_ATTRIBUTE_RGXc                 C   s6   | j | j| j| j| j| j| j| j| j| j| jd| S )Nmoduleconstclassfunctionmethodattrargumentvariableclass_attributeclass_const	inlinevar)r   r   r   r   r   r   )cls	name_type r(   R/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/checkers/base.py	get_regexf   s   zNamingStyle.get_regexN)__name__
__module____qualname____doc__recompiler   r   str__annotations__r   r   r   r   r   r   classmethodr*   r(   r(   r(   r)   r   Y   s   
 r   c                   @   L   e Zd ZdZedZedZedZedZ	edZ
edZdS )SnakeCaseStylez(Regex rules for snake_case naming style.z[^\W\dA-Z][^\WA-Z]+$z[^\W\dA-Z][^\WA-Z]*$z([^\W\dA-Z][^\WA-Z]*|__.*__)$z=([^\W\dA-Z][^\WA-Z]{2,}|_[^\WA-Z]*|__[^\WA-Z\d_][^\WA-Z]+__)$z ([^\W\dA-Z][^\WA-Z]{2,}|__.*__)$Nr+   r,   r-   r.   r/   r0   r   r   r   r   r   r   r(   r(   r(   r)   r5   w   s    



r5   c                   @   r4   )CamelCaseStylez'Regex rules for camelCase naming style.z[^\W\dA-Z][^\W_]+$z[^\W\dA-Z][^\W_]*$z([^\W\dA-Z][^\W_]*|__.*__)$z*([^\W\dA-Z][^\W_]{2,}|__[^\W\dA-Z_]\w+__)$z([^\W\dA-Z][^\W_]{2,}|__.*__)$Nr6   r(   r(   r(   r)   r7          




r7   c                   @   L   e Zd ZdZedZedZedZedZ	edZ
edZdS )PascalCaseStylez(Regex rules for PascalCase naming style.z[^\W\da-z][^\W_]+$z([^\W\da-z][^\W_]*|__.*__)$z*([^\W\da-z][^\W_]{2,}|__[^\W\dA-Z_]\w+__)$z[^\W\da-z][^\W_]{2,}$Nr6   r(   r(   r(   r)   r:      r8   r:   c                   @   r9   )UpperCaseStylez(Regex rules for UPPER_CASE naming style.z[^\W\da-z][^\Wa-z]+$z([^\W\da-z][^\Wa-z]*|__.*__)$z,([^\W\da-z][^\Wa-z]{2,}|__[^\W\dA-Z_]\w+__)$z[^\W\da-z][^\Wa-z]{2,}$Nr6   r(   r(   r(   r)   r;      r8   r;   c                   @   s   e Zd ZdS )AnyStyleN)r+   r,   r-   r(   r(   r(   r)   r<      s    r<   )
snake_case	camelCase
PascalCase
UPPER_CASEanyz^___reversed__)__getitem____len__)isis not==!=zunittest.casezbuiltins.typez_py_abc.ABCMetazabc.ABCMetaexemptignorec                 C   s   g | ]	}d  d|gqS ).builtins)join.0xr(   r(   r)   
<listcomp>   s    rQ   )setdictlist)zset(){}z[]c                 C   s   i | ]}|| d qS )z()r(   rN   r(   r(   r)   
<dictcomp>   s    
rV   )zcollections.dequezcollections.ChainMapzcollections.Counterzcollections.OrderedDictzcollections.defaultdictzcollections.UserDictzcollections.UserList>>=<<=)rY   rZ   rW   rX   )rG   rH   rY   rW   rZ   rX   )r,   ztyping.ForwardRefc                 C   s   | }|rt |jtjs|j}|rt |jtjr|r t|jts"dS |jj}|tjtj	fD ]}|j
D ]\}}|rD|| jkrC  dS q4|| jkrM  dS q4q/dS )zDetect that the given node (AssignName) is inside an
    exception handler and redefines an import from the tryexcept body.
    Returns True if the node redefines an import, False otherwise.
    FT)
isinstanceparentr   ExceptHandlerr   error_of_typeImportErrornodes_of_class
ImportFromImportnamesname)nodecurrent	try_blockimport_noderd   aliasr(   r(   r)   _redefines_import   s$   

rj   c                 C   sB   | j }|durt|tjtjtjtjtjfrdS |j }|dusdS )z4return True if the node is inside a kind of for loopNTF)r\   r[   r   ForListCompSetCompDictCompGeneratorExp)re   r\   r(   r(   r)   in_loop   s   
rp   c                 C   s<   | D ]}t |ttfrt||r dS q||kr dS qdS )zUreturn true if the object is an element of <nested_list> or of a nested
    list
    TF)r[   rT   tuplein_nested_list)nested_listobjelmtr(   r(   r)   rr     s   
rr   c                 C   sb   t jt jf}| j}t||r| t|dg v r/|} |j}|du r"	 |S t||r| t|dg v s|S )z
    Returns the loop node that holds the break node in arguments.

    Args:
        break_node (astroid.Break): the break node of interest.

    Returns:
        astroid.For or astroid.While: the loop node holding the break node.
    orelseN)r   rk   Whiler\   r[   getattr)
break_node
loop_nodesr\   r(   r(   r)   _get_break_loop_node  s   
r{   c                    sV   t jt jf}t jt jf}fddj||dD  t fddjt j|dD S )z
    Returns true if a loop may ends up in a break statement.

    Args:
        loop (astroid.For, astroid.While): the loop node inspected.

    Returns:
        bool: True if the loop may ends up in a break statement, False otherwise.
    c                    s   g | ]}| kr|qS r(   r(   rO   _node)loopr(   r)   rQ   1  s
    z%_loop_exits_early.<locals>.<listcomp>
skip_klassc                 3   s     | ]}t | vr|V  qd S N)r{   r|   )inner_loop_nodesr(   r)   	<genexpr>6  s    z$_loop_exits_early.<locals>.<genexpr>)r   rk   rw   FunctionDefClassDefr`   rA   Break)r~   rz   definition_nodesr(   )r   r~   r)   _loop_exits_early%  s   

r   c                 C   s.   | d uo| j d uo| j tvo|dkp|tjkS )Nr   )	lastgroupEXEMPT_NAME_CATEGORIESr   INFERENCE_FAILURE)match	node_type
confidencer(   r(   r)   _is_multi_naming_match=  s   r   zbuiltins.propertyc                 C   s>   t h}t }| dur|| j |dd | jD  ||fS )zReturns a tuple of property classes and names.

    Property classes are fully qualified, such as 'abc.abstractproperty' and
    property names are the actual names, such as 'abstract_property'.
    Nc                 s   s     | ]}| d dd V  qdS )rK      N)rsplit)rO   propr(   r(   r)   r   S  s    
z"_get_properties.<locals>.<genexpr>)BUILTIN_PROPERTYrR   updateproperty_classes)configr   property_namesr(   r(   r)   _get_propertiesI  s   
r   re   c                 C   s   t |\}}|  sdS t| st| rdS | jr| jjng }|D ](}t|tjs4t|tjrI|j	|v rIt
|}|rIt|drI| |v rI dS q!dS )a0  Determine the name type whose regex the a function's name should match.

    :param node: A function node.
    :param config: Configuration from which to pull additional property classes.
    :type config: :class:`optparse.Values`

    :returns: One of ('function', 'method', 'attr')
    :rtype: str
    r   r    qnamer   )r   	is_methodr   r   
decoratorsr   r[   Name	Attributeattrnamer   
safe_inferhasattrr   )re   r   r   r   r   	decoratorinferredr(   r(   r)   _determine_function_name_typeY  s(   



r   c                 C   s   t t| dkS )z
    Determine if the given `node` has abstract methods.

    The methods should be made abstract by decorating them
    with `abc` decorators.
    r   )lenr   unimplemented_abstract_methodsre   r(   r(   r)   _has_abstract_methods~  s   r   stats	old_statsc                 C   s  i }dD ]r}z|| }W n t y } zt |d}~ww i ||< |dkrvz|d|  }|| }|d | }	|	d|| d< W n t yO   d|| d< Y nw z|d	|  }
|
d | }	|	d|| d
< W q t yu   d|| d
< Y qw qg d}dD ]5}|| }||d}|durt||}nd\}}||t|t|||| dd|| d
dg7 }q}| tj	|ddd dS )zymake a report of

    * percentage of different types documented
    * percentage of different types with a bad name
    )r   r   r   r   Nr   undocumented_g      Y@z.2fpercent_documentedNCbadname_percent_badname)typenumberz
old number
differencez%documentedz%badname)r   r   0   r   )childrencolsrheaders)
KeyErrorr
   EmptyReportErrorget
lint_utilsdiff_stringr1   appendreporter_nodesTable)sectr   r   
nice_statsr   totaleundocumented_node
documentedpercentbadname_nodelinesnewolddiff_strr(   r(   r)   report_by_type_stats  sT   
r   c                 C   s>   | j r| j jD ]}t|tjrt|jdd| jkr dS qdS )zreturn True if the object is a method redefined via decorator.

    For example:
        @property
        def x(self): return self._x
        @x.setter
        def x(self, value): self._x = value
    rd   NTF)r   r   r[   r   rx   exprrd   )re   r   r(   r(   r)   redefined_by_decorator  s   	
r   c                   @   s   e Zd ZejZdZdS )_BasicCheckerbasicN)r+   r,   r-   r   IAstroidChecker__implements__rd   r(   r(   r(   r)   r     s    r   c                	   @   s  e Zd Zi ddddddddd	d
ddddddddifdddddddddddddd d!d"d#d$d%d&dd'ifd(d)d*d+d,d-d.d/ifiZed0d1ejd2d3fd4d5Zd6d7 Z	ed8d9d1ej
d2d3fd:d;Zed<d1ejd2d3fd=d>Zed?d@d0ddAdBd,d1ejd2d3fdCdDZeZdEdF ZdGdH ZedId1ejd2d3fdJdKZedLd1ejd2d3fdMdNZedLd1ejd2d3fdOdPZedQd%d1ejd2d3fdRdSZedQd1ejd2d3fdTdUZedVd1ejd2d3fdWdXZedVd1ejd2d3fdYdZZ ed[d1ej!d2d3fd\d]Z"d^d_ Z#ed`d1ej$d2d3fdadbZ%edcd1ej&d2d3fdddeZ'dfdg Z(dhdi Z)djdk Z*dldm Z+dndo Z,d3S )pBasicErrorCheckerE0100)z__init__ method is a generatorinit-is-generatorz^Used when the special class method __init__ is turned into a generator by a yield in its body.E0101)zExplicit return in __init__return-in-initzIUsed when the special class method __init__ has an explicit return value.E0102)z%s already defined line %sfunction-redefinedz3Used when a function / class / method is redefined.E0103)z%r not properly in loopnot-in-loopz=Used when break or continue keywords are used outside a loop.E0104)zReturn outside functionreturn-outside-functionzEUsed when a "return" statement is found outside a function or method.E0105)zYield outside functionyield-outside-functionzDUsed when a "yield" statement is found outside a function or method.E0106z%Return with argument inside generatorzreturn-arg-in-generatorzUsed when a "return" statement with an argument is found outside in a generator function or method (e.g. with some "yield" statements).
maxversion)   r   E0107)z#Use of the non-existent %s operatornonexistent-operatorzzUsed when you attempt to use the C-style pre-increment or pre-decrement operator -- and ++, which doesn't exist in Python.E0108)z1Duplicate argument name %s in function definitionduplicate-argument-namezCDuplicate argument names in function definitions are syntax errors.E0110)z4Abstract class %r with abstract methods instantiatedabstract-class-instantiatedzeUsed when an abstract class with `abc.ABCMeta` as metaclass has abstract methods and is instantiated.W0120)z-Else clause on loop without a break statementuseless-else-on-loopzLoops should only have an else clause if they can exit early with a break statement, otherwise the statements under else should be on the same scope as the loop itself.E0112)z.More than one starred expression in assignmenttoo-many-star-expressionszhEmitted when there are more than one starred expressions (`*x`) in an assignment. This is a SyntaxError.E0113)z4Starred assignment target must be in a list or tupleinvalid-star-assignment-targetzFEmitted when a star expression is used as a starred assignment target.E0114)z4Can use starred expression only in assignment targetstar-needs-assignment-targetzCEmitted when a star expression is not used in an assignment target.E0115)zName %r is nonlocal and globalnonlocal-and-globalz0Emitted when a name is both nonlocal and global.E0116z0'continue' not supported inside 'finally' clausecontinue-in-finallyz]Emitted when the `continue` keyword is found inside a finally clause, which is a SyntaxError.)r      E0117)z&nonlocal name %s found without bindingnonlocal-without-bindingz^Emitted when a nonlocal variable does not have an attached name somewhere in the parent scopesE0118z+Name %r is used prior to global declarationused-prior-global-declarationzcEmitted when a name is used prior a global declaration, which results in an error since Python 3.6.
minversion)r   r   r   re   returnNc                 C      |  d| d S Nr   )_check_redefinitionselfre   r(   r(   r)   visit_classdef@     z BasicErrorChecker.visit_classdefc                 C   sH   d}|  D ]}t|tjr| |  S t|tjr|d7 }q|dkS )Nr   r   )iteredr[   r   Tuple_too_many_starred_for_tupleStarred)r   assign_tuplestarred_countelemr(   r(   r)   r  D  s   z-BasicErrorChecker._too_many_starred_for_tupler   r   c                 C   sZ   |j d }t|j d tjr| jd|d t|tjsd S | |r+| jd|d d S d S )Nr   r   r   r   )targetsr[   r   r  add_messager  r  )r   re   assign_targetr(   r(   r)   visit_assignM  s   

zBasicErrorChecker.visit_assignr   c                 C   sv   t |jtjr	dS t |jtjtjtjtjfrdS | }t |tj	s%dS |j
|u s0|j
|r9| jd|d dS dS )z@Check that a Starred expression is used in an assignment target.Nr   r   )r[   r\   r   CallListr  Setr   	statementAssignvalue	parent_ofr  )r   re   stmtr(   r(   r)   visit_starredZ  s   zBasicErrorChecker.visit_starredr   r   r   r   c           	      C   s0  |  | | | t|st|s| | rdpd| |jtj	tj
tjfd}| rW|jdkrW| r@| jd|d ndd |D }td	d
 |D rW| jd|d tt}td |jj|jjg}tj|D ]
}||j | qm| D ]}t|dkr|D ]}| jd|j||jfd qq|d S )Nr   r   r   __init__r   r   c                 S   s   g | ]}|j qS r(   r  )rO   rr(   r(   r)   rQ         z7BasicErrorChecker.visit_functiondef.<locals>.<listcomp>c                 s       | ]
}t |s|V  qd S r   )r   is_nonerO   vr(   r(   r)   r         z6BasicErrorChecker.visit_functiondef.<locals>.<genexpr>r   r   r   )linere   args)_check_nonlocal_and_global_check_name_used_prior_globalr   r   (is_registered_in_singledispatch_functionr   r   r`   r   Returnr   r   rd   is_generatorr  rA   collectionsdefaultdictrT   filterr!  
kwonlyargs	itertoolschainfrom_iterabler   valuesr   lineno)	r   re   returnsr.  arg_clusters	argumentsargargument_duplicatesr!   r(   r(   r)   visit_functiondefl  s@   



z#BasicErrorChecker.visit_functiondefc                    s    fdd  tjD }|sd S   tjD ]'}|  ur q|j}||}|s+q|j}|r>||jkr>| jd||fd qd S )Nc                    s*   i | ]}|j D ]}|  u r||qqS r(   )rc   scope)rO   childrd   r   r(   r)   rV     s    zCBasicErrorChecker._check_name_used_prior_global.<locals>.<dictcomp>r   re   r!  )	r`   r   Globalr   r6  rd   r   
fromlinenor  )r   re   scope_globals	node_namerd   corresponding_globalglobal_linenor(   r   r)   r#    s&   


z/BasicErrorChecker._check_name_used_prior_globalc                    s    fddt jj}t|fdd tjD }|sdS t|fdd tjD }||D ]}| j	d|f d q5dS )	z.Check that a name is both nonlocal and global.c                    s   |    u S r   )r6  )rf   r   r(   r)   
same_scope  s   z@BasicErrorChecker._check_nonlocal_and_global.<locals>.same_scopec                 3       | ]
} |r|j V  qd S r   rc   rO   r7  r?  r(   r)   r         
z?BasicErrorChecker._check_nonlocal_and_global.<locals>.<genexpr>Nc                 3   r@  r   rA  rB  rC  r(   r)   r     rD  r   r!  re   )
r+  r,  r-  rR   r`   r   Nonlocalr9  intersectionr  )r   re   	from_iter	nonlocalsglobal_varsrd   r(   )re   r?  r)   r"    s"   

z,BasicErrorChecker._check_nonlocal_and_globalr   c                 C   s&   t | tjs| jd|d d S d S )Nr   r   )r[   framer   r   r  r   r(   r(   r)   visit_return  s   zBasicErrorChecker.visit_returnr   c                 C      |  | d S r   _check_yield_outside_funcr   r(   r(   r)   visit_yield     zBasicErrorChecker.visit_yieldc                 C   rM  r   rN  r   r(   r(   r)   visit_yieldfrom  rQ  z!BasicErrorChecker.visit_yieldfromr   c                 C      |  |d d S )Ncontinue_check_in_loopr   r(   r(   r)   visit_continue  r  z BasicErrorChecker.visit_continuec                 C   rS  )NbreakrU  r   r(   r(   r)   visit_break  r  zBasicErrorChecker.visit_breakr   c                 C   rM  r   _check_else_on_loopr   r(   r(   r)   	visit_for  rQ  zBasicErrorChecker.visit_forc                 C   rM  r   rZ  r   r(   r(   r)   visit_while  rQ  zBasicErrorChecker.visit_whiler   c                 C   sL   |j dv r t|jtjr"|jj |j kr$| jd||j d d dS dS dS dS )z9check use of the non-existent ++ and -- operator operatorz+-r      r8  N)opr[   operandr   UnaryOpr  r   r(   r(   r)   visit_unaryop  s   
zBasicErrorChecker.visit_unaryopc                 C   s~   |  }	 |jd u rn!t|tjtjfs| jd|f|d d S ||jvr*|j  }qd S t|tjs=| jd|f|d d S d S )NTr   rE  )r6  r\   r[   r   r   r   r  locals)r   re   rd   current_scoper(   r(   r)   _check_nonlocal_without_binding  s   


z1BasicErrorChecker._check_nonlocal_without_bindingr   c                 C   s   |j D ]}| || qd S r   )rc   re  r   re   rd   r(   r(   r)   visit_nonlocal  s   
z BasicErrorChecker.visit_nonlocalr   c                 C   s    t |jD ]}| || qdS )zRCheck instantiating abstract class with
        abc.ABCMeta as metaclass.
        N)r   func!_check_inferred_class_is_abstract)r   re   r   r(   r(   r)   
visit_call  s   zBasicErrorChecker.visit_callc                 C   s   t |tjsd S t|}||u rd S t|}|sd S | }|d u r?| D ]}| dkr<| j	d|j
f|d  d S q'd S | tv rQ| j	d|j
f|d d S d S )Nzabc.ABCr   rE  )r[   r   r   r   node_frame_classr   	metaclass	ancestorsr   r  rd   ABC_METACLASSES)r   r   re   klassabstract_methodsrl  ancestorr(   r(   r)   ri    s0   



z3BasicErrorChecker._check_inferred_class_is_abstractc                 C   s,   t | tjtjfs| jd|d d S d S )Nr   r   )r[   rK  r   r   Lambdar  r   r(   r(   r)   rO  @  s   z+BasicErrorChecker._check_yield_outside_funcc                 C   s6   |j rt|s| jd||j d jd d dS dS dS )z>Check that any loop with an else clause has a break statement.r   r   r   )re   r   N)rv   r   r  r/  r   r(   r(   r)   r[  D  s   
z%BasicErrorChecker._check_else_on_loopc                 C   s   |j }|r<t|tjtjfr||jvrdS t|tjtjfrnt|tjr7||j	v r7t|tj
r7| jd|d |j }|s| jd||d dS )z/check that a node is inside a for or while loopNr   r   r   r8  )r\   r[   r   rk   rw   rv   r   r   
TryFinally	finalbodyContinuer  )r   re   r<  r}   r(   r(   r)   rV  P  s    



z BasicErrorChecker._check_in_loopc           
      C   s  |j  }dd |j|j D }tdd |D |}||urt||st|tj	r1|jt
v r1dS t|r8dS t|j tjrt|j jtjrb|j jjdkrbt|j jjtjrb|j jjj|jkrbdS t|j jtjrt|j jjtjr|j jjj|jkr|j jjd d dkrt|j jjd d	 tjr|j jjd d	 jdu rdS z||}W n	 ty   Y n w |d| D ]}t|}|rt|tjr| tkr dS qtj| d
dd}	|	r|	 |jrdS | j!d|||j"fd dS dS dS )z:check for redefinition of a function / method / class namec                 S   s&   g | ]}t |jtjr|jjs|qS r(   )r[   r\   r   	AnnAssignsimple)rO   ir(   r(   r)   rQ   j  s    z9BasicErrorChecker._check_redefinition.<locals>.<listcomp>c                 s   r  r   )r   r   )rO   localr(   r(   r)   r   p  r  z8BasicErrorChecker._check_redefinition.<locals>.<genexpr>Nnotr   rE   r   dummy-variables-rgxdefaultr   r8  )#r\   rK  rc  rd   nextastroidare_exclusiver[   r   r   REDEFINABLE_METHODSr   r   Iftestra  r_  r`  r   CompareleftopsConstr  index
ValueErrorr   Instancer   TYPING_FORWARD_REF_QNAMEr   get_global_optionr   r  r:  )
r   	redeftypere   parent_frameredefinitionsdefined_selfredefinition_indexredefinitionr   dummy_variables_rgxr(   r(   r)   r   e  st   







z%BasicErrorChecker._check_redefinition)-r+   r,   r-   msgsr   check_messagesr   r   r  r  r  r  r  r  r   r5  visit_asyncfunctiondefr#  r"  r%  rL  YieldrP  	YieldFromrR  ru  rW  r   rY  rk   r\  rw   r]  ra  rb  re  rF  rg  r  rj  ri  rO  r[  rV  r   r(   r(   r(   r)   r     s    !)/4:AGLQV]cl
		%
	%r   c                   @   sP  e Zd ZdZejZdZi ddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'Zd(d)e	ffZ
d*d+ Zd,d- Zed.d/d0ejd1d2fd3d4Zed.d/d0ejd1d2fd5d6Zed.d/d0ejd1d2fd7d8Zd9d: Zd;ejd1d2fd<d=Zd;ejd1d2fd>d?Zed@dAdBd0ejd1d2fdCdDZedEdF ZedGdH ZedId0ej d1d2fdJdKZ!edLd0ej"d1d2fdMdNZ#e#Z$dOdP Z%edQdRd0ej&d1d2fdSdTZ'edQd0ej(d1d2fdUdVZ)edQdRd0ej*d1d2fdWdXZ+edQd0ej,d1d2fdYdZZ-d[d\ Z.ed]d^d_d`d0ej/d1d2fdadbZ0edcddd0ej1d1d2fdedfZ2edgd0ej3d1d2fdhdiZ4d0ej5d1d2fdjdkZ6d;ej5d1d2fdldmZ7dndo Z8ddqdrZ9dsdt Z:edud0ej;d1d2fdvdwZ<dxdy Z=dzd{ Z>ed|d}d0ej?d1d2fd~dZ@ed}d0ejAd1d2fddZBd2S )BasicCheckera*  checks for :
    * doc strings
    * number of arguments, local variables, branches, returns and statements in
    functions, methods
    * required module attributes
    * dangerous default values as arguments
    * redefinition of function / method / class
    * uses of the global statement
    r   W0101)zUnreachable codeunreachablezbUsed when there is some code behind a "return" or "raise" statement, which will never be accessed.W0102)z&Dangerous default value %s as argumentdangerous-default-valuez_Used when a mutable value as list or dictionary is detected in a default value for an argument.W0104)z!Statement seems to have no effectpointless-statementzEUsed when a statement doesn't have (or at least seems to) any effect.W0105)zString statement has no effectpointless-string-statementzUsed when a string is used as a statement (which of course has no effect). This is a particular case of W0104 with its own message so you can easily disable it if you're using those strings as documentation, instead of comments.W0106)z&Expression "%s" is assigned to nothingexpression-not-assignedzqUsed when an expression that is not a function call is assigned to nothing. Probably something else was intended.W0108)zLambda may not be necessaryunnecessary-lambdazUsed when the body of a lambda expression is a function call on the same argument list as the lambda itself; such lambda expressions are in all but a few cases replaceable with the function being called in the body of the lambda.W0109)zDuplicate key %r in dictionaryduplicate-keyzDUsed when a dictionary expression binds the same key multiple times.W0122)zUse of exec	exec-usedz~Used when you use the "exec" statement (function for Python 3), to discourage its usage. That doesn't mean you cannot use it !W0123)zUse of eval	eval-usedzUsed when you use the "eval" function, to discourage its usage. Consider using `ast.literal_eval` for safely evaluating strings containing Python expressions from untrusted sources. W0150)z3%s statement in finally block may swallow exceptionlost-exceptionzUsed when a break or a return statement is found inside the finally clause of a try...finally block: the exceptions raised in the try clause will be silently swallowed instead of being re-raised.W0199)z;Assert called on a 2-item-tuple. Did you mean 'assert x,y'?assert-on-tuplezA call of assert on a tuple will always evaluate to true if the tuple is not empty, and will always evaluate to false if it is.W0124)z?Following "as" with another context manager looks like a tuple.confusing-with-statementa2  Emitted when a `with` statement component returns multiple values and uses name binding with `as` only for a part of those values, as in with ctx() as a, b. This can be misleading, since it's not clear if the context manager returns a tuple or if the node without a name binding is another context manager.W0125)z3Using a conditional statement with a constant valueusing-constant-testzEmitted when a conditional statement (If or ternary if) uses a constant value for its test. This might not be what the user intended to do.W0126)zgUsing a conditional statement with potentially wrong function or method call due to missing parentheses$missing-parentheses-for-call-in-testzsEmitted when a conditional statement (If or ternary if) seems to wrongly call a function due to missing parenthesesW0127)z(Assigning the same variable %r to itselfself-assigning-variablez<Emitted when we detect that a variable is assigned to itselfW0128)z$Redeclared variable %r in assignmentredeclared-assigned-namezMEmitted when we detect that a variable was redeclared in the same assignment.E0111)z/The first reversed() argument is not a sequencebad-reversed-sequencezUsed when the first argument to reversed() builtin isn't a sequence (does not implement __reversed__, nor __getitem__ and __len__)z$format function is not called on strmisplaced-format-functionzEmitted when format function is not called on str object. e.g doing print("value: {}").format(123) instead of print("value: {}".format(123)). This might not be what the user intended to do.)zUAssert statement has a string literal as its first argument. The assert will %s fail.assert-on-string-literalzuUsed when an assert statement has a string literal as its first argument, which will cause the assert to always pass.)E0119W0129RP0101zStatistics by typec                 C   s   t | | i | _d | _d S r   )r   r  r   _tryfinallysr   linterr(   r(   r)   r  D  s   
zBasicChecker.__init__c                 C   s    g | _ | jjddddd| _dS )z)initialize visit variables and statisticsr   )r   r   r   class_N)r  r  	add_statsr   r   r(   r(   r)   openI  s   zBasicChecker.openr  r  re   r   Nc                 C      |  ||j d S r   _check_using_constant_testr  r   r(   r(   r)   visit_ifN     zBasicChecker.visit_ifc                 C   r  r   r  r   r(   r(   r)   visit_ifexpR  r  zBasicChecker.visit_ifexpc                 C   s&   |j r|j D ]
}| || qd S d S r   )ifsr  )r   re   if_testr(   r(   r)   visit_comprehensionV  s
   
z BasicChecker.visit_comprehensionc           
   	   C   sL  t jt jt jt jt jtjjtj	tj
t jf	}t jt jt jt jf}t jt jt jt jt jf}d }t|t jf| | }t||sBt|}|rM| jd|d d S t||rd }zt|t jr`| }nt|t jrk||}W n tjyx   d }Y nw |rz|D ]}	|	tjkr| jd|d  nq~W n
 tjy   Y nw | jd|d d S d S )Nr  r   r  )r   Modulero   rr  r   r   r  bases	GeneratorUnboundMethodBoundMethodr   r  r  r  r  BinOpBoolOpra  	Subscriptr[   r  r   r   r  infer_call_resultInferenceErrorUninferable)
r   re   r  const_nodesstructsexcept_nodesr   emitcall_inferredinf_callr(   r(   r)   r  \  sb   





z'BasicChecker._check_using_constant_test_c                 C      | j d  d7  < dS )z3check module name, docstring and required argumentsr   r   Nr   r   r  r(   r(   r)   visit_module  s   zBasicChecker.visit_modulec                 C   r  )zWcheck module name, docstring and redefinition
        increment branch counter
        r   r   Nr  r  r(   r(   r)   r    s   zBasicChecker.visit_classdefr  r  r  c                 C   s  |j }t|tjrLt|j trL| }t|tjtjtjfrCt|tjr*|j	dkr*n|
 }|durC| |u rCt|tjtjfrCdS | jd|d dS t|tjtjtjfspt|jtjre|jj|gkspt|tjrr|j tu rrdS t|tjr| jd|| d dS | jd|d dS )z3Check for various kind of statements without effectr  Nr  r   r  r8  r  )r  r[   r   r  r1   r6  r   r  r   rd   previous_siblingr  rv  r  r  Awaitr  r\   	TryExceptbodyEllipsisrA   r`   	as_string)r   re   r   r6  siblingr(   r(   r)   
visit_expr  s8   




zBasicChecker.visit_exprc                 c   sH    |D ]}t |tjrt |jtjr|jj| jjkr|V  q|V  qd S r   )r[   r   r  r  r   rd   r!  vararg)re   	call_argsr3  r(   r(   r)   _filter_vararg  s   zBasicChecker._filter_varargc                 C   s<   | sdS | D ]}t |jtjr|jj|kr dS q dS dS )NTF)r[   r  r   r   rd   )r!  variadic_namer3  r(   r(   r)   _has_variadic_argument  s   z#BasicChecker._has_variadic_argumentr  c           	      C   s`  |j jrdS |j}t|tjsdS t|jjtjr$t|jjjtjr$dS t	j
j|}t|j j }t| ||j }|j jrI| |j|j jrIdS |j jrY| |j|j jrXdS n|jr^dS |jrdd |j jD }t|t|jkrudS t|j|rdS t|t|krdS t||D ]\}}t|tjs dS |j|jkr dS q| jd|j|d dS )z-check whether or not the lambda is suspiciousNc                 S   s   h | ]}|j qS r(   rd   )rO   keywordr(   r(   r)   	<setcomp>  r  z,BasicChecker.visit_lambda.<locals>.<setcomp>r  )r   re   )r!  defaultsr  r[   r   r  rh  r   r   r  r2  CallSite	from_callrT   r  kwargr  kwargsr  starargskeywordsr   keyword_argumentsrR   r   zipr   rd   r  r:  )	r   re   call	call_siteordinary_argsnew_call_argslambda_kwargsr3  
passed_argr(   r(   r)   visit_lambda  sH   zBasicChecker.visit_lambdar  c                 C   s,   | j | rdnd  d7  < | | dS )zdcheck function name, docstring, arguments, redefinition,
        variable names, max locals
        r   r   r   N)r   r   _check_dangerous_defaultr   r(   r(   r)   r5    s   zBasicChecker.visit_functiondefc              	   C   s  dd }|j jpg |j j pg }|D ]x}|sqzt| }W n
 tjy)   Y qw t|tjr|	 t
v r||u rAt
|	  }n@t|tjsK||rs||rT| }n-t|tjrf|j d|	  d}n|  d|	  d}n|  dt
|	   d}| jd||fd qdS )	z0Check for dangerous default values as arguments.c                 S   s   t | tjtjtjfS r   )r[   r   r  r  r   )internal_noder(   r(   r)   is_iterable,  s   z:BasicChecker._check_dangerous_default.<locals>.is_iterablez() () (r  r8  N)r!  r  kw_defaultsr~  inferr  r  r[   r  r   DEFAULT_ARGUMENT_SYMBOLSpytyper   r  rd   r  r  )r   re   r	  r  r}  r  msgr(   r(   r)   r  )  s2   

z%BasicChecker._check_dangerous_defaultr  r  c                 C   s    |  | | |dtjf dS )1 - check is the node has a right sibling (if so, that's some
        unreachable code)
        2 - check is the node is inside the finally clause of a try...finally
        block
        r   N)_check_unreachable_check_not_in_finallyr   r   r   r(   r(   r)   rL  Q  s   
zBasicChecker.visit_returnc                 C      |  | dS )z\check is the node has a right sibling (if so, that's some unreachable
        code)
        Nr  r   r(   r(   r)   rW  \     zBasicChecker.visit_continuec                 C   s$   |  | | |dtjtjf dS )r  rX  N)r  r  r   rk   rw   r   r(   r(   r)   rY  c  s   
zBasicChecker.visit_breakc                 C   r  )z\check if the node has a right sibling (if so, that's some unreachable
        code)
        Nr  r   r(   r(   r)   visit_raiseo  r  zBasicChecker.visit_raisec                 C   s   t |jtjs	d S |jjdkrd S t|jj}|tj	u rd S |sC|jj}t |tj
s-d S t |jtjrE|jjdkrG| jd|d d S d S d S d S )Nformatprintr  r   )r[   rh  r   r   r   r   r   r   r  r  r  r   rd   r  )r   	call_noder   	call_exprr(   r(   r)    _check_misplaced_format_functionv  s$   
z-BasicChecker._check_misplaced_format_functionr  r  r  r  c                 C   s   |  | t|jtjrA|jj}|| v sC|| v sE|dkr)| jd|d dS |dkr4| 	| dS |dkrG| jd|d dS dS dS dS dS )znvisit a Call node -> check if this is not a disallowed builtin
        call and check for * or ** use
        execr  r   reversedevalr  N)
r  r[   rh  r   r   rd   rK  rootr  _check_reversedrf  r(   r(   r)   rj    s   
zBasicChecker.visit_callr  r  c                 C   s   |j du rt|jtjrt|jjdkr| jd|d t|jtjr=t|jj	t
r?|jj	r0d}nd}| jd||fd dS dS dS )	z:check whether assert is used on a tuple or string literal.Nr^  r  r   neveralwaysr  r8  )failr[   r  r   r  r   eltsr  r  r  r1   )r   re   whenr(   r(   r)   visit_assert  s   
zBasicChecker.visit_assertr  c                 C   sN   t  }|jD ]\}}t|tjr$|j}||v r| jd||d || qdS )z!check duplicate key in dictionaryr  r8  N)rR   itemsr[   r   r  r  r  add)r   re   keyskr  keyr(   r(   r)   
visit_dict  s   
zBasicChecker.visit_dictc                 C   s   | j | dS zupdate try...finally flagN)r  r   r   r(   r(   r)   visit_tryfinally  r  zBasicChecker.visit_tryfinallyc                 C   s   | j   dS r.  )r  popr  r(   r(   r)   leave_tryfinally  rQ  zBasicChecker.leave_tryfinallyc                 C   s`   |  }|dur.t|tjr%t|tjr%t|jtjr%|  }|du r%dS | jd|d dS dS )zcheck unreachable codeNr  r   )next_siblingr[   r   r%  Exprr  r  r  )r   re   unreach_stmtr(   r(   r)   r    s   

zBasicChecker._check_unreachabler(   c                 C   sr   | j sdS |j}|}|r3t||s5t|dr%||jv r%| jd||d dS |}|j}|r7t||rdS dS dS dS )zcheck that a node is not inside a finally clause of a
        try...finally statement.
        If we found before a try...finally block a parent which its type is
        in breaker_classes, we skip the whole check.Nrt  r  r8  )r  r\   r[   r   rt  r  )r   re   r<  breaker_classes_parentr}   r(   r(   r)   r    s   z"BasicChecker._check_not_in_finallyc              
   C   s  zt t j|dd}W n t jy   Y dS w |tju rdS |du rZt|jd tj	rXzt
|jd j }W n tjyC   Y dS w t|dddkrXt |rX| jd|d dS t|tjtjfredS t|tjrtdd	 t|jf|j D rz|jt  W dS  ty   | jd|d Y dS w t|d
rtD ]}|D ]}z|| W q tjy   Y  nw  dS q| jd|d dS | jd|d dS )z3check that the argument to `reversed` is a sequencer   )positionNrd   iterr  r   c                 s   s$    | ]}|j d kot|V  qdS )rS   N)rd   r   is_builtin_object)rO   rq  r(   r(   r)   r      s
    
z/BasicChecker._check_reversed.<locals>.<genexpr>rx   )r   r   get_argument_from_callNoSuchArgumentErrorr  r  r[   r!  r   r  r~  rh  r  r  rx   r9  r  r  r  r  rA   r+  r,  _proxiedrm  rc  REVERSED_PROTOCOL_METHODr   r   REVERSED_METHODSNotFoundError)r   re   r!   rh  methodsmethr(   r(   r)   r!    sd   

zBasicChecker._check_reversedr  c                 C   sh   |j }|r0t||dd  D ]#\}}t|d tjr/|d d u r/t|d tjs/| jd|d qd S d S )Nr   r   r  r   )r(  r  r[   r   
AssignNamer  r  )r   re   pairs	prev_pairpairr(   r(   r)   
visit_with  s   zBasicChecker.visit_withc           	      C   s   |  }|j}g }|j}t|d tjr)t|dkrd S |d j}t|dkr)d S t|jtj	r=t|dkr8d S |jg}nt|jtjrZt|jj}t||ksT|dkrVd S |jj}t
||D ].\}}t|tj	sjq_t|tjsqq_t|tjr}|j|v r}q_|j|jkr| jd|jf|d q_d S )Nr   r   r  rE  )r6  rc  r
  r[   r   r  r   r%  r  r   r  rB  r   rd   r  )	r   re   r6  scope_locals	rhs_namesr
  	rhs_counttargetlhs_namer(   r(   r)   _check_self_assigning_variable-  s@   


z+BasicChecker._check_self_assigning_variablec           	      C   s   t j| dd d}|D ]V}t|tjsq
g }|jD ],}t|tjr'| |g qt|tjrD|jdkrD|r>|	|jr>  d S |
|j qt|}| D ]\}}|dkr_| jd|f|d qNq
d S )Nr{  r|  r  r   r  rE  )r   r  r[   r   r  r%  _check_redeclared_assign_namerB  rd   r   r   r'  Countermost_commonr  )	r   r
  r  rJ  found_nameselementrc   rd   countr(   r(   r)   rM  V  s0   

z*BasicChecker._check_redeclared_assign_namer  r  c                 C   s   |  | | |j d S r   )rL  rM  r
  r   r(   r(   r)   r  o  s   
zBasicChecker.visit_assignc                 C   s   |  |jg d S r   )rM  rJ  r   r(   r(   r)   r\  t  r  zBasicChecker.visit_for)r(   )Cr+   r,   r-   r.   r   r   r   rd   r  r   reportsr  r  r   r  r   r  r  IfExpr  Comprehensionr  r  r  r  r   r  r3  r  staticmethodr  r  rr  r  r   r5  r  r  r%  rL  ru  rW  r   rY  Raiser  r  r  rj  Assertr'  r   r-  rs  r/  r1  r  r  r!  WithrF  rL  rM  r  r  rk   r\  r(   r(   r(   r)   r    s    
 (-4<DKT[afkr 


5+

;
(




8)
r  >   r    r   r   r   r   r!   r   r"   r%   r$   r#   r   constantr   r   r   	attributer!   r"   zclass attributezclass constantzinline iterationr   r=   r@   r?   rA   c                  C   s   g } t tD ]>}t| }t| }|dd}| | d|dtt dd| ddf | | d	d d
dd| d| ddf qt	| S )Nr  -z-naming-stylechoicez<style>zNaming style matching correct z names.)r}  r   choicesmetavarhelpz-rgxregexp<regexp>z$Regular expression matching correct z names. Overrides z-naming-style.r}  r   r_  r`  )
sortedKNOWN_NAME_TYPESHUMAN_READABLE_TYPESDEFAULT_NAMING_STYLESreplacer   rT   NAMING_STYLESr*  rq   )name_optionsr'   human_readable_namedefault_styler(   r(   r)   _create_naming_options  s2   

rm  c                   @   s  e Zd Zddddddgifdd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dddd d!dfd"d#dd$d%dffe  Zd&d'd(hiZd)d* Zd+d, Zd-d. Z	e
dd/d0d1ejd2d3fd4d5Zd6ejd2d3fd7d8Ze
dd/d9d0d1ejd2d3fd:d;Ze
dd/d9d0d1ejd2d3fd<d=ZeZe
dd/d0d1ejd2d3fd>d?Ze
dd/d9d0d1ejd2d3fd@dAZdBdC ZdDdE Z	/dVdFee d1ejdGedHedIed2d3fdJdKZdHed2efdLdMZ dHed2efdNdOZ!e"j#fdPdQZ$dRdS Z%e&dTdU Z'd3S )WNameChecker)z"%s name "%s" doesn't conform to %sinvalid-nameziUsed when the name doesn't conform to naming rules associated to its type (constant, variable, class...).zDisallowed name "%s"disallowed-namezMUsed when the name matches bad-names or bad-names-rgxs- (unauthorized names).	old_names)C0102zblacklisted-name)z3%s name "%s" contains a non-ASCII unicode characternon-ascii-namezEUsed when the name contains at least one non-ASCII unicode character.)z*Name %s will become a keyword in Python %sassign-to-new-keywordzaUsed when assignment will become invalid in future Python release due to introducing new keyword.)C0103C0104C0144W0111z
good-names)rx  jr+  exRunr  csvz<names>zJGood variable names which should always be accepted, separated by a comma.rc  zgood-names-rgxs 
regexp_csvziGood variable names regexes, separated by a comma. If names match any regex, they will always be acceptedz	bad-names)foobarbaztototututatazHBad variable names which should always be refused, separated by a comma.zbad-names-rgxszgBad variable names regexes, separated by a comma. If names match any regex, they will always be refusedz
name-groupr(   z<name1:name2>zrColon-delimited sets of names that determine each other's naming style when the name regexes allow several styles.zinclude-naming-hintFynz<y_or_n>z?Include a hint for the correct naming format with invalid-name.zproperty-classes)zabc.abstractpropertyz<decorator names>zList of decorators that produce properties, such as abc.abstractproperty. Add to this list to register other decorators that produce valid properties. These decorators are taken in consideration only for invalid-name.)r      asyncawaitc                 C   sF   t | | i | _i | _i | _i | _i | _g | _g | _t	
d| _d S )Nz[^ -])r   r  _name_category_name_group
_bad_names_name_regexps_name_hints_good_names_rgxs_compiled_bad_names_rgxs_compiledr/   r0   _non_ascii_rgx_compiledr  r(   r(   r)   r  2  s   zNameChecker.__init__c                 C   s   | j jdddddddddddd| _| jjD ]}|dD ]
}d| | j|< qq|  \}}|| _|| _	dd | jj
D | _dd | jjD | _d S )Nr   )badname_modulebadname_classbadname_functionbadname_methodbadname_attrbadname_constbadname_variablebadname_inlinevarbadname_argumentbadname_class_attributebadname_class_const:group_c                 S      g | ]}t |qS r(   r/   r0   rO   rgxpr(   r(   r)   rQ   R      
z$NameChecker.open.<locals>.<listcomp>c                 S   r  r(   r  r  r(   r(   r)   rQ   U  r  )r  r  r   r   
name_groupsplitr  _create_naming_rulesr  r  good_names_rgxsr  bad_names_rgxsr  )r   groupr'   regexpshintsr(   r(   r)   r  =  s4   zNameChecker.openc                 C   s   i }i }t D ]>}| d}t| j|}t| |||< | d}t| j|d }|d ur0|||< |d ur=|jd||< q| d||< q||fS )N_naming_style_rgxz patternz naming style)re  rx   r   ri  r*   pattern)r   r  r  r'   naming_style_option_namenaming_style_namecustom_regex_setting_namecustom_regexr(   r(   r)   r  Y  s   

z NameChecker._create_naming_rulesro  rs  re   r   Nc                 C   s$   |  d|jdd | i | _d S )Nr   rK   r   )_check_namerd   r  r  r   r(   r(   r)   r  o  s   
zNameChecker.visit_moduler  c           
      C   s   | j  D ]d}t|dk rqtt}tj}t|	 dd d\}}| D ]}|t| 
| tt||}q&t|| dkrUt|| dd d}tj|dd   }n|| d }|D ]}	| j|g|	R   q]qd S )Nr^  c                 S   s   t | d S )Nr   )r   )itemr(   r(   r)   <lambda>z  s    z*NameChecker.leave_module.<locals>.<lambda>)r,  r   c                 S   s   t dd | D S )Nc                 s   s    | ]}|d  j V  qdS )r   N)r/  )rO   warningr(   r(   r)   r     s    z=NameChecker.leave_module.<locals>.<lambda>.<locals>.<genexpr>)min)r  r(   r(   r)   r    r  r   )r  r.  r   r'  r(  rT   sysmaxsizemaxr(  r   r  rd  r+  r,  _raise_name_warning)
r   r  
all_groupsgroupsmin_warningsprevalent_groupr  by_linewarningsr!  r(   r(   r)   leave_modulet  s(   
zNameChecker.leave_modulert  c                 C   sV   |  |j| | d|j| |j D ]\}}t||s(| d||d  qd S )Nr   r    r   )&_check_assign_to_new_keyword_violationrd   r  instance_attrsr(  rA   instance_attr_ancestors)r   re   r    anodesr(   r(   r)   r    s   zNameChecker.visit_classdefc                 C   s   |  |j| tj}| r(t|j |jrd S t	|j r%tj
ntj}| t|| jd|j|| |jj}|d urF| || d S d S )N)r   )r  rd   r   HIGHr   r   overrides_a_methodr\   rK  has_known_bases	INFERENCEr   r  r   r   r!  _recursive_check_names)r   re   r   r!  r(   r(   r)   r5    s&   zNameChecker.visit_functiondefc                 C   s   |j D ]	}| d|| qd S )Nr   )rc   r  rf  r(   r(   r)   visit_global  s   
zNameChecker.visit_globalc                 C   s  |  |j| | }| }t|tjr| d|j| d
S t|tjrut|tj	r[tt
|jtjr?| d|j| d
S t|sWtt
|jtjrY| d|j| d
S d
S d
S t|tjrqt
|drs| d|j| d
S d
S d
S t|tjr|j|v r|j| vrt|s| d|j| d
S d
S d
S d
S t|tjrt||js| D ]}|jdkr| jdkst
|dr| d|j|  d
S q| d	|j| d
S d
S d
S )z!check module level assigned namesr%   r   r   Finalr"   Enumenumr$   r#   N)r  rd   rK  assign_typer[   r   rU  r  r  r  r   r   r  r   rj   r  rv  is_assign_name_annotated_withr   argnamesrT   local_attr_ancestorsrm  r   )r   re   rK  r  rq  r(   r(   r)   visit_assignname  sP   



zNameChecker.visit_assignnamec                 C   s:   |D ]}t |tjr| d|j| q| |j| qdS )z.check names in a possibly recursive list <arg>r!   N)r[   r   rB  r  rd   r  r%  )r   r!  re   r3  r(   r(   r)   r    s
   z"NameChecker._recursive_check_namesc                 C   s   | j ||S r   )r  r   )r   r   r(   r(   r)   _find_name_group  s   zNameChecker._find_name_groupr  r   rd   r  c           
      C   s   t | }| j| }|rd| d| }| jjr#|d| j| jd7 }|dkr.| ||fn| |f}	| j|||	|d | jd|   d7  < d S )	Nzthe `z` group in the r  z	 pattern)ro  re   r!  r   r   r   )	rf  r  r   include_naming_hintr  r  
capitalizer  r   )
r   r  re   r   rd   r   r  
type_labelhintr!  r(   r(   r)   r    s   	

zNameChecker._raise_name_warningc                    $    | j jv pt fdd| jD S )Nc                 3       | ]}|  V  qd S r   r   rO   r  r  r(   r)   r         

z5NameChecker._name_allowed_by_regex.<locals>.<genexpr>)r   
good_namesrA   r  r   rd   r(   r  r)   _name_allowed_by_regex     z"NameChecker._name_allowed_by_regexc                    r  )Nc                 3   r  r   r  r  r  r(   r)   r     r  z8NameChecker._name_disallowed_by_regex.<locals>.<genexpr>)r   	bad_namesrA   r  r  r(   r  r)   _name_disallowed_by_regex  r  z%NameChecker._name_disallowed_by_regexc                    s  | j |}|dur| jd| ||dd  fdd}| j|dr#dS | j|dr>| jd    d7  < | jd	||d
 dS | j  }||}t| |rj| 	 }	| j
|	i }
|
|jg }|| ||f |du r}||s| d| || dS dS dS )z(check for a name using the type's regexpNrs  )r  c                    s&    dkrt | }t|tjrdS dS )Nr"   TF)r   r   r[   r   r   )re   r   r   r(   r)    _should_exempt_from_invalid_name  s
   
zANameChecker._check_name.<locals>._should_exempt_from_invalid_namer  r   r   rp  r8  )r  r   r  r  r  r   r  r  r   r  r  
setdefaultr   r   )r   r   rd   re   r   non_ascii_matchr  ra  r   r  bad_name_groupr  r(   r  r)   r    s,   


zNameChecker._check_namec                 C   s6   |  || j}|d ur| jd|||ftjd d S d S )Nrt  r  )_name_became_keyword_in_versionKEYWORD_ONSETr  r   r  )r   rd   re   keyword_first_versionr(   r(   r)   r  1  s   
z2NameChecker._check_assign_to_new_keyword_violationc                 C   s@   |  D ]\}}| |v rtj|k rddd |D   S qd S )NrK   c                 s   s    | ]}t |V  qd S r   )r1   r  r(   r(   r)   r   A  s    z>NameChecker._name_became_keyword_in_version.<locals>.<genexpr>)r(  r  version_inforM   )rd   rulesversionr  r(   r(   r)   r  =  s
   z+NameChecker._name_became_keyword_in_version)ro  )(r+   r,   r-   r  rm  optionsr  r  r  r  r   r  r   r  r  r  r   r  r   r5  r  r9  r  rB  r  r  r  r   r1   NodeNGr  boolr  r  r   r  r  r  rV  r  r(   r(   r(   r)   rn    s    
 
KM'

!rn  c                   @   s   e Zd Zdddddgifddddd	gifd
dddd	gifddddd	gifdZdeddddfddddddffZdd Zeddde	j
dd fd!d"Zeddde	jdd fd#d$Zeddde	jdd fd%d&ZeZd'ejfd(d)Zd S )*DocStringCheckerzEmpty %s docstringempty-docstringz^Used when a module, function, class or method has an empty docstring (it would be too easy ;).rq  )W0132zold-empty-docstringzMissing module docstringmissing-module-docstringzMUsed when a module has no docstring.Empty modules do not require a docstring.)C0111missing-docstringzMissing class docstringmissing-class-docstringzMUsed when a class has no docstring.Even an empty class must have a docstring.z$Missing function or method docstringmissing-function-docstringznUsed when a function or method has no docstring.Some special methods like __init__ do not require a docstring.)C0112C0114C0115C0116zno-docstring-rgxra  rb  zcRegular expression which should only match function or class names that do not require a docstring.rc  zdocstring-min-lengthr   intz<int>z[Minimum line length for functions/classes that require docstrings, shorter ones are exempt.c                 C   s   | j jddddd| _d S )Nr   )undocumented_moduleundocumented_functionundocumented_methodundocumented_class)r  r  r   r  r(   r(   r)   r    s   zDocStringChecker.openr  re   r   Nc                 C   r   )Nr   )_check_docstringr   r(   r(   r)   r    r  zDocStringChecker.visit_modulec                 C   s(   | j j|jd u r| d| d S d S r   )r   no_docstring_rgxr   rd   r  r   r(   r(   r)   r    s   zDocStringChecker.visit_classdefc                 C   s   | j j|jd u rt| rdnd}t|st|st|r d S t|j	
 tjrad}t|j	
 r6tjntj}|j	
  D ]}|j|v rTt||j tjrTd} nq@| j||| |d d S t|j	
 tjrr| || d S d S d S )Nr   r   FT)report_missingr   )r   r  r   rd   r   r   r   r   r[   r\   rK  r   r   r   r  r   r  r   rm  r   r  r  )r   re   ftype
overriddenr   rq  r(   r(   r)   r5    s:   

z"DocStringChecker.visit_functiondefTc           
      C   sX  |j }|du rt|}|du r|sdS t||j }|dkr#|s#dS | jj}|dkr5|dkr5||k r5dS | jd|   d7  < |jrut	|jd t
jrut	|jd jt
jrut|jd jj}t	|tjrut	|jtjru|jjdv rudS |dkr|d}	n	|d	krd
}	nd}	| j|	||d dS | s| jd|   d7  < | jd||f|d dS dS )z(check the node has a non empty docstringNr   r   r   r   r   )r1   unicodebytesr  r   r  r  )re   r   r  r  )doc_infer_dunder_doc_attributer   get_node_last_linenor/  r   docstring_min_lengthr   r  r[   r   r3  r  r  r   rh  r  r  boundr  rd   r  strip)
r   r   re   r  r   	docstringr   	max_linesrh  messager(   r(   r)   r    sJ   

z!DocStringChecker._check_docstring)r+   r,   r-   r  NO_REQUIRED_DOC_RGXr  r  r   r  r   r  r  r   r  r   r5  r  r   r  r  r(   r(   r(   r)   r  E  s^    !


 r  c                   @   s6   e Zd ZdZddiZeddejddfdd	Z	dS )
PassCheckerz/check if the pass statement is really necessaryW0107)zUnnecessary pass statementunnecessary-passz@Used when a "pass" statement that can be avoided is encountered.r  re   r   Nc                 C   sN   t |j|dkst|jtjtjfr#|jjd ur%| jd|d d S d S d S )Nr   r  r   )	r   r\   child_sequencer[   r   r   r   r  r  r   r(   r(   r)   
visit_pass  s   zPassChecker.visit_pass)
r+   r,   r-   r.   r  r   r  r   Passr  r(   r(   r(   r)   r    s    r  c                 C   s"   t | tjot| jdko| j S )zSIs this a call with exactly 1 argument,
    where that argument is positional?
    r   )r[   r   r  r   r!  r  )r   r(   r(   r)   _is_one_arg_pos_call  s   "r  c                 C   sJ   z| d }W n
 t y   Y d S w t|}|sd S t|tjs"d S |jS )Nr.   )r   r   r   r[   r   r  r  )re   r  r(   r(   r)   r    s   
r  c                   @   s   e Zd ZdZdddddddgifd	d
dddZ	d*defddZ	d*defddZdd Zdd Z	de
jfddZdd Zeddddd d!de
jd"d#fd$d%Zd&d' Zd(d) Zd#S )+ComparisonCheckera  Checks for comparisons

    - singleton comparison: 'expr == True', 'expr == False' and 'expr == None'
    - yoda condition: 'const "comp" right' where comp can be '==', '!=', '<',
      '<=', '>' or '>=', and right can be a variable, an attribute, a method or
      a function
    )Comparison %s should be %ssingleton-comparisonzQUsed when an expression is compared to singleton values like True, False or None.)zComparison should be %smisplaced-comparison-constantzUsed when the constant is placed on the left side of a comparison. It is usually clearer in intent to place it in the right hand side of the comparison.z4Use isinstance() rather than type() for a typecheck.unidiomatic-typecheckzThe idiomatic way to perform an explicit typecheck in Python is to use isinstance(x, Y) rather than type(x) == Y, type(x) is Y. Though there are unusual situations where these give different results.rq  )W0154zold-unidiomatic-typecheck)zComparison to literalliteral-comparisonzUsed when comparing an object to a literal, which is usually what you do not want to do, since you can compare to a different literal than what was expected altogether.)zRedundant comparison - %scomparison-with-itselfz/Used when something is compared against itself.)z;Comparing against a callable, did you omit the parenthesis?comparison-with-callablezThis message is emitted when pylint detects that a comparison with a callable was made, which might suggest that some parenthesis were omitted, resulting in potential unwanted behaviour.)r  nan-comparisonzPUsed when an expression is compared to NaNvalues like numpy.NaN and float('nan'))C0121C0122C0123R0123R0124W0143W0177Fchecking_for_absencec              
      s  d dt f fdd}||r|j|}}n||r!|j|}}ndS ddd}|d	v rdd
}	ddd}
ddd	}||u}|	|| | | |t|sS|rSdnd|
| | || }n|| | | }| jd|d|  d|fd dS )z<Check if == or != is being used to compare a singleton value)TFNr   c                    s"   t  tjot fddD S )Nc                 3   s    | ]} j |u V  qd S r   r  )rO   r  r   r(   r)   r   P	  r  z]ComparisonChecker._check_singleton_comparison.<locals>._is_singleton_const.<locals>.<genexpr>)r[   r   r  rA   r   singleton_valuesr   r)   _is_singleton_constO	  s   zJComparisonChecker._check_singleton_comparison.<locals>._is_singleton_constNz
'{} is {}'z'{} is not {}')FT)TFzB{} if checking for the singleton value {}, or {} if testing for {}znot {}rU   
truthiness	falsinessz
'bool({})'z'{}'r  'r8  )r  r  r  r  r   is_test_conditionr  )r   
left_valueright_value	root_noder-  r0  	singletonother_valuesingleton_comparison_examplesuggestion_templatetruthiness_exampletruthiness_phrasechecking_truthiness
suggestionr(   r.  r)   _check_singleton_comparisonI	  sN   



z-ComparisonChecker._check_singleton_comparisonc           	         s   dd  dd dt f fdd}||}|s||sd S d}|r$d	}|r2d
| d|  d}nd
| d|  d}| jd|d
|  d
|fd d S )Nc                 S   sd   z't | tjr%t| jdkr%| jd j dkr%|  d  dkr%W dS W dS  t	y1   Y dS w )Nr   r   nanzbuiltins.floatTF)
r[   r   r  r   r!  r  lowerr   r  AttributeErrorr   r(   r(   r)   _is_float_nan	  s   z>ComparisonChecker._check_nan_comparison.<locals>._is_float_nanc                 S   s4   t | tjr| jdkrt | jtjr| jjdv S dS )NNaN)numpynmpnpF)r[   r   r   r   r   r   rd   r   r(   r(   r)   _is_numpy_nan	  s   z>ComparisonChecker._check_nan_comparison.<locals>._is_numpy_nanr   c                    s    | p| S r   r(   r   rD  rI  r(   r)   _is_nan	  s   z8ComparisonChecker._check_nan_comparison.<locals>._is_nanr}  znot r3  zmath.isnan(z)'r%  r8  )r  r  r  )	r   r5  r6  r7  r-  rK  nan_leftabsence_textr?  r(   rJ  r)   _check_nan_comparison	  s"   
z'ComparisonChecker._check_nan_comparisonc                 C   sv   t |tjtjtjtjf}d}t |tjr,t |jts |jdu r"dS t |jt	t
ttf}|s0|r9| jd|d dS dS )zMCheck if we compare to a literal, which is usually what we do not want to do.FNr"  r   )r[   r   r  r  r   r  r  r  r  r
  r1   r  floatr  )r   literalre   is_other_literalis_constr(   r(   r)   _check_literal_comparison	  s   z+ComparisonChecker._check_literal_comparisonc                 C   sL   t |tjrd S t||}|  d| d|j}| jd||fd d S )N r  r8  )r[   r   r  REVERSED_COMPSr   r  r  r  )r   re   r  rightoperatorr?  r(   r(   r)   _check_misplaced_constant	  s
   z+ComparisonChecker._check_misplaced_constantre   c                 C   s   |j }|jd d }|jd d }t|tjr$t|tjr$|j}|j}nt|tjr6t|tjr6|j}|j}||krO| d| d| }| jd||fd dS dS )zCheck if identifier is compared against itself.
        :param node: Compare node
        :Example:
        val = 786
        if val == val:  # [comparison-with-itself]
            pass
        r   r   rT  r#  r8  N)	r  r  r[   r   r  r  r   rd   r  )r   re   left_operandright_operandrW  r?  r(   r(   r)   _check_logical_tautology	  s"   z*ComparisonChecker._check_logical_tautologyc                    sp   |j d d }|tvrd S tjtjf |j|j d d }}t fdd||fD dkr6| jd|d d S d S )Nr   r   c                 3   s$    | ]}t t| rd V  qdS )r   N)r[   r   r   )rO   r`  bare_callablesr(   r)   r   	  s    
z?ComparisonChecker._check_callable_comparison.<locals>.<genexpr>r$  r   )	r  COMPARISON_OPERATORSr   r   r  r  r  sumr  )r   re   rW  rY  rZ  r(   r\  r)   _check_callable_comparison	  s   z,ComparisonChecker._check_callable_comparisonr  r  r"  r#  r$  r   Nc                 C   s   |  | | | | | t|jdkrd S |j}|jd \}}|tv r4t|tj	r4| 
|||| |dv rC| j||||dkd |dv rR| j||||dv d |dv r^| || d S d S )	Nr   r   )rG   rH   rH   )r-  )rG   rH   rE   rF   )rH   rF   rE   rF   )r`  r[  _check_unidiomatic_typecheckr   r  r  r^  r[   r   r  rX  r@  rN  rS  )r   re   r  rW  rV  r(   r(   r)   visit_compare	  s(   
	

zComparisonChecker.visit_comparec                 C   s@   |j d \}}|tv r|j}t|r| |||| d S d S d S )Nr   )r  TYPECHECK_COMPARISON_OPERATORSr  r  _check_type_x_is_y)r   re   rW  rV  r  r(   r(   r)   rb  
  s   z.ComparisonChecker._check_unidiomatic_typecheckc                 C   s   t |j}t|tjr| tksdS |dv r=t|r=t |j}t|tjr=| tkr=t |j	d }t|t
s=dS | jd|d dS )z(Check for expressions like type(x) == Y.Nra  r   r   r   )r   r   rh  r[   r   r   r   
TYPE_QNAMEr  r!  LITERAL_NODE_TYPESr  )r   re   r  rW  rV  	left_func
right_func	right_argr(   r(   r)   re  
  s   


z$ComparisonChecker._check_type_x_is_y)F)r+   r,   r-   r.   r  r  r@  rN  rS  rX  r   r  r[  r`  r   r  rc  rb  re  r(   r(   r(   r)   r  	  sJ    		3
;
)r  c                 C   sX   |  t|  |  t|  |  t|  |  t|  |  t|  |  t|  dS )z-required method to auto register this checkerN)register_checkerr   r  rn  r  r  r  )r  r(   r(   r)   register.
  s   rl  r   )Wr.   r'  r+  r/   r  typingr   r   r   r   r   r   r  r   pylintr	   r
   r   r   r   pylint.checkerspylint.checkers.utilsr   r   r   r   pylint.reporters.ureportsr   pylint.typingr   r   r5   r7   r:   r;   r<   ri  r0   r  r=  SEQUENCE_PROTOCOL_METHODSr>  	frozensetrd  r  r  r  rg  UNITTEST_CASErf  rn  r   rS   r  r  rU  r^  r  r  rj   rp   rr   r{   r   r   r   r   r   r   r   r   r   BaseCheckerr   r   r  re  rf  rg  rm  rn  r  r  r  r  r  rl  r(   r(   r(   r)   <module>   s   A 
	
	%

3   b     L        "