Your IP : 216.73.217.111


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pylint/checkers/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pylint/checkers/__pycache__/base.cpython-37.pyc

B

mJv\�K�@s
dZddlZddlZddlZddlZddlZddlmZddlZddl	Zddl
ZddlmZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZGdd�d�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zeeeeed�Ze� d�Z!dZ"dZ#e#e"ffZ$e%d�Z&ej'ej(ej)ej*fZ+dZ,ej-Z.de.Z/ej0dkZ1ej0dkZ2ej0d kZ3d!d"hZ4d#d$hZ5e6e7d%d&�d'D�d(d)d*g��Z8d+d,d-d.d/�Z9e%d0�Z:e%d1�Z;d2d3�Z<d4d5�Z=d6d7�Z>d8d9�Z?d:d;�Z@d<d=�ZAd>ZBd?d@�ZCdpdAdB�ZDdCdD�ZEdEdF�ZFdGdH�ZGGdIdJ�dJejH�ZIGdKdL�dLeI�ZJGdMdN�dNeI�ZKdOdPdQdRdSdTdUdVdWdXh
ZLdOdYdQdRdSdZdUdVd[d\d]�
ZMd^d_d`d^d^d^d^d^dadad]�
ZNdbdc�ZOGddde�deeI�ZPGdfdg�dgeI�ZQGdhdi�dieI�ZRdjdk�ZSGdldm�dmeI�ZTdndo�ZUdS)qzbasic checker for Python code�N)�Pattern)�checkers)�
exceptions)�
interfaces)�utils)�	reporters)�get_node_last_lineno)�nodesc@s0eZdZdZdZdZdZdZdZe	dd��Z
dS)�NamingStyleNcCs2|j|j|j|j|j|j|j|j|j|jd�
|S)N)
�module�const�class�function�method�attr�argument�variable�class_attribute�	inlinevar)�MOD_NAME_RGX�CONST_NAME_RGX�CLASS_NAME_RGX�DEFAULT_NAME_RGX�CLASS_ATTRIBUTE_RGX�COMP_VAR_RGX)�cls�	name_type�r�E/opt/alt/python37/lib/python3.7/site-packages/pylint/checkers/base.py�	get_regexIszNamingStyle.get_regex)�__name__�
__module__�__qualname__rrrrrr�classmethodrrrrrr
=sr
c@sLeZdZdZe�d�Ze�d�Ze�d�Ze�d�Z	e�d�Z
e�d�ZdS)	�SnakeCaseStylez(Regex rules for snake_case naming style.z[a-z_][a-z0-9_]+$z([a-z_][a-z0-9_]*)$z(([a-z_][a-z0-9_]*)|(__.*__))$z[a-z_][a-z0-9_]*$z<(([a-z_][a-z0-9_]{2,})|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$z!(([a-z_][a-z0-9_]{2,}|(__.*__)))$N)r r!r"�__doc__�re�compilerrrrrrrrrrr$Ys



r$c@sLeZdZdZe�d�Ze�d�Ze�d�Ze�d�Z	e�d�Z
e�d�ZdS)	�CamelCaseStylez'Regex rules for camelCase naming style.z[a-z_][a-zA-Z0-9]+$z([a-z_][a-zA-Z0-9]*)$z (([a-z_][A-Za-z0-9]*)|(__.*__))$z[a-z_][A-Za-z0-9]*$z3(([a-z_][a-zA-Z0-9]{2,})|(__[a-z][a-zA-Z0-9_]+__))$z!([a-z_][A-Za-z0-9]{2,}|(__.*__))$N)r r!r"r%r&r'rrrrrrrrrrr(fs




r(c@sLeZdZdZe�d�Ze�d�Ze�d�Ze�d�Z	e�d�Z
e�d�ZdS)�PascalCaseStylez(Regex rules for PascalCase naming style.z[A-Z_][a-zA-Z0-9]+$z (([A-Z_][A-Za-z0-9]*)|(__.*__))$z0[A-Z_][a-zA-Z0-9]{2,}$|(__[a-z][a-zA-Z0-9_]+__)$z[A-Z_][a-zA-Z0-9]{2,}$N)r r!r"r%r&r'rrrrrrrrrrr)qs




r)c@sLeZdZdZe�d�Ze�d�Ze�d�Ze�d�Z	e�d�Z
e�d�ZdS)�UpperCaseStylez(Regex rules for UPPER_CASE naming style.z[A-Z_][A-Z0-9_]+$z(([A-Z_][A-Z0-9_]*)|(__.*__))$z/([A-Z_][A-Z0-9_]{2,})|(__[a-z][a-zA-Z0-9_]+__)$z[A-Z_][A-Z0-9_]{2,}$N)r r!r"r%r&r'rrrrrrrrrrr*|s




r*c@seZdZedd��ZdS)�AnyStylecCs
t�d�S)Nz.*)r&r')rrrrrr�szAnyStyle.get_regexN)r r!r"r#rrrrrr+�sr+)�
snake_caseZ	camelCase�
PascalCase�
UPPER_CASE�anyz^_�__reversed__)�__getitem__�__len__)�iszis notz==z!=�inznot inz
unittest.casez%s.type)�r5)r5r)r5�z_py_abc.ABCMetazabc.ABCMetaZexempt�ignorecCsg|]}d�t|g��qS)�.)�join�BUILTINS)�.0�xrrr�
<listcomp>�sr=)�set�dict�listzset()z{}z[]�>z>=�<z<=)rBz<=rAz>=)z==z!=rBrAz<=z>=)r!cCs�|}x|r t|jtj�s |j}qW|r4t�|jt�s8dS|jj}xP|�tjtj	f�D]:}x4|j
D]*\}}|r|||jkr�dSq`||jkr`dSq`WqTWdS)z� Detect 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�parent�astroid�
ExceptHandlerrZ
error_of_type�ImportError�nodes_of_classZ
ImportFromZImport�names�name)�node�currentZ	try_blockZimport_noderJ�aliasrrr�_redefines_import�s


rNcCs@|j}x4|dk	r:t|tjtjtjtjtjf�r2dS|j}qWdS)z4return True if the node is inside a kind of for loopNTF)rDrCrE�ForZListCompZSetCompZDictComp�GeneratorExp)rKrDrrr�in_loop�s


rQcCs<x6|D].}t|ttf�r(t||�r4dSq||krdSqWdS)zUreturn true if the object is an element of <nested_list> or of a nested
    list
    TF)rCr@�tuple�in_nested_list)Znested_list�objZelmtrrrrS�s

rScCsJtjtjf}|j}x2t||�r.|t|dg�krD|}|j}|dkrPqW|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)rErO�WhilerDrC�getattr)Z
break_node�
loop_nodesrDrrr�_get_break_loop_node�s
rYcsVtjtjf}tjtjf}�fdd��j||d�D��t�fdd��jtj|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.
    csg|]}|�kr|�qSrr)r;�_node)�looprrr=
