
    c                    H   d 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 ddlmZ ddlmZ dd	lmZ dd
lmZ erddlmZ e	ej        ej        ej        ej        ej        ej        ej        ej         ej!        ej"        ej#        ej$        ej%        ej&        ej'        ej(        f         Z)e	ej*        ej+        ej,        ej-        f         Z. ede	e)ej-        ej/        f                   Z0 G d de          Z G d de          Z G d dej1                  Z2ddZ3dS )z.Module to add McCabe checker class for pylint.    )annotations)Sequence)TYPE_CHECKINGAnyTypeVarUnion)nodes)	PathGraph)PathGraphingAstVisitor)checkers)only_required_for_messages)HIGH)PyLinter_AppendableNodeT)boundc                        e Zd Zd fdZ xZS )r
   node"_SubGraphNodes | nodes.FunctionDefc                ^    t                                          ddd           || _        d S )N    )nameentitylineno)super__init__root)selfr   	__class__s     8lib/python3.11/site-packages/pylint/extensions/mccabe.pyr   zPathGraph.__init__1   s-    bA666			    )r   r   )__name__
__module____qualname__r   __classcell__r   s   @r    r
   r
   0   s=                 r!   r
   c                       e Zd Zd fdZddZdd	ZddZeZd dZexZ	xZ
xZxZxZxZxZxZxZxZxZxZxZxZxZZd!dZeZd"dZ	 d#d$dZd%dZ xZS )&r   returnNonec                d    t                                                       d| _        d | _        d S )Nr   )r   r   _bottom_countergraph)r   r   s    r    r   zPathGraphingAstVisitor.__init__7   s,     '+


