Your IP : 216.73.216.196


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

B

A!p\:�@s�dZddlmZddlmZmZddlm	Z	ddl
mZddlm
Z
mZGdd�de�ZGd	d
�d
e�ZGdd�de	j�Zd
d�ZdS)z/Module to add McCabe checker class for pylint. �)�absolute_import)�	PathGraph�PathGraphingAstVisitor)�checkers)�check_messages)�HIGH�IAstroidCheckercseZdZ�fdd�Z�ZS)rcs tt|�jdddd�||_dS)N��)�name�entity�lineno)�superr�__init__�root)�self�node)�	__class__��I/opt/alt/python37/lib/python3.7/site-packages/pylint/extensions/mccabe.pyrszPathGraph.__init__)�__name__�
__module__�__qualname__r�
__classcell__rr)rrrsrcs�eZdZ�fdd�Zdd�Zdd�Zdd�ZeZd	d
�ZeZ	Z
ZZZ
ZZZZZZZZZZZZdd�ZeZd
d�Zddd�Zdd�Z�ZS)rcstt|���d|_dS)Nr)rrr�_bottom_counter)r)rrrrszPathGraphingAstVisitor.__init__cGs&x |��D]}|j|f|��q
WdS)N)Zget_children�dispatch)rr�args�childrrr�default szPathGraphingAstVisitor.defaultcGsR||_|j}|j�|�}|dkrD|j}t|jd||j�}||j|<||f|��S)N�visit)rr�_cache�getr�getattr�visitorr)rrr�klass�methZ	classNamerrrr$s
zPathGraphingAstVisitor.dispatchcCs�|jdk	rd|�|�}||_|�|j�d|j}|jd7_|j�|j|�|j�||�||_n<t|�|_||_|�|j�|j|jd|j	|j
f<|��dS)Nz%sr
z%s%s)�graph�_append_node�tail�
dispatch_list�bodyr�connectr�graphs�	classnamer�reset)rr�pathnode�bottomrrr�visitFunctionDef.s



z'PathGraphingAstVisitor.visitFunctionDefcCs|�|�dS)N)r')rrrrr�visitSimpleStatementBsz+PathGraphingAstVisitor.visitSimpleStatementcCs|�|�|�|j�dS)N)r'r)r*)rrrrr�	visitWith_s
z PathGraphingAstVisitor.visitWithcCs$|js
dS|j�|j|�||_|S)N)r(r&r+)rrrrrr'es
z#PathGraphingAstVisitor._append_nodercCs^|jdkrBt|�|_|�|||�|j|jd|j|f<|��n|�|�|�|||�dS)z?create the subgraphs representing any `if` and `for` statementsNz%s%s)r&r�_subgraph_parser,r-r.r')rrr�extra_blocksrrr�	_subgraphls



z PathGraphingAstVisitor._subgraphcCs�g}||_|�|j�|�|j�x*|D]"}||_|�|j�|�|j�q(W|jrt||_|�|j�|�|j�n
|�|�|r�d|j}|jd7_x|D]}|j�||�q�W||_dS)z@parse the body and any `else` block of `if` and `for` statementsz%sr
N)r(r)r*�appendZorelserr&r+)rrr/r5Z
loose_ends�extrar0�lerrrr4xs&



z&PathGraphingAstVisitor._subgraph_parse)r) rrrrrrr1ZvisitAsyncFunctionDefr2ZvisitAssertZvisitAssignZvisitAugAssignZvisitDeleteZ
visitPrintZ
visitRaiseZ
visitYieldZvisitImportZ	visitCallZvisitSubscriptZ	visitPassZ
visitContinueZ
visitBreakZvisitGlobalZvisitReturnZ	visitExprZ
visitAwaitr3ZvisitAsyncWithr'r6r4rrr)rrrs
D
rc@sDeZdZdZeZdZddiZddddd	d
�ffZe	d�dd
��Z
dS)�McCabeMethodCheckerzoChecks McCabe complexity cyclomatic threshold in methods and functions
    to validate a too complex code.
    ZdesignZR1260)z*%s is too complex. The McCabe rating is %dztoo-complexzSUsed when a method or function is too complex based on McCabe Complexity Cyclomaticzmax-complexity�
�intz<int>z&McCabe complexity cyclomatic threshold)r�type�metavar�helpztoo-complexcCs�t�}x|jD]}|�||�qWxj|j��D]\}|��}|j}t|d�rVd|j}nd|j	j
��}||jj
krtq.|jd|t||fd�q.WdS)z�visit an astroid.Module node to check too complex rating and
        add message if is greather than max_complexity stored from optionsrz'%s'z	This '%s'ztoo-complex)rZ
confidencerN)rr*Zpreorderr,�values�
complexityr�hasattrrrr�lower�configZmax_complexityZadd_messager)rrr#rr&rAZ	node_namerrr�visit_module�s
z McCabeMethodChecker.visit_moduleN)rrr�__doc__rZ__implements__rZmsgs�optionsrrErrrrr:�sr:cCs|�t|��dS)z�Required method to auto register this checker.

    :param linter: Main interface object for Pylint plugins
    :type linter: Pylint object
    N)Zregister_checkerr:)Zlinterrrr�register�srHN)rF�
__future__rZmccaberZMccabe_PathGraphrZMccabe_PathGraphingAstVisitor�pylintrZpylint.checkers.utilsrZpylint.interfacesrrZBaseCheckerr:rHrrrr�<module>sw1