sz%_loop_exits_early.<locals>.<listcomp>)�
skip_klassc3s|]}t|��kr|VqdS)N)rY)r;rZ)�inner_loop_nodesrr�	<genexpr>sz$_loop_exits_early.<locals>.<genexpr>)rErOrV�FunctionDef�ClassDefrHr/ZBreak)r[rXZdefinition_nodesr)r]r[r�_loop_exits_earlys


racCs.|dk	o,|jdk	o,|jtko,|dkp,|tjkS)Nr)�	lastgroup�EXEMPT_NAME_CATEGORIESr�INFERENCE_FAILURE)�match�	node_type�
confidencerrr�_is_multi_naming_matchs

rhzbuiltins.propertycCs>th}t�}|dk	r6|�|j�|�dd�|jD��||fS)z�Returns 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'.
    Ncss|]}|�dd�dVqdS)r8����N)�rsplit)r;Zproprrrr^/sz"_get_properties.<locals>.<genexpr>)�BUILTIN_PROPERTYr>�update�property_classes)�configrn�property_namesrrr�_get_properties$srqcCs�t|�\}}|��sdS|jr(|jj}ng}xh|D]`}t|tj�sXt|tj�rx|j|krxt	�
|�}|r�|��|kr�dSq2t|tj�r2|jdkr2dSq2WdS)a\Determine the name type whose regex the a function's name should match.

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

    :returns: One of ('function', 'method', 'attr')
    :rtype: str
    rr)�setter�deleterr)rq�	is_method�
decoratorsr	rCrE�Name�	Attribute�attrnamer�
safe_infer�qname)rKrornrpru�	decorator�inferedrrr�_determine_function_name_type4s"



r}cCstt�|��dkS)z�
    Determine if the given `node` has abstract methods.

    The methods should be made abstract by decorating them
    with `abc` decorators.
    r)�lenrZunimplemented_abstract_methods)rKrrr�_has_abstract_methodsZsrcCs|i}x�dD]�}y||}Wntk
r6t���YnXi||<|dkr
y0||d|}|d|}d|||d<Wn tk
r�d||d<YnXy(|d|d|}d|||d	<Wq
tk
r�d||d	<Yq
Xq
Wd
}xtdD]l}||}	|�|d�}
|
dk	�r"t�|
|	�}nd\}
}||t|	�t|
�|||�dd
�||�d	d
�f7}q�W|�tj	|ddd��dS)zymake a report of

    * percentage of different types documented
    * percentage of different types with a bad name
    )rr
rrr�
undocumented_gY@z%.2fZpercent_documented�NC�badname_Zpercent_badname)�type�numberz
old number�
differencez%documentedz%badnameN)r�r��0�ri)�children�colsZrheaders)
�KeyErrorrZEmptyReportError�getrZdiff_string�str�append�reporter_nodesZTable)�sect�statsZ	old_statsZ
nice_statsrf�totalZ
documented�percent�lines�new�oldZdiff_strrrr�report_by_type_statsdsD


r�cCs@|jr<x4|jjD](}t|tj�rt|jdd�|jkrdSqWdS)z�return 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
    rJNTF)rur	rCrErwrW�exprrJ)rKr{rrr�redefined_by_decorator�s	r�c@seZdZejZdZdS)�
_BasicChecker�basicN)r r!r"r�IAstroidChecker�__implements__rJrrrrr��sr�c@s�eZdZddddddddd	d
difdd
dddddddddddddifd�Ze�d�dd��Zdd �Ze�d!d"�d#d$��Ze�d%�d&d'��Z	e�d(d)ddd*d+d�d,d-��Z
e
Zd.d/�Zd0d1�Z
e�d2�d3d4��Ze�d5�d6d7��Ze�d5�d8d9��Ze�d:d;�d<d=��Ze�d:�d>d?��Ze�d@�dAdB��Ze�d@�dCdD��Ze�dE�dFdG��ZdHdI�Ze�dJ�dKdL��Ze�dM�dNdO��ZdPdQ�ZdRdS�ZdTdU�ZdVdW�ZdXdY�ZdZS)[�BasicErrorChecker)z__init__ method is a generatorzinit-is-generatorz^Used when the special class method __init__ is turned into a generator by a yield in its body.)zExplicit return in __init__zreturn-in-initzIUsed when the special class method __init__ has an explicit return value.)z%s already defined line %szfunction-redefinedz3Used when a function / class / method is redefined.)z%r not properly in loopznot-in-loopz=Used when break or continue keywords are used outside a loop.)zReturn outside functionzreturn-outside-functionzEUsed when a "return" statement is found outside a function or method.)zYield outside functionzyield-outside-functionzDUsed when a "yield" statement is found outside a function or method.z%Return with argument inside generatorzreturn-arg-in-generatorz�Used when a "return" statement with an argument is found outside in a generator function or method (e.g. with some "yield" statements).Z
maxversion)r5r5)z#Use of the non-existent %s operatorznonexistent-operatorzzUsed when you attempt to use the C-style pre-increment or pre-decrement operator -- and ++, which doesn't exist in Python.)z1Duplicate argument name %s in function definitionzduplicate-argument-namezCDuplicate argument names in function definitions are syntax errors.)z4Abstract class %r with abstract methods instantiatedzabstract-class-instantiatedzeUsed when an abstract class with `abc.ABCMeta` as metaclass has abstract methods and is instantiated.)z-Else clause on loop without a break statementzuseless-else-on-loopz�Loops 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.)z.More than one starred expression in assignmentztoo-many-star-expressionszhEmitted when there are more than one starred expressions (`*x`) in an assignment. This is a SyntaxError.)z4Starred assignment target must be in a list or tuplezinvalid-star-assignment-targetzFEmitted when a star expression is used as a starred assignment target.)z4Can use starred expression only in assignment targetzstar-needs-assignment-targetzCEmitted when a star expression is not used in an assignment target.)zName %r is nonlocal and globalznonlocal-and-globalz0Emitted when a name is both nonlocal and global.)z0'continue' not supported inside 'finally' clausezcontinue-in-finallyz]Emitted when the `continue` keyword is found inside a finally clause, which is a SyntaxError.)z&nonlocal name %s found without bindingznonlocal-without-bindingz^Emitted when a nonlocal variable does not have an attached name somewhere in the parent scopesz+Name %r is used prior to global declarationzused-prior-global-declarationzcEmitted when a name is used prior a global declaration, which results in an error since Python 3.6.Z
minversion)r5r�)ZE0100ZE0101ZE0102ZE0103ZE0104ZE0105ZE0106ZE0107ZE0108ZE0110ZW0120ZE0112ZE0113ZE0114ZE0115ZE0116ZE0117ZE0118zfunction-redefinedcCs|�d|�dS)Nr
)�_check_redefinition)�selfrKrrr�visit_classdefsz BasicErrorChecker.visit_classdefcCsHd}x:|��D].}t|tj�r(|�|�St|tj�r|d7}qW|dkS)Nrri)ZiteredrCrE�Tuple�_too_many_starred_for_tuple�Starred)r�Zassign_tupleZ
starred_count�elemrrrr�s
z-BasicErrorChecker._too_many_starred_for_tupleztoo-many-star-expressionszinvalid-star-assignment-targetcCsV|jd}t|jdtj�r*|jd|d�t|tj�s:dS|�|�rR|jd|d�dS)Nrzinvalid-star-assignment-target)rKztoo-many-star-expressions)�targetsrCrEr��add_messager�r�)r�rKZ
assign_targetrrr�visit_assign"s

