
    e9X                       U d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
Z
ddl
mZ ddlmZ dd	lmZmZ dd
lmZ e	rddlmZ ddddddddddd
Zded<    ej.                  d      Z eddh      ZdZdZdZ eg dd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdiee      ZdrdjZdsdkZ dtdlZ!	 	 	 	 	 	 dudmZ"	 	 	 	 	 	 dvdnZ# G do dpe      Z$dwdqZ%y)xzCheck for signs of poor design.    )annotationsN)defaultdict)Iterator)TYPE_CHECKING)nodes)BaseChecker)is_enumonly_required_for_messages)MessageDefinitionTuple)PyLinter)zToo many ancestors (%s/%s)too-many-ancestorsznUsed when class has too many parent classes, try to reduce this to get a simpler (and so easier to use) class.)z$Too many instance attributes (%s/%s)too-many-instance-attributeszsUsed when class has too many instance attributes, try to reduce this to get a simpler (and so easier to use) class.)zToo few public methods (%s/%s)too-few-public-methodszLUsed when class has too few public methods, so be sure it's really worth it.)zToo many public methods (%s/%s)too-many-public-methodsznUsed when class has too many public methods, try to reduce this to get a simpler (and so easier to use) class.)z"Too many return statements (%s/%s)too-many-return-statementszWUsed when a function or method has too many return statement, making it hard to follow.)zToo many branches (%s/%s)too-many-brancheszOUsed when a function or method has too many branches, making it hard to follow.)zToo many arguments (%s/%s)too-many-argumentsz8Used when a function or method takes too many arguments.)z Too many local variables (%s/%s)too-many-localsz<Used when a function or method has too many local variables.)zToo many statements (%s/%s)too-many-statementszpUsed when a function or method has too many statements. You should then split it in smaller functions / methods.)z4Too many boolean expressions in if statement (%s/%s)too-many-boolean-expressionsz@Used when an if statement contains too many boolean expressions.)
R0901R0902R0903R0904R0911R0912R0913R0914R0915R0916z!dict[str, MessageDefinitionTuple]MSGSz^_{2}[a-z]+_{2}$	dataclassattrsdataclassesztyping.NamedTupleztyping.TypedDictzbuiltins.objectzbuiltins.tuplezbuiltins.dictzbuiltins.listzbuiltins.setzbulitins.frozensetzcollections.ChainMapzcollections.Counterzcollections.OrderedDictzcollections.UserDictzcollections.UserListzcollections.UserStringzcollections.defaultdictzcollections.dequezcollections.namedtuplez_collections_abc.Awaitablez_collections_abc.Coroutinez_collections_abc.AsyncIterablez_collections_abc.AsyncIteratorz_collections_abc.AsyncGeneratorz_collections_abc.Hashablez_collections_abc.Iterablez_collections_abc.Iteratorz_collections_abc.Generatorz_collections_abc.Reversiblez_collections_abc.Sizedz_collections_abc.Containerz_collections_abc.Collectionz_collections_abc.Setz_collections_abc.MutableSetz_collections_abc.Mappingz_collections_abc.MutableMappingz_collections_abc.MappingViewz_collections_abc.KeysViewz_collections_abc.ItemsViewz_collections_abc.ValuesViewz_collections_abc.Sequencez _collections_abc.MutableSequencez_collections_abc.ByteStringztyping.Tupleztyping.Listztyping.Dictz
typing.Setztyping.FrozenSetztyping.Dequeztyping.DefaultDictztyping.OrderedDictztyping.Counterztyping.ChainMapztyping.Awaitableztyping.Coroutineztyping.AsyncIterableztyping.AsyncIteratorztyping.AsyncGeneratorztyping.Iterableztyping.Iteratorztyping.Generatorztyping.Reversibleztyping.Containerztyping.Collectionztyping.AbstractSetztyping.MutableSetztyping.Mappingztyping.MutableMappingztyping.Sequenceztyping.MutableSequenceztyping.ByteStringztyping.MappingViewztyping.KeysViewztyping.ItemsViewztyping.ValuesViewztyping.ContextManagerztyping.AsyncContextManagerztyping.Hashableztyping.Sizedc                r   | j                         D ]-  }t        |      r y|j                         t        t        fv s- y | j
                  syt        | j                         j                        }| j
                  j                  D ]  }t        |t        j                        r|j                  }t        |t        j                  t        j                  f      sTt        |t        j                        r|j                   }n|j"                  }|t$        v s|j'                  t$              s	t(        |v s y y)z7Check if a class is exempt from too-few-public-methods.TF)	ancestorsr	   qnameTYPING_NAMEDTUPLETYPING_TYPEDDICT
