bgϞdZddlmZddlZddlZddlZddlmZddlm Z m Z ddl Z ddl m Z m Z mZddlmZddlmZmZdd lmZmZmZdd lm Zdd lmZe rdd lmZejd krddlmZnddl mZGddeZ!dZ"dZ#e#e"ffZ$e%e&ddDgdfiddDZ'd#d Z(Gd!d"e!Z)dS)$zBasic checker for Python code.) annotationsN)Iterator) TYPE_CHECKINGcast)nodesobjectsutil)utils) BaseCheckerr )HIGH INFERENCE Confidence)r) LinterStats)PyLinter)LiteralceZdZdZdZdS) _BasicCheckerzYPermits separating multiple checks with the same checker name into classes/file. basicN)__name__ __module__ __qualname____doc__names/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/checkers/base/basic_checker.pyrr!s DDDrr __reversed__) __getitem____len__c<g|]}dd|gS).builtins)join.0xs r r*0s(DDDq:q/ " "DDDr)setdictlist)zset()z{}z[]ci|]}||d S)z()rr's r r/3s0     a888   r)zcollections.dequezcollections.ChainMapzcollections.Counterzcollections.OrderedDictzcollections.defaultdictzcollections.UserDictzcollections.UserListsectreporter_nodes.Sectionstatsr old_statsLinterStats | NonereturnNonec (i}dD]}ttd|}||}i||<|dkrY||}||z }|dz|z }|d||d<||} | dz|z }|d||d<gd} dD]}ttd|}||} |r||nd } | rt j| | nd } | |t| | rt| nd | r| nd ||dd ||dd gz } | tj | d d d S)zzMake a report of. * percentage of different types documented * percentage of different types with a bad name )moduleclassmethodfunction)r;r9r:r8rgY@z.2fpercent_documentedpercent_badname)typenumberz old number differencez %documentedz%badnameNNC0)childrencolsrheaders) rrget_node_countget_undocumented get_bad_names lint_utils diff_stringstrgetappendreporter_nodesTable)r0r2r3 nice_stats node_typetotalundocumented_node documentedpercent badname_nodelinesnewolddiff_strs rreport_by_type_statsr]Bs-/J> H H !HI9UU $$Y// " 9 A:: % 6 6y A A !22J!E)U2G=D:J:JJy !"6 7 ..y99L#e+u4G:A7G7GJy !"3 4 U U UE>   !HI9UU ""9--5>Hi&&y111D7:D:)#s333  HH %CHHH *HHd y ! % %&:C @ @ y ! % %&7 = =    KK$e!aHHHIIIIIrceZdZdZdZiddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*Zd+d,effZdfd1 Zdd2Z e j d3d4dd7Z e j d3d4dd9Z e j d3d4dd;Zdd?ZeddBZddEZddGZe j dHdIdJdKdLddNZeddSZeddYZe j dZdd[Ze j d\dd^ZeZdd_Ze j d`daddcZe j d`ddeZe j d`daddgZe j d`ddiZddlZe j dmdndodpd`ddqZ e j drdsdduZ!e j dvddxZ"e j dydd{Z#dd}Z$dd~Z%e&fddZ' dddZ(ddZ)e j dddZ*ddZ+ddZ,e j ddddZ-e j dddZ.xZ/S) BasicCheckera>Basic checker. 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 rW0101)zUnreachable 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 argumentdangerous-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 effectpointless-statementzEUsed when a statement doesn't have (or at least seems to) any effect.W0105)zString statement has no effectpointless-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 nothingexpression-not-assignedzqUsed when an expression that is not a function call is assigned to nothing. Probably something else was intended.W0108)zLambda may not be necessaryunnecessary-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)zDuplicate key %r in dictionary duplicate-keyzDUsed when a dictionary expression binds the same key multiple times.W0122)z Use of exec exec-useda Raised when the 'exec' statement is used. It's dangerous to use this function for a user input, and it's also slower than actual code in general. This doesn't mean you should never use it, but you should consider alternatives first and restrict the functions available.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 exceptionlost-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 populated tuple. Did you mean 'assert x,y'?assert-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.W0124)z?Following "as" with another context manager looks like a tuple.confusing-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.W0125)z3Using a conditional statement with a constant valueusing-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 parenthesesW0127)z(Assigning the same variable %r to itselfself-assigning-variablez>>> ? ? ? ?r,nodes.If | nodes.IfExp | nodes.Comprehensionrnodes.NodeNG | Nonec Btjtjtjtjtjt jjt j t j tjf }tj tj tj tjf}tjtjtjtjtjf}d}t)|tjf|z|z}d}t)||sft-j|}t)|t0jr7t)|tjrt6|\}}nt)|tjr|}|rt-j|j} t)| tjr_d} | D]'} t)| jtjsd} nd} (| r| d|tBdS|r| d|tBdSt)||rd} t)|tjr"tE|#} nz5BasicChecker._name_holds_generator..s^$ $ +,el;;$ {)/1C D D$ $ $ $ $ $ rrDr)rrrframelookuprnextall itertoolschainlenrrrr)rrr lookup_resultmaybe_generator_assigned first_items rrz"BasicChecker._name_holds_generatorsD $ +++++# $ //66tyAA  .-- -$ $ ,Q/$ $ $  2D99  !9?J=2JKKLL HM!$%%**}Q/295<HH+}Q/29?LL+(5Q'7':'A'G$)))r_ nodes.ModulecD|jjjdxxdz cc<dS)z4Check module name, docstring and required arguments.r8rDNrr2 node_countrrs r visit_modulezBasicChecker.visit_modules, $X...!3.....rnodes.ClassDefcD|jjjdxxdz cc<dS)zXCheck module name, docstring and redefinition increment branch counter. klassrDNrrs rvisit_classdefzBasicChecker.visit_classdefs. $W---2-----rrerrgrir nodes.Exprc8|j}t|tjrt|jtr|}t|tjtjtjfrzt|tjr |j dkrnT| }|>||ur(t|tj tj frdS| d|dSt|tjrd}t|jtjr |jj }n+t|jtjr |jj}|ddrt)j|nd}t|t,jr| d|t0dSt|tjtjfsXt|jtjr|jj|gks(t|tjr|jt<urdSt|tjr| d |t@dStC|"tjr,| d ||# dS| d |dS) z4Check for various kind of statements without effect.rNrgrrDrrrrirargsre)$rrrrrMscoperrrrprevious_siblingr AnnAssignrrrr Attributeattrnameisupperr rrExceptionInstancer YieldAwaitr TryExceptbodyEllipsis NamedExprr anynodes_of_class as_string)rrexprrsiblingrrs r visit_exprzBasicChecker.visit_exprsz dEK ( ( Z C-H-H  JJLLE%%.%,@Q!RSS eU%677 EJ*>   3$9! F tek5;7 8 8 4;88 =A[=MRVQW=W=W4-->X26*2H2H F dEO , , ?   9QU  V V V V V $$UZ00 1 1 ?   )4>>;K;K         2  > > > > >r nodes.Lambda call_argslist[nodes.NodeNG]Iterator[nodes.NodeNG]c#K|D]^}t|tjr>t|jtjr|jj|jjkr|VZ|V_dSr)rrStarredrrrrvararg)rrargs r_filter_varargzBasicChecker._filter_varargst   C#u}-- sy%*55 $)*:::III   rr#list[nodes.Starred | nodes.Keyword] variadic_namerMboolc@| ptfd|DS)Nc3K|]S}t|jtjr|jjkpt|jtj VTdSr)rrrrr)r(ars rrz6BasicChecker._has_variadic_argument..sq   qw + + . - 3aguz222      r)r )rrs `r_has_variadic_argumentz#BasicChecker._has_variadic_argumentsHx 3           rrkc,|jjrdS|j}t|tjsdSt|jjtjr+t|jjjtjrdStj j |}t|jj}t|||j}|jjr'||j|jjrdS|jjr(||j|jjrdSn |jrdS|jrfd|jjD}t+|t+|jkrdSt/|j|rdSt+|t+|krdSt3||D]5\}}t|tjsdS|j|jkrdS6|jtjD]'} | | jd|urdS(|d|j|dS)z'Check whether the lambda is suspicious.Nch|] }|j Sr)r)r(keywords r z,BasicChecker.visit_lambda..3sLLLgW\LLLrrrk)liner) rdefaultsr rrrrrrr argumentsCallSite from_callr-rkwargr!kwargsrstarargskeywordsrkeyword_argumentsr+r@ziprrr rr fromlineno) rrcall call_site ordinary_args new_call_args lambda_kwargsr passed_argrs r visit_lambdazBasicChecker.visit_lambda s 9   Fy$ ++  F dineo 6 6 : IN < <   F%.88>> TY^,, T00tyAABB 9? **4; HH  9  **4=$):JKK   ]  F = ML9KLLLM=!!S)D%E%EEE9.//::=II  }  ]!3!3 3 3 F"=-@@  OCj%*55 x:?**+ I,,UZ88  D{{49%%a(D001 -DO$OOOOOrrcnodes.FunctionDefc|r |jjjdxxdz cc<n|jjjdxxdz cc<||dS)zeCheck function name, docstring, arguments, redefinition, variable names, max locals. r:rDr;N) is_methodrr2r_check_dangerous_defaultrs rvisit_functiondefzBasicChecker.visit_functiondefMs{ >>   : K  ( 2 2 2a 7 2 2 2 2 K  ( 4 4 4 9 4 4 4 %%d+++++rczd d}|jjpg|jjpgz}|D]}|s t|}n#t j$rY:wxYwt|t jr<| tvr ||ur t| }nt|t js ||r||r| }nt|tj r |jd| d}nd|d| d}n7|dt| d}|d ||f d S) z0Check for dangerous default values as arguments. internal_node nodes.NodeNGr5rcdt|tjtjtjfSr)rrrrr)r?s r is_iterablez:BasicChecker._check_dangerous_default..is_iterable]smej%)UZ-PQQ Qrz() ()z (rcrN)r?r@r5r)rr' kw_defaultsrinferrrrInstanceqnameDEFAULT_ARGUMENT_SYMBOLSpytyperrrrr)rrrBr'defaultrmsgs rr<z%BasicChecker._check_dangerous_defaultZs R R R RI&,"1F1L"M T TG  W]]__--)    5'"233 TKKMM%===G##25;;==ACCw'788_KK "h . . F  344 dD0 1 1  F N"+Ii44 9>5:66 NN'722  !<9 MMMMM N N  N N22rrqrorrctj|r||t||t |jtjr|jj }|| dvss|| vs_|dkr| d|d S|dkr| |d S|dkr| d |d Sd Sd Sd Sd S) zVisit a Call node.)rTrexecrorreversedevalrqN)r is_terminating_funcrNr rerrrrrrrootr_check_reversed)rrrs r visit_callzBasicChecker.visit_calls%  $T * * @  # #DY # ? ? ? --d333 di , , =9>DDJJdJ3333ttyy{{7J7J6>>$$[t$<<<<<Z''((.....V^^$$[t$<<<<< = =437J7J $^rrur nodes.Assertct|jtjr:t |jjdkr|d|tt|jtjrKt|jj tr.|jj rd}nd}|d||fdSdSdS) z:Check whether assert is used on a tuple or string literal.rrurneveralwaysrrN) rrrrreltsrr rrrM)rrwhens r visit_assertzBasicChecker.visit_asserts di - - L#din2E2E2I2I   .Td  K K K di - - R*TY_c2R2R Ry    7d$  Q Q Q Q Q  R R R Rrrm nodes.DictcBt}|jD]\}}t|tjr|j}n0t|tjr|}nW||vr|d||| |dS)z"Check duplicate key in dictionary.rmrN) r+itemsrrrrrrradd)rrkeyskrkeys r visit_dictzBasicChecker.visit_dictsuuJ  DAq!U[)) gAu// kkmmd{{  t# FFF HHSMMMM  rr nodes.Setct}|jD]\}t|tjr|j}n%||vr|d||t||]dS)zCheck duplicate value in set.r)rrrN) r+rrrrrrrr rx)rrvaluesvrs r visit_setzBasicChecker.visit_sets  A!U[))   %Du! JJu      rnodes.TryFinallycL|jJ|j|dSzUpdate try...finally flag.N)rrOrs rvisit_tryfinallyzBasicChecker.visit_tryfinallys. ,,,   &&&&&rcJ|jJ|jdSr)rpoprs rleave_tryfinallyzBasicChecker.leave_tryfinallys, ,,, rFnodes.Return | nodes.Continue | nodes.Break | nodes.Raise | nodes.Callrrc<|}|t|tjrQt|tjr7t|jtjr|}|dS|d||dSdS)zCheck unreachable code.Nrar) next_siblingrrReturnExprrrr)rrrunreachable_statements rrNzBasicChecker._check_unreachable s !% 1 1 3 3 ,4.. 4ejAA 4:EKHH )>(J(J(L(L%(0F   $9j       - ,rrnodes.Break | nodes.Return node_namebreaker_classestuple[nodes.NodeNG, ...]c|jsdS|j}|}|r`t||sRt|dr#||jvr|d||dS|}|j}|rt||NdSdSdSdS)zCheck that a node is not inside a 'finally' clause of a 'try...finally' statement. If we find a parent which type is in breaker_classes before a 'try...finally' block we skip the whole check. N finalbodyrsr)rrrhasattrrr)rrrr_parent_nodes rrOz"BasicChecker._check_not_in_finally#s   F+ #j/BB #w ,, ':K1K1K  !19 MMMElG  #j/BB # # # # # # # # #rc tjtj|d}t|tjrdS|t|jdtjr t|jdj }n#tj $rYdSwxYwt|dddkr+tj|r|d|dSt|tjtjfrdS|jst|tjrt+dt-j|jf|jDr= |jt6n'#t8$r|d|YnwxYwdSt;|d rXt<D]5}|D].} ||#tj$rYnwxYwn6|d|dSdS|d|dS#tj $rYdSwxYw) z4Check that the argument to `reversed` is a sequence.r)positionNriterrrc3TK|]#}|jdkotj|V$dS)r,N)rr is_builtin_object)r(ancestors rrz/BasicChecker._check_reversed..ZsM MV+Q0G0Q0Qrgetattr)!r rget_argument_from_callrr rrrrrrrErrrrrrrrrFr rr_proxied ancestorslocalsREVERSED_PROTOCOL_METHODKeyErrorrREVERSED_METHODS NotFoundErrorNoSuchArgumentError)rrargumentrmethodsmeths rrlzBasicChecker._check_reversed<s5 E'(DTTU(V(V(VWWH(D$899 dilEJ77M#DIaL$5$;$;$=$=>>"1fd  $)$;D$A$A (()@t(LLL(UZ$=>>  ? z(G|jjj}|D]}t|tjsg}|jD]}t|tjr||g3t|tjrE|j dkr:|r| |j rdS| |j tj |}|D]$\}}|dkr|d|f|% dS)NrrDrr)rrdummy_variables_rgxrrrrr_check_redeclared_assign_namerrmatchrO collectionsCounter most_commonr) rrrr found_nameselementnamesrcounts rrz*BasicChecker._check_redeclared_assign_namesH"k0D  Ffek22 K!; 5 5gu{33566yAAAA)9::5w|s?R?R*/B/H/H/V/V&&w|444' 44E$0022   e199$$2$v%   rr}rcd||||jdSr)rrrrs r visit_assignzBasicChecker.visit_assigns4 ++D111 **4<88888r nodes.Forc<||jgdSr)rrrs r visit_forzBasicChecker.visit_fors  **DK=99999r)rrr5r6)r5r6)rrr5r6)rrr5r6)rrr5r6)rrrrr5r6)rrr5r)rrr5r6)rrr5r6)rrr5r6)rrrrr5r)rrrrMr5r)rrr5r6)rr9r5r6)rrLr5r6)rrQr5r6)rrVr5r6)rr\r5r6)r_r`r5r6)rr`r5r6)rrnr5r6)rrur5r6)rr}r5r6)rrr5r6)rrr5r6)rrrrr5r6)r)rrrrMrrr5r6)rrr5r6)rrr5r6)rrr5r6)rrr5r6)0rrrrrmsgsr]reportsrrr only_required_for_messagesrrrr staticmethodrrrrrr!r8r=visit_asyncfunctiondefr<rPrTr[r^rermrtr|rrrr rNrOrlrrrrr __classcell__)rs@rr_r_ls   DS  S   S   S $  %S 4  5S @  AS P  QS Z  [S j  kS z  {S J  KS X  YS j  kS x  yS F  GS P  QS Z  [S h     [S S S Dj.0DEGG@@@@@@----&U%E9999&U%E9999&U%E???? OUOUOUOUb***\*:44443333 &U%'$!$ <?<?<?<?|   \    \ &U%&:;;@P@P@P<;@PD&U%&?@@,,,A@,/&T&T&T&TP&U%m5EFF I I IGF I&U%m44&&&54& &U%m5EFF L L LGF L&U%m44&&&54& NNNN*&U%# ===="&U%&79STT R R RUT R&U%o66   76 &U%&788   98 ''''     "&457 #####27E7E7E7Er&U%&@AA L L LBA L''''R.&U%!#=9999&U%&@AA:::BA:::::rr_)r0r1r2rr3r4r5r6)*r __future__rrrsyscollections.abcrtypingrrrrrr pylintr rKpylint.checkersr pylint.interfacesr r rpylint.reporters.ureportsrP pylint.utilsrpylint.lint.pylinterr version_infortyping_extensionsrrSEQUENCE_PROTOCOL_METHODSrr,r0rHr]r_rrrrsP %$"""""" $$$$$$&&&&&&&&((((((((((&&&&&&........9999999999======$$$$$$.------v))))))K*6-0H/JK 4CDD,CDDD       (&J&J&J&JTb :b :b :b :b :=b :b :b :b :b :r