zBasicErrorChecker.visit_assignzstar-needs-assignment-targetcCsvt|jtj�rdStr6t|jtjtjtjtjf�r6dS|�	�}t|tj
�sNdS|j|ksd|j�|�rr|j
d|d�dS)z@Check that a Starred expression is used in an assignment target.Nzstar-needs-assignment-target)rK)rCrDrE�Call�PY35�Listr��Set�DictZ	statement�Assign�valueZ	parent_ofr�)r�rKZstmtrrr�
visit_starred/szBasicErrorChecker.visit_starredzinit-is-generatorzreturn-in-initzduplicate-argument-nameznonlocal-and-globalc
Cs�|�|�|�|�t|�s>t�|�s>|�|��r6dp8d|�|jtj	tj
tjfd�}|��r�|jdkr�|�
�r�|jd|d�q�dd�|D�}td	d
�|D��r�|jd|d�nF|�
�r�ts�x8|D]0}t|jtj�r�|jjdk	r�|jd||jd
�q�Wt�t�}td|jj|jjg�}x&tj�|�D]}||j�|��q$WxH|��D]<}t |�dk�rHx&|D]}	|jd|	j!|	|	jfd��q`W�qHWdS)Nrr)r\�__init__zinit-is-generator)rKcSsg|]
}|j�qSr)r�)r;�rrrrr=[sz7BasicErrorChecker.visit_functiondef.<locals>.<listcomp>css|]}t�|�s|VqdS)N)rZis_none)r;�vrrrr^]sz6BasicErrorChecker.visit_functiondef.<locals>.<genexpr>zreturn-in-initzreturn-arg-in-generator)rK�linerizduplicate-argument-name)r�rK�args)"�_check_nonlocal_and_global�_check_name_used_prior_globalr�rZ(is_registered_in_singledispatch_functionr�rtrHrEZReturnr_r`rJZis_generatorr�r/�PY33rCr��Const�
fromlineno�collections�defaultdictr@�filterr��
kwonlyargs�	itertools�chain�
from_iterabler��valuesr~�lineno)
r�rKZreturnsr�ZretnodeZarg_clusters�	arguments�argZargument_duplicatesrrrr�visit_functiondefCsF






z#BasicErrorChecker.visit_functiondefcs��fdd���tj�D�}|s"dSx^��tj�D]N}|���k	rBq0|j}|�|�}|sXq0|j}|r0||jkr0|jd||fd�q0WdS)Ncs*i|]"}|jD]}|���kr||�qqSr)rI�scope)r;�childrJ)rKrr�
<dictcomp>�s
zCBasicErrorChecker._check_name_used_prior_global.<locals>.<dictcomp>zused-prior-global-declaration)rKr�)	rHrE�Globalrvr�rJr�r�r�)r�rKZ
scope_globals�	node_namerJZcorresponding_globalZ
global_linenor)rKrr��s

z/BasicErrorChecker._check_name_used_prior_globalcs��fdd��tjj}t|�fdd���tj�D���}|s>dSt|�fdd���tj�D���}x$|�|�D]}|j	d|f�d�qlWdS)	z.Check that a name is both nonlocal and global.cs|���kS)N)r�)rL)rKrr�
same_scope�sz@BasicErrorChecker._check_nonlocal_and_global.<locals>.same_scopec3s|]}�|�r|jVqdS)N)rI)r;r�)r�rrr^�sz?BasicErrorChecker._check_nonlocal_and_global.<locals>.<genexpr>Nc3s|]}�|�r|jVqdS)N)rI)r;r�)r�rrr^�sznonlocal-and-global)r�rK)
r�r�r�r>rHrEZNonlocalr��intersectionr�)r�rKZ	from_iter�	nonlocals�global_varsrJr)rKr�rr��s