decoratorssetrootlocalsr   
isinstanceastroidCallfuncName	AttributenameattrnameDATACLASSES_DECORATORSintersectionDATACLASS_IMPORT)nodeancestorroot_locals	decoratorr4   s        A/usr/lib/python3/dist-packages/pylint/checkers/design_analysis.py_is_exempt_from_public_methodsr>      s     NN$ 8>> 13CDD	 ??diik(()K__** 	i.!I)gllG4E4E%FGi.>>D%%D))$$%;<;.     c                    d}| j                         D ]0  }t        |t        j                        r|t	        |      z  },|dz  }2 |S )zCounts the number of boolean expressions in BoolOp `bool_op` (recursive).

    example: a and (b or c or (d and e)) ==> 5 boolean expressions
    r      )get_childrenr.   r/   BoolOp_count_boolean_expressions)bool_opnb_bool_expr	bool_exprs      r=   rD   rD      sQ    
 L))+ 	i06yAALAL	
 r?   c                    t        d | j                         D              }| j                         D ]7  }t        j	                  |j
                        s#|j
                  dk7  s3|dz  }9 |S )Nc              3  X   K   | ]"  }|j                   j                  d       rd $ yw_rA   Nr4   
startswith.0methods     r=   	<genexpr>z*_count_methods_in_class.<locals>.<genexpr>   s"     XFFKK<R<RSV<WaX    **__init__rA   )summethods	mymethodsSPECIAL_OBJsearchr4   )r9   all_methodsrP   s      r=   _count_methods_in_classrZ      s_    XdllnXXK .." fkk*v{{j/H1K r?   c              #    K   t               }t        | j                  d            }|ra|j                         }|j	                         |v r%||vr6| |j                  |       |j                  |j                  d             |r`yyw)a  Get parents of ``node``, excluding ancestors of ``ignored_parents``.

    If we have the following inheritance diagram:

             F
            /
        D  E
         \/
          B  C
           \/
            A      # class A(B, C): ...

    And ``ignored_parents`` is ``{"E"}``, then this function will return
    ``{A, B, C, D}`` -- both ``E`` and its ancestors are excluded.
    F)recursN)r+   listr&   popr'   addextend)r9   ignored_parentsparents
to_exploreparents        r=   _get_parents_iterre      s     $ $'5GdnnEn23J
!<<>_,  LKKf..e.<= s   BB
Bc                ,    t        t        | |            S N)r+   re   )r9   ra   s     r=   _get_parentsrh     s      788r?   c                      e Zd ZdZdZe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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(g d)d*d+dffZdE fd,ZdFd-Z	dGd.Z
 ed/d0d1d2      dHd3       Z ed1d2      dHd4       Z ed5d6d7d8d9d:      dId;       ZeZ ed5d6d7d8d9      dId<       ZeZdJd=ZdKd>ZdLd?Z ed@d6      dMdA       ZdMdBZdNdCZeZdOdPdDZ xZS )QMisdesignCheckerzChecker of potential misdesigns.

    Checks for sign of poor/misdesign:
    * number of methods, attributes, local variables...
    * size, complexity of functions, methods
    designzmax-args   intz<int>z2Maximum number of arguments for function / method.)defaulttypemetavarhelpz
max-locals   z4Maximum number of locals for function / method body.zmax-returns   z<Maximum number of return / yield for function / method body.zmax-branches   z4Maximum number of branch for function / method body.zmax-statements2   z7Maximum number of statements in function / method body.zmax-parents   z<num>z2Maximum number of parents for a class (see R0901).zignored-parents csvz%<comma separated list of class names>zOList of qualified class names to ignore when counting class parents (see R0901)zmax-attributesz5Maximum number of attributes for a class (see R0902).zmin-public-methods   z9Minimum number of public methods for a class (see R0903).zmax-public-methods   z9Maximum number of public methods for a class (see R0904).zmax-bool-exprzEMaximum number of boolean expressions in an if statement (see R0916).zexclude-too-few-public-methods
regexp_csvz<pattern>[,<pattern>...]zfList of regular expressions of class ancestor names to ignore when counting public methods (see R0903)c                0    t         |   |       |  |  |  y rg   )superrS   )selflinter	__class__s     r=   rS   zMisdesignChecker.__init__  s     r?   c                    | j                   j                  j                          g | _        t	        t
              | _        g | _        | j                   j                  j                  | _
        y)zInitialize visit variables.N)r   statsreset_node_count_returnsr   rm   	_branches_stmtsconfigexclude_too_few_public_methods_exclude_too_few_public_methods)r~   s    r=   openzMisdesignChecker.open  sM    **,$S)KK== 	,r?   c                l    t        | j                        D ]  \  }}| j                  |xx   |z  cc<    y rg   )	enumerater   )r~   amountirK   s       r=   _inc_all_stmtszMisdesignChecker._inc_all_stmts  s0    dkk* 	%DAqKKNf$N	%r?   r   r   r   r   c                   t        |t        j                  | j                  j                  j
                              }t        |      }|| j                  j                  j                  kD  r4| j                  d||| j                  j                  j                  f       |j                         }|j                  j                         D cg c]  \  }}|d   j                         |u s| }}}t        |      | j                  j                  j                  kD  r>| j                  d|t        |      | j                  j                  j                  f       yyc c}}w )zFCheck size of inheritance hierarchy and number of instance attributes.r   r9   argsr   r   N)rh   STDLIB_CLASSES_IGNORE_ANCESTORunionr   r   ra   lenmax_parentsadd_messager,   instance_attrsitemsmax_attributes)r~   r9   rb   
