bgWdZddlmZddlZddlmZddlmZddlZddlm Z ddl m Z ddl m Z dd lmZdd lmZdd lmZd d hZedZdZd dZd!dZd"dZd#dZGddeZdS)$z+Basic Error checker from the basic checker.) annotationsN)Iterator)Any)nodes)InferenceResult)utils) _BasicChecker) infer_all)HIGHz_py_abc.ABCMetaz abc.ABCMeta) __module__ztyping.ForwardRef break_node nodes.Breakreturnnodes.For | nodes.While | Nonectjtjf}|j}t ||r|t |dgvr/|}|j}|n#t |||t |dgv/|S)zReturns 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. orelse)rForWhileparent isinstancegetattr)r loop_nodesrs y/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/checkers/base/basic_error_checker.py_get_break_loop_noders)U[)J  F,, g"??11  >  ,, g"??11 Mloopnodes.For | nodes.Whileboolc tjtjf}tjtjf}fd||Dt fdtj|DS)zReturns true if a loop may end with a break statement. Args: loop (astroid.For, astroid.While): the loop node inspected. Returns: bool: True if the loop may end with a break statement, False otherwise. c g|] }|k| Sr!).0_noders r z%_loop_exits_early..<s*777  D==  ==r skip_klassc3>K|]}t|v|VdSN)r)r"r#inner_loop_nodess r z$_loop_exits_early..AsC   & &.> > >  > > > >r)rrr FunctionDefClassDefnodes_of_classanyBreak)rrdefinition_nodesr)s` @r_loop_exits_earlyr11s)U[)J)5>:7777((@P(QQ777 ((AQ(RR  rnodenodes.ClassDefcLttj|dkS)zDetermine if the given `node` has abstract methods. The methods should be made abstract by decorating them with `abc` decorators. r)lenrunimplemented_abstract_methodsr2s r_has_abstract_methodsr8Hs" u3D99 : :Q >>rnodes.FunctionDefc|jrK|jjD]>}t|tjr"t |jdd|jkrdS?dS)zReturn 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 nameNTF) decoratorsrr Attributerexprr;)r2 decorators rredefined_by_decoratorr@Qs^ .  I9eo66 INFD99TYFFtt 5rc eZdZiddddddddd d d d d dddddifdddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,ifiZdsd/Zejd0dtd3Zdud7Zejd8d9dvd;Z ejd<dwd>Z ejd?d@d0ddAdBd)dxdDZ e Z dxdEZ dxdFZejdGdydIZejdJdzdLZejdJd{dNZejdOdPd|dRZejdOd}dTZejdUd~dWZejdUddYZejdZdd\Zdd`ZejdaddbZejdcddeZddhZdzdiZddkZddnZddqZdrS)BasicErrorCheckerE0100)z__init__ method is a generatorinit-is-generatorz^Used when the special class method __init__ is turned into a generator by a yield in its body.E0101)zExplicit return in __init__return-in-initzIUsed when the special class method __init__ has an explicit return value.E0102)z%s already defined line %sfunction-redefinedz3Used when a function / class / method is redefined.E0103)z%r not properly in loop not-in-loopz=Used when break or continue keywords are used outside a loop.E0104)zReturn outside functionreturn-outside-functionzEUsed when a "return" statement is found outside a function or method.E0105)zYield outside functionyield-outside-functionzDUsed when a "yield" statement is found outside a function or method.E0106z%Return with argument inside generatorzreturn-arg-in-generatorzUsed when a "return" statement with an argument is found outside in a generator function or method (e.g. with some "yield" statements). maxversion)rQE0107)z#Use of the non-existent %s operatornonexistent-operatorzzUsed when you attempt to use the C-style pre-increment or pre-decrement operator -- and ++, which doesn't exist in Python.E0108)z1Duplicate argument name %s in function definitionduplicate-argument-namezCDuplicate argument names in function definitions are syntax errors.E0110)z4Abstract class %r with abstract methods instantiatedabstract-class-instantiatedzeUsed when an abstract class with `abc.ABCMeta` as metaclass has abstract methods and is instantiated.W0120)zcElse clause on loop without a break statement, remove the else and de-indent all the code inside ituseless-else-on-loopzLoops 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.E0112)z.More than one starred expression in assignmenttoo-many-star-expressionszhEmitted when there are more than one starred expressions (`*x`) in an assignment. This is a SyntaxError.E0113)z4Starred assignment target must be in a list or tupleinvalid-star-assignment-targetzFEmitted when a star expression is used as a starred assignment target.E0114)z4Can use starred expression only in assignment targetstar-needs-assignment-targetzCEmitted when a star expression is not used in an assignment target.E0115)zName %r is nonlocal and globalnonlocal-and-globalz0Emitted when a name is both nonlocal and global.E0116)z0'continue' not supported inside 'finally' clausecontinue-in-finallyz]Emitted when the `continue` keyword is found inside a finally clause, which is a SyntaxError.E0117)z&nonlocal name %s found without bindingnonlocal-without-bindingz^Emitted when a nonlocal variable does not have an attached name somewhere in the parent scopesE0118z+Name %r is used prior to global declarationused-prior-global-declarationzcEmitted when a name is used prior a global declaration, which results in an error since Python 3.6. minversion)rQrNonec>|jjj}|dk|_dS)N)rQ)linterconfig py_version _py38_plus)selfros ropenzBasicErrorChecker.opens['2 $.rrHr2r3c2|d|dS)Nclass)_check_redefinitionrqr2s rvisit_classdefz BasicErrorChecker.visit_classdefs   $/////r assign_tuple nodes.Tuplercd}|D]R}t|tjr||cSt|tjr|dz }S|dkS)Nr)iteredrrTuple_too_many_starred_for_tupleStarred)rqrx starred_countelems rr~z-BasicErrorChecker._too_many_starred_for_tuplesz  '')) # #D$ ,, >77=====$ .. #" q  rr[r] nodes.Assignc,|jd}t|jdtjr|d|t|tjsdS||r|d|dSdS)Nrr]r7r[)targetsrrr add_messager}r~)rqr2 assign_targets r visit_assignzBasicErrorChecker.visit_assigns  Q dl1ou} 5 5 J   =D  I I I-55  F  + +M : : E   8t  D D D D D E Err_ nodes.Starredct|jtjrdSt|jtjtjtjtjfrdS|d}t|tj sdS|j |us|j |r| d|dSdS)z@Check that a Starred expression is used in an assignment target.NTfuturer_r7) rrrCallListr}SetDict statementAssignvalue parent_ofr)rqr2stmts r visit_starredzBasicErrorChecker.visit_starreds dk5: . .  F dkEJ UY #S T T  F~~T~**$ --  F :  !5!5d!;!;    ;$  G G G G G  rrDrFrUrar9cx||||t|s@tj|s,||rdpd||tj tj tj f}|rs|j dkrh| r|d|n.s333a!'333rc3BK|]}tj||VdSr()ris_none)r"vs rr*z6BasicErrorChecker.visit_functiondef..s1AAQ a0@0@AqAAAAAArrFrU)r2args confidence)_check_nonlocal_and_global_check_name_used_prior_globalr@r(is_registered_in_singledispatch_functionru is_methodr-rReturnr+r,r; is_generatorrr.filterr kwonlyargs itertoolschain from_iterabler )rqr2returnsvalues arg_clusters argumentsargs rvisit_functiondefz#BasicErrorChecker.visit_functiondefs ''--- **4000%    X@FF X  $ $T^^%5%5%B(%PjRV W W W%% Le&7%H&   >>   B Z 7 7  "" B  !44 @@@@337333AA&AAAAAB$$%5D$AAA #)$AU0V#W#W ?00;; - -Cx<''  -(# !*- SX&& - -rcpfdtjD}|sdStjD]e}|ur|j}||}|s8|j}|r$||jkr|d||ffdS)NcVi|]%}|jD]}|u||&Sr!)namesscope)r"childr;r2s r zCBasicErrorChecker._check_name_used_prior_global..0sQ      {{}}$$ %%$$$rrgr2r) r-rGlobalNamerr;get fromlinenor)rqr2 scope_globals node_namer;corresponding_global global_linenos ` rrz/BasicErrorChecker._check_name_used_prior_global/s    ,,U\::     F,,UZ88  I  ,,>D#0#4#4T#:#: ' 0;M 1E!E!E  3)4'!  rcd fd tjj}t|fdt jD}|sdSt|fdt jD}||D]}| d |f dS) z.Check that a name is both nonlocal and global.currentnodes.Global | nodes.Nonlocalrrc0|uSr()r)rr2s r same_scopez@BasicErrorChecker._check_nonlocal_and_global..same_scopeLs==??d* *rc3<K|]}| |jVdSr(rr"rrs rr*z?BasicErrorChecker._check_nonlocal_and_global..QI:e$$ rNc3<K|]}| |jVdSr(rrs rr*z?BasicErrorChecker._check_nonlocal_and_global..\rrrarr2)rrrr) rrrsetr-rNonlocalr intersectionr)rqr2 from_iter nonlocals global_varsr;rs ` @rrz,BasicErrorChecker._check_nonlocal_and_globalIs3 + + + + + +O1  I!00@@      F I!00>>    **;77 M MD   2$t  L L L L M MrrL nodes.Returnct|dtjs|d|dSdS)NTrrLr7)rframerr+rrvs r visit_returnzBasicErrorChecker.visit_returnesR$**D*1153DEE C   6T  B B B B B C CrrN nodes.Yieldc0||dSr(_check_yield_outside_funcrvs r visit_yieldzBasicErrorChecker.visit_yieldj &&t,,,,,rnodes.YieldFromc0||dSr(rrvs rvisit_yieldfromz!BasicErrorChecker.visit_yieldfromnrrrJrcnodes.Continuec2||ddS)Ncontinue_check_in_looprvs rvisit_continuez BasicErrorChecker.visit_continuers D*-----rrc2||ddS)Nbreakrrvs r visit_breakzBasicErrorChecker.visit_breakvs D'*****rrY nodes.Forc0||dSr(_check_else_on_looprvs r visit_forzBasicErrorChecker.visit_forz   &&&&&r nodes.Whilec0||dSr(rrvs r visit_whilezBasicErrorChecker.visit_while~rrrS nodes.UnaryOpc|jdvrnt|jtjrQ|jj|jkr>|jdz|jjkr(|d||jdzdSdSdSdSdS)z2Check use of the non-existent ++ and -- operators.z+-r{rSrN)oproperandrUnaryOp col_offsetrrvs r visit_unaryopzBasicErrorChecker.visit_unaryopsW__4<77DG++1$ (???   3$TWq[  Q Q Q Q Q ___++??rnodes.Nonlocalr;strc|}|j|t|tjtjfs|d|f|dS||us ||jvr|j}dSt|tjs!|d|f|tdSdS)Nrer)rr2r) rrrrr,r+rlocalsr )rqr2r; current_scopes r_check_nonlocal_without_bindingz1BasicErrorChecker._check_nonlocal_without_bindings ".mene>O-PQQ   !;4'PT UUU  ,,M>##y00$$5X]Check that any loop with an else clause has a break statement.rYrr{)r2lineN)rr1rlinenorvs rrz%BasicErrorChecker._check_else_on_loopsp ; 066    &[^*Q.          rnodes.Continue | nodes.Breakrc|D]}t|tjtjfr ||jvrdSt|tjtjfrn\t|tjrA||j vr8t|tj r|j s| d|| d||dS)z0Check that a node is inside a for or while loop.Nrcr7rJr) node_ancestorsrrrrrr,r+ TryFinally finalbodyContinuerpr)rqr2rrs rrz BasicErrorChecker._check_in_loops))++ C CF&59ek":;; v},,FF&5>53D"EFF 65#344 CF,,,tU^44--  !6T BBB T BBBBBr redeftypenodes.Call | nodes.FunctionDefc|jd}d|j|jD}t d|D|}||urt j||st|tj r|jtvrdStj |rdSt|jtj rit|jjtjr_|jjjdkrJt|jjjtjr!|jjjj|jkrdSt|jjtjrt|jjjtjr|jjjj|jkrz|jjjdddkrYt|jjjdd tjr$|jjjdd jdS ||}|d|D]R}tj|}|r:t|t jr |t8krdSSn#t:$rYnwxYw|jjj } | r| !|jrdS|"d |||j#f dSdSdS) z;Check for redefinition of a function / method / class name.Trchg|]/}t|jtjr |jj-|0Sr!)rrr AnnAssignsimple)r"is rr$z9BasicErrorChecker._check_redefinition..sK   qx99 ?@ho    rc3BK|]}tj||VdSr()ris_overload_stub)r"locals rr*z8BasicErrorChecker._check_redefinition.. s2 S SuU5KE5R5R SU S S S S S SrNnotrisr{rHr)$rrrr;nextastroid are_exclusiverrr,REDEFINABLE_METHODSrr#IftestrrrrCompareleftopsConstrindex safe_inferInstancer TYPING_FORWARD_REF_QNAME ValueErrorrmrndummy_variables_rgxmatchrr) rqrr2 parent_frame redefinitions defined_selfredefinition_index redefinitionrr6s rruz%BasicErrorChecker._check_redefinitions${(((55   !(3    S S S S S    t # #G,A$ ,U,U #<88 I!444%d++ $+ux00 t{/?? (+u44"4;#3#;UZHH5 (05BBF t{/??"4;#3#8%*EE (-2di?? (,Q/2d::"4;#3#7#:1#=u{KK; (,Q/28@F %2%8%8%>%>"%22E3E2E$FL$/ ==H &x1ABB%NN,,0HHH    #'+"4"H " ':'@'@'K'K    $!89      m $ # # #s7J** J76J7N)rrj)r2r3rrj)rxryrr)r2rrrj)r2rrrj)r2r9rrj)r2rrrj)r2rrrj)r2rrrj)r2rrrj)r2rrrj)r2rrrj)r2rrrj)r2rrrj)r2rr;rrrj)r2rrrj)r2rrrj)rrr2rrrj)r2rrrj)r2rrrrrj)rrr2rrrj)__name__r __qualname__msgsrrronly_required_for_messagesrwr~rrrvisit_asyncfunctiondefrrrrrrrrrrrrrrrrrrur!rrrBrBds4j  j   j   j $  %j .  /j 8  9j B  3 % #6 "  Cj R  Sj ^  _j h  ij t  uj D  Ej P  Qj Z  [j d  ej n  oj z  {j F  9 + : 6 "  Gj j DX////&U%&:;;000<;0!!!!&U%#%E E E E E&U%&DEEHHHFEH"&U%!!'----B/4MMMM8&U%&?@@CCCA@C&U%&>??---@?-&U%&>??---@?-&U%m5JKK...LK.&U%m44+++54+&U%&<=='''>='&U%&<=='''>='&U%&<==RRR>=R,&U%&@AA===BA=&U%&CDDCCCEDC%%%%NBBBB    CCCC*JJJJJJrrB)r rrr)rrrr)r2r3rr)r2r9rr)__doc__ __future__rrcollections.abcrtypingrr(rastroid.typingrpylint.checkersr"pylint.checkers.base.basic_checkerr pylint.checkers.utilsr pylint.interfacesr r  frozensetr*r4rr1r8r@rBr!rrrLsr 21""""""$$$$$$******!!!!!!<<<<<<++++++""""""$m4i00.*.????&bbbbb bbbbbr