z,BasicErrorChecker._check_nonlocal_and_globalzreturn-outside-functioncCs"t|��tj�s|jd|d�dS)Nzreturn-outside-function)rK)rC�framerEr_r�)r�rKrrr�visit_return�szBasicErrorChecker.visit_returnzyield-outside-functioncCs|�|�dS)N)�_check_yield_outside_func)r�rKrrr�visit_yield�szBasicErrorChecker.visit_yieldcCs|�|�dS)N)r�)r�rKrrr�visit_yieldfrom�sz!BasicErrorChecker.visit_yieldfromznot-in-loopzcontinue-in-finallycCs|�|d�dS)N�continue)�_check_in_loop)r�rKrrr�visit_continue�sz BasicErrorChecker.visit_continuecCs|�|d�dS)N�break)r�)r�rKrrr�visit_break�szBasicErrorChecker.visit_breakzuseless-else-on-loopcCs|�|�dS)N)�_check_else_on_loop)r�rKrrr�	visit_for�szBasicErrorChecker.visit_forcCs|�|�dS)N)r�)r�rKrrr�visit_while�szBasicErrorChecker.visit_whileznonexistent-operatorcCs@|jdkr<t|jtj�r<|jj|jkr<|jd||jdd�dS)z9check use of the non-existent ++ and -- operator operatorz+-znonexistent-operator�)rKr�N)�oprC�operandrE�UnaryOpr�)r�rKrrr�
visit_unaryop�s
zBasicErrorChecker.visit_unaryopcCsz|��}xN|jdkrPt|tjtjf�s>|jd|f|d�dS||jkrT|j��}q
dSt|tj�sv|jd|f|d�dS)Nznonlocal-without-binding)r�rK)r�rDrCrEr`r_r��locals)r�rKrJZ
current_scoperrr�_check_nonlocal_without_binding�s


z1BasicErrorChecker._check_nonlocal_without_bindingznonlocal-without-bindingcCs x|jD]}|�||�qWdS)N)rIr�)r�rKrJrrr�visit_nonlocal�sz BasicErrorChecker.visit_nonlocalzabstract-class-instantiatedcCs@y$x|j��D]}|�||�qWWntjk
r:dSXdS)zS Check instantiating abstract class with
        abc.ABCMeta as metaclass.
        N)�func�infer�!_check_inferred_class_is_abstractrE�InferenceError)r�rK�inferredrrr�
visit_call�s
zBasicErrorChecker.visit_callcCs�t|tj�sdSt�|�}||kr&dSt|�}|s6dS|��}|dkr~x2|��D]&}|��dkrP|j	d|j
f|d�PqPWdS|��tkr�|j	d|j
f|d�dS)Nzabc.ABCzabstract-class-instantiated)r�rK)rCrEr`rZnode_frame_classr�	metaclass�	ancestorsrzr�rJ�ABC_METACLASSES)r�r|rK�klassZabstract_methodsr��ancestorrrrr�s&
z3BasicErrorChecker._check_inferred_class_is_abstractcCs(t|��tjtjf�s$|jd|d�dS)Nzyield-outside-function)rK)rCr�rEr_�Lambdar�)r�rKrrrr�'sz+BasicErrorChecker._check_yield_outside_funccCs.|jr*t|�s*|jd||jdjdd�dS)z>Check that any loop with an else clause has a break statement.zuseless-else-on-looprri)rKr�N)rUrar�r�)r�rKrrrr�+s
z%BasicErrorChecker._check_else_on_loopcCs�|j}xr|rxt|tjtjf�r,||jkr,dSt|tjtjf�r@Pt|tj�rp||j	krpt|tj
�rp|jd|d�|j}qW|jd||d�dS)z/check that a node is inside a for or while loopNzcontinue-in-finally)rKznot-in-loop)rKr�)rDrCrErOrVrUr`r_Z
TryFinally�	finalbody�Continuer�)r�rKr�rZrrrr�7s


z BasicErrorChecker._check_in_loopcCs�|j��}||j}||k	r|t�||�s|t|tj�rB|jtkrBdStj	|ddd�}|rf|�
|j�rfdS|jd|||jfd�dS)z:check for redefinition of a function / method / class nameNzdummy-variables-rgx)�defaultzfunction-redefined)rKr�)
rDr�rJrEZ
are_exclusiverCr`�REDEFINABLE_METHODS�
lint_utilsZget_global_optionrer�r�)r�Z	redeftyperKZparent_frameZdefined_selfZdummy_variables_rgxrrrr�Ls


z%BasicErrorChecker._check_redefinitionN)r r!r"�msgsr�check_messagesr�r�r�r�r��visit_asyncfunctiondefr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��sn	
4
%r�c@s�eZdZdZejZdZddddddd	d
ddd
ddddd�Zdde	ffZ
dd�Zdd�Ze
�d�dd��Ze
�d�dd��Ze
�d�dd��Zd d!�Zd"d#�Zd$d%�Ze
�d&d'd(�d)d*��Zed+d,��Zed-d.��Ze
�d/�d0d1��Ze
�d2�d3d4��ZeZd5d6�Ze
�d7d8�d9d:��Ze
�d7�d;d<��Ze
�d7d8�d=d>��Ze
�d7�d?d@��Z e
�dA�dBdC��Z!dDdE�Z"e
�dFdAdGdH�dIdJ��Z#e
�dK�dLdM��Z$e
�dN�dOdP��Z%dQdR�Z&dSdT�Z'dUdV�Z(d`dXdY�Z)dZd[�Z*e
�d\�d]d^��Z+d_S)a�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�)zUnreachable code�unreachablezbUsed when there is some code behind a "return" or "raise" statement, which will never be accessed.)z&Dangerous default value %s as argumentzdangerous-default-valuez_Used when a mutable value as list or dictionary is detected in a default value for an argument.)z!Statement seems to have no effectzpointless-statementzEUsed when a statement doesn't have (or at least seems to) any effect.)zString statement has no effectzpointless-string-statementz�Used 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.)z&Expression "%s" is assigned to nothingzexpression-not-assignedzqUsed when an expression that is not a function call is assigned to nothing. Probably something else was intended.)zLambda may not be necessaryzunnecessary-lambdaz�Used 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.)zDuplicate key %r in dictionaryz
duplicate-keyzDUsed when a dictionary expression binds the same key multiple times.)zUse of execz	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 !)zUse of evalz	eval-usedz�Used 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. )z3%s statement in finally block may swallow exceptionzlost-exceptionz�Used 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.)z5Assert called on a 2-uple. Did you mean 'assert x,y'?zassert-on-tuplezA 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.)z?Following "as" with another context manager looks like a tuple.zconfusing-with-statementa2Emitted 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.)z3Using a conditional statement with a constant valuezusing-constant-testz�Emitted 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.)z/The first reversed() argument is not a sequencezbad-reversed-sequencez�Used 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 strzmisplaced-format-functionz�Emitted 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.)ZW0101ZW0102ZW0104ZW0105ZW0106ZW0108ZW0109ZW0122ZW0123ZW0150ZW0199ZW0124ZW0125ZE0111ZE0119ZRP0101zStatistics by typecCst�||�d|_d|_dS)N)r�r�r��_tryfinallys)r��linterrrrr��szBasicChecker.__init__cCs g|_|jjddddd�|_dS)z2initialize visit variables and statistics
        r)rrr�class_N)r�r��	add_statsr�)r�rrr�open�szBasicChecker.openzusing-constant-testcCs|�||j�dS)N)�_check_using_constant_test�test)r�rKrrr�visit_if�szBasicChecker.visit_ifcCs|�||j�dS)N)r�r)r�rKrrr�visit_ifexp�szBasicChecker.visit_ifexpcCs&|jr"x|jD]}|�||�qWdS)N)Zifsr�)r�rKZif_testrrr�visit_comprehension�sz BasicChecker.visit_comprehensionc	Cs�tjtjjtjtjtjtjjtj	tj