nb_parentsr,   kvfiltered_attrss           r=   visit_classdefzMisdesignChecker.visit_classdef  s.    *001C1C1S1ST
 \
**666$ $++"4"4"@"@A   yy{ //557
1a1Q499;$;NA
 
 ~!3!3!B!BB..)4;;+=+=+L+LM   C
s   E+Ec                   t        d |j                         D              }|| j                  j                  j                  kD  r4| j                  d||| j                  j                  j                  f       |j                  dk(  rA| j                  r5|j                         D ]"  t        fd| j                  D              s" y |j                  dk7  st        |      ryt        |      }|| j                  j                  j                  k  r5| j                  d||| j                  j                  j                  f       yy)zCheck number of public methods.c              3  X   K   | ]"  }|j                   j                  d       rd $ ywrJ   rL   rN   s     r=   rQ   z2MisdesignChecker.leave_classdef.<locals>.<genexpr>  s&      
FKK4J4J34OA
rR   r   r   classc              3  \   K   | ]#  }|j                  j                                % y wrg   )matchr'   )rO   patternr:   s     r=   rQ   z2MisdesignChecker.leave_classdef.<locals>.<genexpr>  s)       MM(.."23s   ),Nr   )rT   rV   r   r   max_public_methodsr   ro   r   r&   anyr>   rZ   min_public_methods)r~   r9   
my_methodsrY   r:   s       @r=   leave_classdefzMisdesignChecker.leave_classdef  s-     
 NN,
 

 **===) $++"4"4"G"GH   99D$H$H NN,  #'#G#G   99#A$#G
 .d3++>>>(!4;;#5#5#H#HI   ?r?   r   r   r   r   r   zkeyword-arg-before-varargc                T   | j                   j                  d       |j                  j                  |j                  j                  z   |j                  j                  z   }| j
                  j                  j                  |d}rt        fd|D              }t        |      |z
  }|| j
                  j                  j                  kD  r@| j                  d|t        |      | j
                  j                  j                  f       nd}t        |j                        |z
  }d|j                  v r|dz  }|| j
                  j                  j                  kD  r4| j                  d||| j
                  j                  j                  f       | j                  j                  d       y)	zeCheck function name, docstring, arguments, redefinition,
        variable names, max locals.
        r   Nc              3  Z   K   | ]"  }j                  |j                        sd  $ yw)rA   N)r   r4   )rO   argignored_argument_namess     r=   rQ   z5MisdesignChecker.visit_functiondef.<locals>.<genexpr>  s(      ')?)E)Echh)OA's    ++r   r   rK   rA   r   )r   appendr   posonlyargs
kwonlyargsr   r   r   rT   r   max_argsr   r-   
max_localsr   )r~   r9   r   ignored_args_numargnumlocnumr   s         @r=   visit_functiondefz"MisdesignChecker.visit_functiondef  sm    	Qyy~~		 5 55		8L8LL!%!3!3!J!J %#& '!%' $  Y!11F**333  (d)T[[%7%7%@%@A !   !T[[!$44 $++aKFDKK&&111!dkk00;;<   	1r?   c                   | j                   j                         }|| j                  j                  j                  kD  r4| j                  d||| j                  j                  j                  f       | j                  |   }|| j                  j                  j                  kD  r4| j                  d||| j                  j                  j                  f       | j                  j                         }|| j                  j                  j                  kD  r5| j                  d||| j                  j                  j                  f       yy)zlMost of the work is done here on close:
        checks for max returns, branch, return in __init__.
        r   r   r   r   N)