r!   r   nodes.NodeNGargsr   c                P    |                                 D ]} | j        |g|R   d S N)get_childrendispatch)r   r   r.   childs       r    defaultzPathGraphingAstVisitor.default<   sD    &&(( 	( 	(EDM%'$'''''	( 	(r!   c                    || _         |j        }| j                            |          }|/|j        }t          | j        d|z   | j                  }|| j        |<    ||g|R  S )Nvisit)r   r   _cachegetr"   getattrvisitorr4   )r   r   r.   klassmeth
class_names         r    r2   zPathGraphingAstVisitor.dispatch@   sp    	{u%% 	&J4<:)=t|LLD!%DKtD 4    r!   nodes.FunctionDefc                   | j         |                     |          }|| _        |                     |j                   | j         }| xj        dz  c_        | j                             | j        |           | j                             ||           || _        d S t          |          | _         || _        |                     |j                   | j         | j        | j	         |j
         <   |                                  d S )Nr   )r,   _append_nodetaildispatch_listbodyr+   connectr
   graphs	classnamer   reset)r   r   pathnodebottoms       r    visitFunctionDefz'PathGraphingAstVisitor.visitFunctionDefJ   s    : 	((..H DIty))),.F  A%  Jty&111JtV,,,DIII"4DJDIty))):>*DK4>649667JJLLLLLr!   _StatementNodesc                0    |                      |           d S r0   )r@   r   r   s     r    visitSimpleStatementz+PathGraphingAstVisitor.visitSimpleStatement^   s    $r!   
nodes.Withc                d    |                      |           |                     |j                   d S r0   )r@   rB   rC   rM   s     r    	visitWithz PathGraphingAstVisitor.visitWithy   s2    $49%%%%%r!   r   _AppendableNodeT | Nonec                t    | j         r| j        sd S | j                            | j         |           || _         |S r0   )rA   r,   rD   rM   s     r    r@   z#PathGraphingAstVisitor._append_node   s@    y 	
 	4
49d+++	r!    _SubGraphNodesr   strextra_blocksSequence[nodes.ExceptHandler]c                   | j         Yt          |          | _         |                     |||           | j         | j        | j         | <   |                                  dS |                     |           |                     |||           dS )z@Create the subgraphs representing any `if` and `for` statements.N)r,   r
   _subgraph_parserE   rF   rG   r@   )r   r   r   rW   s       r    	_subgraphz PathGraphingAstVisitor._subgraph   s     : 	;"4DJ  t\:::59ZDK4>14112JJLLLLLd###  t\:::::r!   rH   c                H   g }|| _         |                     |j                   |                    | j                    |D ]=}|| _         |                     |j                   |                    | j                    >|j        r<|| _         |                     |j                   |                    | j                    n|                    |           |rH| j        rC| j         }| xj        dz  c_        |D ]}| j                            ||           || _         dS dS dS )zAParse the body and any `else` block of `if` and `for` statements.r   N)rA   rB   rC   appendorelser,   r+   rD   )r   r   rH   rW   
loose_endsextrarI   ends           r    rZ   z&PathGraphingAstVisitor._subgraph_parse   sN    
	49%%%$)$$$! 	) 	)EDIuz***di((((; 	$DIt{+++di((((d### 	DJ 	,.F  A%  ! 0 0
""3////DIII	 	 	 	r!   )r(   r)   )r   r-   r.   r   r(   r)   )r   r-   r.   r   r(   r   )r   r>   r(   r)   )r   rK   r(   r)   )r   rO   r(   r)   )r   r   r(   rR   )rT   )r   rU   r   rV   rW   rX   r(   r)   )r   rU   rH   rU   rW   rX   r(   r)   )r"   r#   r$   r   r4   r2   rJ   visitAsyncFunctionDefrN   visitAssertvisitAssignvisitAugAssignvisitDelete
visitRaise
visitYieldvisitImport	visitCallvisitSubscript	visitPassvisitContinue
visitBreakvisitGlobalvisitReturn	visitExpr
visitAwaitrQ   visitAsyncWithr@   r[   rZ   r%   r&   s   @r    r   r   6   s       , , , , , ,
( ( ( (! ! ! !   $ -       2 >R-RK RR 	R
 	R 	R 	R 	R 	R 	R" 	#R& 	'R* 	+R, 	-R, "-R, %.
& & & & N    79	; ; ; ; ;"       r!   r   c                  \    e Zd ZdZdZddiZddddd	d
ffZ ed          dd            ZdS )McCabeMethodCheckerzoChecks McCabe complexity cyclomatic threshold in methods and functions
    to validate a too complex code.
    designR1260)z*%s is too complex. The McCabe rating is %dtoo-complexzSUsed when a method or function is too complex based on McCabe Complexity Cyclomaticzmax-complexity
   intz<int>z&McCabe complexity cyclomatic threshold)r4   typemetavarhelprx   r   nodes.Moduler(   r)   c                   t                      }|j        D ]}|                    ||           |j                                        D ]}|                                }|j        }t          |d          rd|j         d}n"d|j	        j
                                         d}|| j        j        j        k    rq|                     d|t           ||f           dS )zVisit an astroid.Module node to check too complex rating and
        add message if is greater than max_complexity stored from options.
        r   'zThis 'rx   )r   
confidencer.   N)r   rC   preorderrE   values
complexityr   hasattrr   r   r"   lowerlinterconfigmax_complexityadd_messager   )r   r   r:   r3   r,   r   	node_names          r    visit_modulez McCabeMethodChecker.visit_module   s   
 )**Y 	- 	-EUG,,,,^**,, 	 	E))++J:DtV$$ H,	,,,		GT^%<%B%B%D%DGGG	T[/>> DTJ@W     	 	r!   N)r   r~   r(   r)   )	r"   r#   r$   __doc__r   msgsoptionsr   r   rT   r!   r    ru   ru      s          D 	 
D "@	 	

G  ..   /.  r!   ru   r   r   r(   r)   c                J    |                      t          |                      d S r0   )register_checkerru   )r   s    r    registerr      s%    
/7788888r!   N)r   r   r(   r)   )4r   
__future__r   collections.abcr   typingr   r   r   r   astroidr	   mccaber
   Mccabe_PathGraphr   Mccabe_PathGraphingAstVisitorpylintr   pylint.checkers.utilsr   pylint.interfacesr   pylint.lintr   AssertAssign	AugAssignDeleteRaiseYieldImportCall	SubscriptPassContinueBreakGlobalReturnExprAwaitrK   If	TryExceptForWhilerU   FunctionDefr   BaseCheckerru   r   rT   r!   r    <module>r      s/  
 5 4 " " " " " " $ $ $ $ $ $ 5 5 5 5 5 5 5 5 5 5 5 5       0 0 0 0 0 0 J J J J J J       < < < < < < " " " " " " %$$$$$$	L	L	O	L	K	K	L	J	O	J	N	K	L	L	J	K& ux%)U[HI7eOU[%BS$ST   
        { { { { {: { { {|. . . . .(. . . .b9 9 9 9 9 9r!   