tjf	}tjtjtj
f}tjtjtjtjtjtjf}d}t|tjf||�}t||�s�t�|�}|s�t||�r�|jd|d�dS)Nzusing-constant-test)rK)rE�ModuleZscoped_nodesrPr�r_r`�bases�	GeneratorZ
UnboundMethod�BoundMethodr�r�r�rwr�ZBinOpZBoolOpr�Z	SubscriptrCr�rryr�)r�rKrZconst_nodes�structsZexcept_nodesr��emitrrrr��s,	

z'BasicChecker._check_using_constant_testcCs|jdd7<dS)z<check module name, docstring and required arguments
        rriN)r�)r��_rrr�visit_moduleszBasicChecker.visit_modulecCs|jdd7<dS)zWcheck module name, docstring and redefinition
        increment branch counter
        r
riN)r�)r�rKrrrr�$szBasicChecker.visit_classdefzpointless-statementzpointless-string-statementzexpression-not-assignedcCs
|j}t|tj�r�t|jt�r�|��}t|tjtjtjf�r�t|tj�rT|j	dkrTn2|�
�}|dk	r�|��|kr�t|tjtjf�r�dS|j
d|d�dSt|tjtjtjtjf�s�t|jtj�r�|jj|gkr�dSt|�tj��r�|j
d||��d�n|j
d|d�dS)z3check for various kind of statements without effectr�Nzpointless-string-statement)rKzexpression-not-assigned)rKr�zpointless-statement)r�rCrEr�r�r�r`rr_rJZprevious_siblingr�Z	AnnAssignr�ZYieldZAwait�Ellipsisr�rDZ	TryExcept�bodyr/rH�	as_string)r�rKr�r�Zsiblingrrr�
visit_expr*s,	zBasicChecker.visit_exprccsJxD|D]<}t|tj�r<t|jtj�rB|jj|jjkrB|Vq|VqWdS)N)rCrEr�r�rvrJr��vararg)rK�	call_argsr�rrr�_filter_varargZs
zBasicChecker._filter_varargcCs>|sdSx0|D](}t|jtj�r2|jj|kr6dSqdSqWdS)NTF)rCr�rErvrJ)r�Z
variadic_namer�rrr�_has_variadic_argumenths
z#BasicChecker._has_variadic_argumentzunnecessary-lambdacCs"|jjrdS|j}t|tj�s"dSt|jjtj�rHt|jjjtj�rHdSt	|jj�}t	|�
||j��}|jjr�|�|j
|jj�r�dSn|j
s�|jr�dS|jjr�|�|j|jj�r�dSn
|jr�dSt|�t|�kr�dSx6t||�D](\}}t|tj�s�dS|j|jkr�dSq�W|jd|j|d�dS)z6check whether or not the lambda is suspicious
        Nzunnecessary-lambda)r�rK)r��defaultsr
rCrEr�r�rwr�r@r�kwargr�kwargs�keywordsrZstarargsr~�ziprvrJr�r�)r�rK�callZ
ordinary_argsZ
new_call_argsr�Z
passed_argrrr�visit_lambdats8zBasicChecker.visit_lambdazdangerous-default-valuecCs,|j|��rdpdd7<|�|�dS)zdcheck function name, docstring, arguments, redefinition,
        variable names, max locals
        rrriN)r�rt�_check_dangerous_default)r�rKrrrr��szBasicChecker.visit_functiondefc	Cs�dd�}x�|jjD]�}yt|���}Wntjk
r>wYnXt|tj�r|��t	kr||krnt	|��}ntt|tj�s�||�r�||�r�|�
�}q�t|tj�r�d|j|��f}q�d|�
�|��f}nd|�
�t	|��f}|jd||fd�qWdS)NcSst|tjtjtjf�S)N)rCrEr�r�r�)�nrrr�<lambda>��z7BasicChecker._check_dangerous_default.<locals>.<lambda>z	%s() (%s)z%s (%s)zdangerous-default-value)rKr�)r�r�nextr�rEr�rC�Instancerz�DEFAULT_ARGUMENT_SYMBOLSZpytyper�rJrr�)r�rKZis_iterabler�r��msgrrrr�s(
z%BasicChecker._check_dangerous_defaultr�zlost-exceptioncCs |�|�|�|dtjf�dS)z�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
        �returnN)�_check_unreachable�_check_not_in_finallyrEr_)r�rKrrrr��s
zBasicChecker.visit_returncCs|�|�dS)z\check is the node has a right sibling (if so, that's some unreachable
        code)
        N)r$)r�rKrrrr��szBasicChecker.visit_continuecCs$|�|�|�|dtjtjf�dS)z�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)r$r%rErOrV)r�rKrrrr��s
zBasicChecker.visit_breakcCs|�|�dS)z\check if the node has a right sibling (if so, that's some unreachable
        code)
        N)r$)r�rKrrr�visit_raise�szBasicChecker.visit_raisez	exec-usedcCs|jd|d�dS)z'just print a warning on exec statementsz	exec-used)rKN)r�)r�rKrrr�
visit_exec�szBasicChecker.visit_execcCs�t|jtj�sdS|jjdkr"dSt�|jj�}|tjkr>dS|s�|jj}t|tj	�sZdSt|jtj
�r�|jjdkr�|jd|d�dS)N�format�printzmisplaced-format-function)rK)
rCr�rErwrxrryr��Uninferabler�rvrJr�)r�Z	call_noder�Z	call_exprrrr� _check_misplaced_format_functions
z-BasicChecker._check_misplaced_format_functionz	eval-usedzbad-reversed-sequencezmisplaced-format-functioncCs~|�|�t|jtj�rz|jj}||��ksz||��ksz|dkrP|jd|d�n*|dkrd|�	|�n|dkrz|jd|d�dS)zovisit a Call node -> check if this is not a blacklisted builtin
        call and check for * or ** use
        �execz	exec-used)rK�reversed�evalz	eval-usedN)
r+rCr�rErvrJr��rootr��_check_reversed)r�rKrJrrrr�s
zBasicChecker.visit_callzassert-on-tuplecCs:|jdkr6t|jtj�r6t|jj�dkr6|jd|d�dS)z0check the use of an assert statement on a tuple.Nr�zassert-on-tuple)rK)ZfailrCrrEr�r~�eltsr�)r�rKrrr�visit_assert+s
zBasicChecker.visit_assertz
duplicate-keycCsRt�}xF|jD]<\}}t|tj�r|j}||kr@|jd||d�|�|�qWdS)z!check duplicate key in dictionaryz
duplicate-key)rKr�N)r>�itemsrCrEr�r�r��add)r�rK�keys�kr
�keyrrr�
visit_dict5szBasicChecker.visit_dictcCs|j�|�dS)zupdate try...finally flagN)r�r�)r�rKrrr�visit_tryfinally@szBasicChecker.visit_tryfinallycCs|j��dS)zupdate try...finally flagN)r��pop)r�rKrrr�leave_tryfinallyDszBasicChecker.leave_tryfinallycCs"|��}|dk	r|jd|d�dS)zcheck unreachable codeNr�)rK)Znext_siblingr�)r�rKZunreach_stmtrrrr$HszBasicChecker._check_unreachablercCs^|js
dS|j}|}xD|rXt||�sXt|d�rL||jkrL|jd||d�dS|}|j}qWdS)z�check that a node is not inside a finally clause of a
        try...finally statement.
        If we found before a try...finally bloc a parent which its type is
        in breaker_classes, we skip the whole check.Nr�zlost-exception)rKr�)r�rDrC�hasattrr�r�)r�rKr�Zbreaker_classesZ_parentrZrrrr%Nsz"BasicChecker._check_not_in_finallyc