r   r^   r   r   max_returnsr   r   max_branchesr   max_statements)r~   r9   returnsbranchesstmtss        r=   leave_functiondefz"MisdesignChecker.leave_functiondef,  s    --##%T[[''333,t{{11==>  
 >>$'dkk((555# 2 2 ? ?@   !4;;%%444%T[[//>>?   5r?   c                L    | j                   sy| j                   dxx   dz  cc<   y)zCount number of returns.NrA   )r   )r~   rK   s     r=   visit_returnzMisdesignChecker.visit_returnP  s     }}bQr?   c                @    |j                   r| j                  d       yy)zXDefault visit method -> increments the statements counter if
        necessary.
        rA   N)is_statementr   )r~   r9   s     r=   visit_defaultzMisdesignChecker.visit_defaultV  s      " r?   c                    t        |j                        }|j                  r|dz  }|j                  r|dz  }| j	                  ||       | j                  |       y Increments the branches counter.rA   N)r   handlersorelse	finalbody_inc_branchr   r~   r9   r   s      r=   	visit_tryzMisdesignChecker.visit_try]  sN    t}}%;;MH>>MHx(H%r?   r   c                   | j                  |       d}|j                  rDt        |j                        dkD  s't        |j                  d   t        j
                        s|dz  }| j                  ||       | j                  |       y)z?Increments the branches counter and checks boolean expressions.rA   r   N)_check_boolean_expressionsr   r   r.   r/   Ifr   r   r   s      r=   visit_ifzMisdesignChecker.visit_ifg  sk     	''-;;q 
4;;q>7::(NMHx(H%r?   c                   |j                   }t        |t        j                        syt	        |      }|| j
                  j                  j                  kD  r5| j                  d||| j
                  j                  j                  f       yy)zvGo through "if" node `node` and count its boolean expressions
        if the 'if' node test is a BoolOp node.
        Nr   r   )	testr.   r/   rC   rD   r   r   max_bool_exprr   )r~   r9   	conditionrF   s       r=   r   z+MisdesignChecker._check_boolean_expressionst  sv     II	)W^^41)<$++,,:::."DKK$6$6$D$DE   ;r?   c                N    d}|j                   r|dz  }| j                  ||       yr   )r   r   r   s      r=   visit_whilezMisdesignChecker.visit_while  s'    ;;MHx(r?   c                N    | j                   |j                         xx   |z  cc<   y)r   N)r   scope)r~   r9   branchesnums      r=   r   zMisdesignChecker._inc_branch  s    tzz|$3$r?   r   r   returnNone)r   r   )r   rm   r   r   )r9   nodes.ClassDefr   r   )r9   znodes.FunctionDefr   r   )rK   znodes.Returnr   r   )r9   nodes.NodeNGr   r   )r9   z	nodes.Tryr   r   )r9   znodes.Ifr   r   )r9   znodes.Whiler   r   )rA   )r9   r   r   rm   r   r   )__name__
__module____qualname____doc__r4   r!   msgsoptionsrS   r   r   r
   r   r   r   visit_asyncfunctiondefr   leave_asyncfunctiondefr   r   r   r   r   r   	visit_forr   __classcell__)r   s   @r=   rj   rj     sl    DD "L		
 "N		
 "			
 "N		
 "Q		
 "L		
 Bi		
 "			
 !"			
 !"			
 ")			
 -$5E			
SsGj
%  & !	<   8:ST+ U+Z  $#''R /$6 /#&   >@ST
& U
&) I4 4r?   rj   c                8    | j                  t        |              y rg   )register_checkerrj   )r   s    r=   registerr     s    
,V45r?   )r9   zastroid.ClassDefr   bool)rE   znodes.BoolOpr   rm   )r9   r   r   rm   )r9   r   ra   frozenset[str]r   zIterator[nodes.ClassDef])r9   r   ra   r   r   zset[nodes.ClassDef]r   )&r   
__future__r   recollectionsr   collections.abcr   typingr   r/   r   pylint.checkersr   pylint.checkers.utilsr	   r
   pylint.typingr   pylint.lintr   r!   __annotations__compilerW   	frozensetr6   r8   r(   r)   r   r>   rD   rZ   re   rh   rj   r   rw   r?   r=   <module>r      s  
 & " 	 # $     ' E 0$


k:   <z bjj+,"K#9:   ' %  "+NNN 	N 		N
 	N 	N 	N 	N 	"N 	N 	N 	!N 	"N 	N 	!N  	%!N" 	%#N$ 	)%N& 	)'N( 	*)N* 	$+N, 	$-N. 	$/N0 	%1N2 	&3N4 	!5N6 	%7N8 	&9N: 	;N< 	&=N> 	#?N@ 	*ANB 	'CND 	$ENF 	%GNH 	&INJ 	$KNL 	+MNN 	&ONP 	QNR 	SNT 	UNV 	WNX 	YNZ 	[N\ 	]N^ 	_N` 	aNb 	cNd 	eNf 	gNh 	iNj 	kNl 	 mNn 	oNp 	qNr 	sNt 	uNv 	wNx 	yNz 	{N| 	}N~ 	N@ 	 ANB 	CND 	!ENF 	GNH 	INJ 	KNL 	MNN 	ONP 	 QNR 	%SNT 	UNV 	WNX 	YNZ 	[NP" f@!>
!>+9!>!>H9
9+999}4{ }4@6r?   