Cs�yt�tj|dd��}Wntjk
r0Y�n�X|tjkr@dS|dkr�t|jdtj�r�yt	|jdj
���}Wntjk
r�dSXt
|dd�dkr�t�|�r�|jd|d�dSt|tjtjf�r�dSt|tj��rZ|jjdk�rt�|j��r|jd|d�dStd	d
�|j��D���rZy|jtWn$tk
�rT|jd|d�YnXdSt|d��r�xhtD]B}x:|D]0}y|�
|�Wntjk
�r�PYnX�qvWP�qlW|jd|d�n|jd|d�dS)z5 check that the argument to `reversed` is a sequence r)�positionNrJ�iterzbad-reversed-sequence)rKr?css"|]}|jdkot�|�VqdS)r?N)rJr�is_builtin_object)r;r�rrrr^�sz/BasicChecker._check_reversed.<locals>.<genexpr>rW)rryZget_argument_from_callZNoSuchArgumentErrorrEr*rCr�r�rr�r�r�rWr?r�r�r�r Z_proxiedrJr/r�r��REVERSED_PROTOCOL_METHODr�r<�REVERSED_METHODSZ
NotFoundError)r�rKrr��methods�methrrrr0`sT



zBasicChecker._check_reversedzconfusing-with-statementcCs�ts4g}|j}t|tj�r&|�|j�|�|j�n|j}|r�xjt||dd��D]T\}}t|dtj�rR|ddkrRt|dtj	�sRts�|j
|jj
krR|jd|d�qRWdS)Nrirzconfusing-with-statement)rK)�PY3KrDrCrEZWith�extendr3r�
AssignNamer�r�r�)r�rK�pairsZparent_nodeZ	prev_pair�pairrrr�
visit_with�szBasicChecker.visit_withN)r),r r!r"r%rr�r�rJr�r�Zreportsr�r�rr�rrrr�rr�r�staticmethodrrrr�r�rr�r�r�r&r'r+r�r2r8r9r;r$r%r0rIrrrrr�fsf			$/4&

;r�rrr
rrrrrrrZconstant�	attributezclass attributezinline iteration)
rrr
rrrrrrrr,r.r-r/c
Cs�g}x�tt�D]t}t|}t|}|�dd�}|�d|f|dtt���dd|fd�f�|�d|fdd	d
d||fd�f�qWt	|�S)
Nr
�-z%s-naming-style�choicez<style>z'Naming style matching correct %s names.)r�r��choices�metavar�helpz%s-rgx�regexpz<regexp>zHRegular expression matching correct %s names. Overrides %s-naming-style.)r�r�rOrP)
�sorted�KNOWN_NAME_TYPES�HUMAN_READABLE_TYPES�DEFAULT_NAMING_STYLES�replacer�r@�
NAMING_STYLESr5rR)Zname_optionsrZhuman_readable_nameZ
default_stylerrr�_create_naming_options�s*
rXc
@sFeZdZdddd�Zddddd	d
�fddddd
d
�fdddddd
�fdddddd
�fdddddd
�ffe�ZdddhiZdd�Zd d!�Zd"d#�Z	e
�d$d%�d&d'��Zd(d)�Z
e
�d$d%d*�d+d,��Ze
�d$d%d*�d-d.��ZeZe
�d$d%�d/d0��Ze
�d$d%d*�d1d2��Zd3d4�Zd5d6�Zd7d8�Zejfd9d:�Zd;d<�Zed=d>��Zd?S)@�NameChecker)zBlack listed name "%s"zblacklisted-namezDUsed when the name is listed in the black list (unauthorized names).)z"%s name "%s" doesn't conform to %szinvalid-nameziUsed when the name doesn't conform to naming rules associated to its type (constant, variable, class...).)z*Name %s will become a keyword in Python %szassign-to-new-keywordzaUsed when assignment will become invalid in future Python release due to introducing new keyword.)ZC0102ZC0103ZW0111z
good-names)�i�jr6�exZRunr
Zcsvz<names>zJGood variable names which should always be accepted, separated by a comma.)r�r�rOrPz	bad-names)ZfooZbarZbazZtotoZtutuZtatazHBad variable names which should always be refused, separated by a comma.z
name-grouprz
<name1:name2>zrColon-delimited sets of names that determine each other's naming style when the name regexes allow several styles.zinclude-naming-hintFZynz<y_or_n>z?Include a hint for the correct naming format with invalid-name.zproperty-classes)zabc.abstractpropertyz<decorator names>z�List 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.)r5��async�awaitcCs.t�||�i|_i|_i|_i|_i|_dS)N)r�r�Z_name_category�_name_group�
_bad_names�
_name_regexps�_name_hints)r�r�rrrr�TszNameChecker.__init__cCst|jjddddddddddd�
|_x4|jjD](}x"|�d�D]}d|f|j|<q<Wq,W|��\}}||_||_	dS)Nr)
Zbadname_moduleZ
badname_classZbadname_functionZbadname_methodZbadname_attrZ
badname_constZbadname_variableZbadname_inlinevarZbadname_argumentZbadname_class_attribute�:zgroup_%s)
r�r�r�ro�
name_group�splitr`�_create_naming_rulesrbrc)r��groupr�regexps�hintsrrrr�\s"
zNameChecker.opencCs�i}i}x�tD]x}d|f}t|j|�}t|�|�||<d|f}t|j|d�}|dk	rb|||<|dk	rzd|j||<qd|||<qW||fS)Nz%s_naming_stylez%s_rgxz
%r patternz%s naming style)rSrWrorWr�pattern)r�rirjrZnaming_style_option_nameZnaming_style_nameZcustom_regex_setting_nameZcustom_regexrrrrgqs


z NameChecker._create_naming_ruleszblacklisted-namezinvalid-namecCs$|�d|j�d�d|�i|_dS)Nrr8rj)�_check_namerJrfra)r�rKrrrr�szNameChecker.visit_modulec	Cs�x�|j��D]�}t|�dkrqt�t�}tj}x0|��D]$}|t|��|�t	t|�|�}q8Wt||�dkr�t
||dd�d�}tj|dd��}n||d}x|D]}|j
|�q�WqWdS)Nr�ricSstdd�|D��S)Ncss|]}|djVqdS)rN)r�)r;�warningrrrr^�sz=NameChecker.leave_module.<locals>.<lambda>.<locals>.<genexpr>)�min)rhrrrr�rz*NameChecker.leave_module.<locals>.<lambda>)r7r)rar�r~r�r�r@�sys�maxsizer�rnrRr�r��_raise_name_warning)	r�rKZ
all_groups�groupsZmin_warningsrhZby_line�warningsr�rrr�leave_module�s 

zNameChecker.leave_modulezassign-to-new-keywordcCsZ|�|j|�|�d|j|�x6|j��D](\}}t|�|��s*|�d||d�q*WdS)Nr
rr)�&_check_assign_to_new_keyword_violationrJrlZinstance_attrsr3r/Zinstance_attr_ancestors)r�rKrZanodesrrrr��s
zNameChecker.visit_classdefcCs�|�|j|�tj}|��rPt�|j��|j�r4dSt�	|j���rJtj
ntj}|�t
||jd�|j||�|jj}|dk	r�|�||�dS)N)ro)rurJr�HIGHrtrZoverrides_a_methodrDr��has_known_bases�	INFERENCErdrlr}ror��_recursive_check_names)r�rKrgr�rrrr��szNameChecker.visit_functiondefcCs"x|jD]}|�d||�qWdS)Nr)rIrl)r�rKrJrrr�visit_global�szNameChecker.visit_globalcCs,|�|j|�|��}|��}t|tj�r<|�d|j|�n�t|tj�r�t|tj	�r�t
|�s�tt�|j
�tj�r�|�d|j|�q�t|�s�|�d|j|�nt|tj�r�|�d|j|�nnt|tj�r�|j|kr�|j|��kr�t|�s�|�d|j|�n0t|tj��r(t|�|j���s(|�d|j|�dS)z!check module level assigned namesrr
rrrN)rurJr��assign_typerCrEZ
Comprehensionrlrr�rQrryr�r`rNrFr_�argnamesr@Zlocal_attr_ancestors)r�rKr�r{rrr�visit_assignname�s(zNameChecker.visit_assignnamecCs>x8|D]0}t|tj�r(|�d|j|�q|�|j|�qWdS)z.check names in a possibly recursive list <arg>rN)rCrErFrlrJryr1)r�r�rKr�rrrry�s
z"NameChecker._recursive_check_namescCs|j�||�S)N)r`r�)r�rfrrr�_find_name_group�szNameChecker._find_name_groupcCsht|}|j|}|jjr.|d|j|j7}|��||f}|jd|||d�|jd|d7<dS)Nz
 (%r pattern)zinvalid-name)rKr�rgr�ri)	rTrcroZinclude_naming_hintrbrk�
capitalizer�r�)r�rKrfrJrgZ
type_labelZhintr�rrrrq�s
zNameChecker._raise_name_warningc
s��fdd�}t�|�r,t�|�\}}|r,dS||jjkr<dS||jjkrr|jd�d7<|jd||d�dS|j�}|�	|�}	t
|	�|�r�|���}
|j�
|
i�}|�
|	jg�}|�|�||f�|	dkr�||�s�|�|�||�dS)z(check for a name using the type's regexpcs&�dkr"t�|�}t|tj�r"dSdS)NrTF)rryrCrEr`)rKr�)rfrr� _should_exempt_from_invalid_name�s

zANameChecker._check_name.<locals>._should_exempt_from_invalid_nameNr�rizblacklisted-name)rKr�)rZis_inside_exceptZclobber_in_exceptroZ
good_namesZ	bad_namesr�r�rbrerhr~ra�
setdefaultrbr�rq)
r�rfrJrKrgr�Z
clobberingr
rQrereZbad_name_grouprsr)rfrrl�s(



zNameChecker._check_namecCs2|�||j�}|dk	r.|jd|||ftjd�dS)Nzassign-to-new-keyword)rKr�rg)�_name_became_keyword_in_version�
KEYWORD_ONSETr�rrv)r�rJrKZkeyword_first_versionrrrrus
z2NameChecker._check_assign_to_new_keyword_violationcCs<x6|��D]*\}}||kr
tj|kr
d�tt|��Sq
WdS)Nr8)r3ro�version_infor9�mapr�)rJZrules�versionrrrrr�&sz+NameChecker._name_became_keyword_in_versionN)r r!r"r�rX�optionsr�r�r�rgrr�rrtr�r�r�rzr}ryr~rqrrvrlrurJr�rrrrrYs\	

 rYc@s�eZdZddd�Zdedddd�fd	d
ddd
d�ffZdd�Ze�dd�dd��Z	e�dd�dd��Z
edd��Ze�dd�dd��Z
e
Zdejfdd�ZdS)�DocStringChecker)zMissing %s docstringzmissing-docstringz�Used when a module, function, class or method has no docstring.Some special methods like __init__ doesn't necessary require a docstring.)zEmpty %s docstringzempty-docstringz^Used when a module, function, class or method has an empty docstring (it would be too easy ;).)ZC0111ZC0112zno-docstring-rgxrQz<regexp>zcRegular expression which should only match function or class names that do not require a docstring.)r�r�rOrPzdocstring-min-lengthrj�intz<int>z[Minimum line length for functions/classes that require docstrings, shorter ones are exempt.cCs|jjddddd�|_dS)Nr)Zundocumented_moduleZundocumented_functionZundocumented_methodZundocumented_class)r�r�r�)r�rrrr�Xs
zDocStringChecker.openzmissing-docstringzempty-docstringcCs|�d|�dS)Nr)�_check_docstring)r�rKrrrr`szDocStringChecker.visit_modulecCs$|jj�|j�dkr |�d|�dS)Nr
)ro�no_docstring_rgxrerJr�)r�rKrrrr�dszDocStringChecker.visit_classdefcCs8ddh}x*|jjD]}t|tj�r|j|krdSqWdS)NrrrsTF)rur	rCrErwrx)rKrIr{rrr�_is_setter_or_deleteris
z&DocStringChecker._is_setter_or_deletercCs�|jj�|j�dkr�|��r dnd}|jr8|�|�r8dSt|j�	�t
j�r�d}t�
|j�	��rdtjntj}x8|j�	���D]&}|j|krzt||jt
j�rzd}PqzW|j||||d�n$t|j�	�t
j�r�|�||�ndSdS)NrrFT)�report_missingrg)ror�rerJrtrur�rCrDr�rEr`rrwrrxrdr�r_r�r)r�rKZftypeZ
overriddenrgr�rrrr�qs$z"DocStringChecker.visit_functiondefTc	Cs<|j}|dk�r|sdSt|�|j}|dkr6|s6dS|jj}|dkrZ|dkrZ||krZdS|jd|d7<|jr�t|jdtj	�r�t|jdj
tj�r�t�
|jdj
j�}t|tj�r�t|jtj�r�tr�|jjdkr�dS|jjdkr�dS|jd	||f|d
�n4|���s8|jd|d7<|jd||f|d
�dS)z(check the node has a non empty docstringNrrjr�rirr�)r��unicode�byteszmissing-docstring)rKr�rgzempty-docstring)�docrr�roZdocstring_min_lengthr�r
rCrEZExprr�r�rryr�rZboundr rDrJr��strip)	r�rfrKr�rgZ	docstringr��	max_linesr�rrrr��s6

z!DocStringChecker._check_docstringN)r r!r"r��NO_REQUIRED_DOC_RGXr�r�rr�rr�rJr�r�r�rrvr�rrrrr�.s&r�c@s*eZdZdZddiZe�d�dd��ZdS)�PassCheckerz/check if the pass statement is really necessaryZW0107)zUnnecessary pass statementzunnecessary-passz@Used when a "pass" statement that can be avoided is encountered.zunnecessary-passcCsFt|j�|��dks4t|jtjtjf�rB|jjdk	rB|jd|d�dS)Nrizunnecessary-pass)rK)	r~rDZchild_sequencerCrEr`r_r�r�)r�rKrrr�
visit_pass�szPassChecker.visit_passN)r r!r"r%r�rr�r�rrrrr��sr�cCs"t|tj�o t|j�dko |jS)zSIs this a call with exactly 1 argument,
    where that argument is positional?
    ri)rCrEr�r~r�r)rrrr�_is_one_arg_pos_call�sr�c@s�eZdZdZdddddddgifd	d
dd�Zd$dd�Zdd�Zdd�Zdd�Zdd�Z	e
�dddddd�dd��Zdd �Z
d!d"�Zd#S)%�ComparisonCheckeraChecks 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
    )zComparison to %s should be %szsingleton-comparisonzQUsed when an expression is compared to singleton values like True, False or None.)zComparison should be %szmisplaced-comparison-constantz�Used 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.z5Using type() instead of isinstance() for a typecheck.zunidiomatic-typecheckz�The 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.Z	old_names)ZW0154zunidiomatic-typecheck)zComparison to literalzliteral-comparisonz�Used 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.)zRedundant comparison - %szcomparison-with-itselfz/Used when something is compared against itself.)z;Comparing against a callable, did you omit the parenthesis?zcomparison-with-callablez�This 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.)ZC0121ZC0122ZC0123ZR0123ZR0124ZW0143FcCs�|jdkr.|sd}nd}|jd|d|fd�nZ|jdkr\|sBd}nd}|jd|d|fd�n,|jdkr�|spd	}nd
}|jd|d|fd�dS)NTzjust 'expr'zjust 'not expr'zsingleton-comparison)rKr�Fz
'not expr'z'expr'z'expr is None'z'expr is not None')r�r�)r�Z	singletonZ	root_node�negative_check�
suggestionrrr�_check_singleton_comparisons$


z-ComparisonChecker._check_singleton_comparisoncCsvtjtjtjtjf}t||�}d}t|tj�r\t|jt�sD|jdkrHdSt|jt	t
ttf�}|sd|rr|j
d|d�dS)zMCheck if we compare to a literal, which is usually what we do not want to do.FNzliteral-comparison)rK)rEr�r�r�r�rCr�r��boolr�r�r��floatr�)r��literalrKr	Zis_other_literalZis_constrrr�_check_literal_comparison&s
z+ComparisonChecker._check_literal_comparisoncCsFt|tj�rdSt�||�}d|��||jf}|jd||fd�dS)Nz%s %s %rzmisplaced-comparison-constant)rKr�)rCrEr��REVERSED_COMPSr�rr�r�)r�rK�left�right�operatorr�rrr�_check_misplaced_constant4s
z+ComparisonChecker._check_misplaced_constantcCs�|j}|jdd}|jdd}t|tj�rHt|tj�rH|j}|j}n$t|tj�rlt|tj�rl|j}|j}||kr�d|||f}|jd||fd�dS)z�Check if identifier is compared against itself.
        :param node: Compare node
        :type node: astroid.node_classes.Compare
        :Example:
        val = 786
        if val == val:  # [comparison-with-itself]
            pass
        rriz%s %s %szcomparison-with-itself)rKr�N)	r��opsrCrEr�r�rvrJr�)r�rK�left_operand�
right_operandr�r�rrr�_check_logical_tautology;s	

z*ComparisonChecker._check_logical_tautologycsl|jdd}|tkrdStjtjf�|j|jdd}}t�fdd�||fD��dkrh|jd|d�dS)Nrric3s"|]}tt�|���rdVqdS)riN)rCrry)r;r�)�bare_callablesrrr^asz?ComparisonChecker._check_callable_comparison.<locals>.<genexpr>zcomparison-with-callable)rK)r��COMPARISON_OPERATORSrEr_rr��sumr�)r�rKr�r�r�r)r�r�_check_callable_comparisonVs
z,ComparisonChecker._check_callable_comparisonzsingleton-comparisonzmisplaced-comparison-constantzliteral-comparisonzcomparison-with-itselfzcomparison-with-callablecCs�|�|�|�|�|�|�t|j�dkr0dS|j}|jd\}}|tkrht|tj	�rh|�
||||�|dkr�t|tj	�r�|�||�nt|tj	�r�|�||�|dkr�t|tj	�r�|j||dd�|dkr�|�||�dS)Nrirz==z!=T)r�)r3zis not)
r�r��_check_unidiomatic_typecheckr~r�r�r�rCrEr�r�r�r�)r�rKr�r�r�rrr�
visit_compareis&	


zComparisonChecker.visit_comparecCs8|jd\}}|tkr4|j}t|�r4|�||||�dS)Nr)r��TYPECHECK_COMPARISON_OPERATORSr�r��_check_type_x_is_y)r�rKr�r�r�rrrr��s
z.ComparisonChecker._check_unidiomatic_typecheckcCs�t�|j�}t|tj�r$|��tks(dS|dkrzt|�rzt�|j�}t|tj�rz|��tkrzt�|j	d�}t|t
�szdS|jd|d�dS)z(Check for expressions like type(x) == Y.N)r3zis notrzunidiomatic-typecheck)rK)rryr�rCrEr`rz�
TYPE_QNAMEr�r��LITERAL_NODE_TYPESr�)r�rKr�r�r�Z	left_funcZ
right_funcZ	right_argrrrr��s
z$ComparisonChecker._check_type_x_is_yN)F)r r!r"r%r�r�r�r�r�r�rr�r�r�r�rrrrr��s0

r�cCsX|�t|��|�t|��|�t|��|�t|��|�t|��|�t|��dS)z-required method to auto register this checkerN)Zregister_checkerr�r�rYr�r�r�)r�rrr�register�sr�)N)Vr%�builtinsr�r�ror&�typingrrEZ
astroid.basesZastroid.scoped_nodes�pylintrrrZpylint.checkersrrZpylint.checkers.utilsrZpylint.reporters.ureportsr	r�Zpylint.utilsr�r
r$r(r)r*r+rWr'r�r@ZSEQUENCE_PROTOCOL_METHODSrA�	frozensetr�r�r�r�r�r�Z
UNITTEST_CASEr r:r�r�r�rDr�r�rcr?rr!r�r�r�rNrQrSrYrarhrlrqr}rr�r�ZBaseCheckerr�r�r�rSrTrUrXrYr�r�r�r�r�rrrr�<module>&s�






	
&
-@W"-Q