bg1hUdZddlmZddlZddlZddlZddlmZddlm Z m Z ddl Z ddl m Z m Z mZddlmZddlmZmZdd lmZdd lmZdd lmZmZdd lmZe rdd lmZdPdZ dQdRdZ dSdZ!idddddd d!d"d#d$d%d&gifd'd(d)d*d+d,d-d.d/d0d1d2d%d3gifd4d5d6d7d8d9d:d;dd?d@dAZ"dBe#dC<GdDdEZ$GdFdGe$Z%GdHdIe$Z&GdJdKej'Z(dTdOZ)dS)Uz,Checks for various exception related errors.) annotationsN) Generator) TYPE_CHECKINGAny)nodesobjectsutil)InferenceContext)InferenceResultSuccessfulInferenceResult)checkers)utils)HIGH INFERENCE)MessageDefinitionTuple)PyLinterreturnset[str]cVdd}tjt|}d|DS)NobjrrboolcVt|tot|tSN) isinstancetype issubclass BaseException)rs k/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/checkers/exceptions.py predicatez&_builtin_exceptions..predicates!#t$$GC)G)GGc"h|] \}}|j S)__name__.0_excs r z&_builtin_exceptions.."s 1 1 1XaCL 1 1 1r )rrrr)inspect getmembersbuiltins)rmemberss r_builtin_exceptionsr-sBHHHH 955G 1 1 1 1 11r stmt nodes.NodeNGcontextInferenceContext | NoneEGenerator[tuple[nodes.NodeNG, SuccessfulInferenceResult], None, None]c#LKt|tjtjfrB|jD]8}t j|}|r t|tjs||fV9dS| |D]#}t|tjr||fV$dS)zRecursively generate nodes inferred by the given statement. If the inferred value is a list or a tuple, recurse on the elements. Returns an iterator which yields tuples in the format ('original node', 'inferred node'). N) rrListTupleeltsr safe_inferr UninferableBaseinfer)r.r0eltinferreds r_annotated_unpack_inferr<%s$U[1229 $ $C',,H $ 8T5I J J $8m###JJw'' h 4 5 5  Hnr bodylist[nodes.NodeNG]rc4td|DS)zz_is_raising..<s.>>z$ ,,>>>>>>r )any)r=s r _is_raisingrF:s >>>>> > >>r E0701)zBad except clauses order (%s)bad-except-orderzUsed when except clauses are not in the correct order (from the more specific to the more generic). If you don't fix the order, some exceptions may not be caught by the most specific handler.E0702)z6Raising %s while only classes or instances are allowedraising-bad-typezkUsed when something which is neither a class nor an instance is raised (i.e. a `TypeError` will be raised).E0704)z2The raise statement is not inside an except clausemisplaced-bare-raiseagUsed when a bare raise is not used inside an except clause. This generates an error, since there are no active exceptions to be reraised. An exception to this rule is represented by a bare raise inside a finally clause, which might work, as long as an exception is raised inside the try block, but it is nevertheless a code smell that must not be relied upon.E0705zDException cause set to something which is not an exception, nor Nonebad-exception-causeziUsed when using the syntax "raise ... from ...", where the exception cause is not an exception, nor None. old_names)E0703zbad-exception-contextE0710)zBRaising a new style class which doesn't inherit from BaseExceptionraising-non-exceptionzOUsed when a new style class which doesn't inherit from BaseException is raised.E0711)z8NotImplemented raised - should raise NotImplementedErrornotimplemented-raisedzAUsed when NotImplemented is raised instead of NotImplementedErrorE0712)z>Catching an exception which doesn't inherit from Exception: %scatching-non-exceptionzcUsed when a class which doesn't inherit from Exception is used as an exception in an except clause.W0702)zNo exception type(s) specified bare-exceptaJA bare ``except:`` clause will catch ``SystemExit`` and ``KeyboardInterrupt`` exceptions, making it harder to interrupt a program with ``Control-C``, and can disguise other problems. If you want to catch all exceptions that signal program errors, use ``except Exception:`` (bare except is equivalent to ``except BaseException:``).W0718z!Catching too general exception %sbroad-exception-caughtzIf you use a naked ``except Exception:`` clause, you might end up catching exceptions other than the ones you expect to catch. This can hide bugs or make it harder to debug programs when unrelated errors are hidden.)W0703z broad-exceptW0705)z,Catching previously caught exception type %sduplicate-exceptzQUsed when an except catches a type that was already caught by a previous handler.W0706)z%The except handler raises immediatelytry-except-raisezUsed when an except handler uses raise as its first or only operator. This is useless because it raises back the exception immediately. Remove the raise operator or the entire try-except-raise block!W0707)z3Consider explicitly re-raising using %s'%s from %s'raise-missing-fromahPython's exception chaining shows the traceback of the current exception, but also of the original exception. When you raise a new exception after another exception was caught it's likely that the second exception is a friendly re-wrapping of the first exception. In such cases `raise from` provides a better link between the two tracebacks in the final error.W0711)z;Exception to catch is the result of a binary "%s" operationbinary-op-exceptionz~Used when the exception to catch is of the form "except A or B:". If intending to catch multiple, rewrite as "except (A, B):"W0715)z?Exception arguments suggest string formatting might be intendedraising-format-tuplezUsed when passing multiple arguments to an exception constructor, the first of them a string literal containing what appears to be placeholders intended for formattingW0716)zInvalid exception operation. %swrong-exception-operationzUsed when an operation is done against an exception, but the operation is not valid for the exception in question. Usually emitted when having binary operations between exceptions in except handlers.W0719)z!Raising too general exception: %sbroad-exception-raisedaARaising exceptions that are too generic force you to catch exceptions generically too. It will force you to use a naked ``except Exception:`` clause. You might then end up catching exceptions other than the ones you expect to catch. This can hide bugs or make it harder to debug programs when unrelated errors are hidden.z!dict[str, MessageDefinitionTuple]MSGSc*eZdZdZddZdd Zdd ZdS) BaseVisitorz/Base class for visitors defined in this module.checkerExceptionsCheckerrC nodes.RaiserNonec"||_||_dSr)_checker_node)selfrmrCs r__init__zBaseVisitor.__init__s  r r c|jj}t|d|zd}|r ||dS||dS)Nvisit_) __class__r#lowergetattr visit_default)rtrCname dispatch_meths rvisitzBaseVisitor.visitse~&,,..hot<<  % M$        t $ $ $ $ $r r&r/cdS)z)Default implementation for all the nodes.Nr"rtr&s rr{zBaseVisitor.visit_defaultsr N)rmrnrCrorrp)rCr rrp)r&r/rrp)r# __module__ __qualname____doc__rur~r{r"r rrlrlsV99%%%%888888r rlc"eZdZdZd dZd dZd S) ExceptionRaiseRefVisitorz4Visit references (anything that is not an AST leaf).rC nodes.Namerrpc|jdkr)|jd|jtdS t t |}n#tj$rYdSwxYw|D]f\}}t|tj rG|j |r-|jd|j|jtgdS)NNotImplementedrTrC confidenceriargsrCr)r|rr add_messagersrlistr<astroidInferenceErrorrrClassDef_is_overgeneral_exceptionr)rtrC exceptionsr& exceptions r visit_namez#ExceptionRaiseRefVisitor.visit_names 9( ( ( M % %'djT &    F 5d;;< -99)DD  )),"( *  sAA&%A& nodes.Callct|jtjr||jt |jdkrt|jdtjrnt|jdjtrK|jdj}d|vsd|vr3d|vr1|j d|j tdSdSdSdSdSdS)Nr%{}rer)rfuncrNamerlenrConstvaluestrrrrrsr)rtrCmsgs r visit_callz#ExceptionRaiseRefVisitor.visit_calls di , , ' OODI & & &  NNQ  49Q<55 49Q<-s33 )A,$CczzcSjjSCZZ ))**       )jZZr N)rCrrrp)rCrrrp)r#rrrrrr"r rrrsB>>.      r rc>eZdZdZddZdd ZeZdd ZddZddZ dS)ExceptionRaiseLeafVisitorz1Visitor for handling leaf kinds of a raise value.rC nodes.Constrrpct|jd|j|jjjt dS)NrJrCrr)rrrrsrrxr#rrtrCs r visit_constz%ExceptionRaiseLeafVisitor.visit_constsA !! %. "     r instanceobjects.ExceptionInstancec>|j}||dSr)_proxiedvisit_classdef)rtrclss rvisit_instancez(ExceptionRaiseLeafVisitor.visit_instances$ C     r nodes.ClassDefctj|sDtj|r2|jr-|jd|jtdSdSdSdS)NrRr)rinherit_from_std_exhas_known_basesnewstylerrrrsrrs rrz(ExceptionRaiseLeafVisitor.visit_classdefs(.. 53H3N3N }  ))+(*      r r& nodes.TuplecV|jd|jdtdS)NrJtupler)rrrrsrrs r visit_tuplez%ExceptionRaiseLeafVisitor.visit_tuples9 !!  "     r r/ct|d|jj}|jd|j|t dS)Nr|rJr)rzrxr#rrrrsr)rtrCr|s rr{z'ExceptionRaiseLeafVisitor.visit_defaultsOtVT^%<== !!  "     r N)rCrrrp)rrrrp)rCrrrp)r&rrrp)rCr/rrp) r#rrrrrvisit_exceptioninstancerrr{r"r rrrs;;    !!!! -          r rc ZeZdZdZdZeZddddddffZd4fd Ze j d d ddddddd5dZ d5dZ d5dZ d5dZd6d Zd7d"Ze j d#d8d%Ze j d#d9d'Ze j d(d)d*d+d,d-d.d7d/Zd:d3ZxZS);rnzException related checks.rzovergeneral-exceptions)zbuiltins.BaseExceptionzbuiltins.Exceptioncsvzz0Exceptions that will emit a warning when caught.)defaultrmetavarhelprrpct|_|jjjD](}d|vr"t jd|dt ddd)tdS)N.zSpecifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.z ' ?) instead.z*pylint: Command line or configuration filerpylint)categoryfilenamelinenomodule) r-linterconfigovergeneral_exceptionswarnings warn_explicit UserWarningsuperopen)rtexc_namerxs rrzExceptionsChecker.open3s#6#8#8  *A  H(""&ZCKZZZ)I#      r rLrJrRrTrNrerarirCroc|j||dS|j||n|||j}t |||tj|}|t|tj rdSt|||dSr) r'_check_misplaced_bare_raisecause_check_raise_missing_from_check_bad_exception_causerr~rr7rr r8r)rtrCexprr;s r visit_raisezExceptionsChecker.visit_raiseCs 8   , ,T 2 2 2 F :   * *4 0 0 0 0  + +D 1 1 1x t,,224888#D))  z(D4HII  F!$--33H=====r c|}t|tjr!|r |jdkrdS|}tjtjf}|r3t|j|s|j}|rt|j|tjf}|rt|j|s|d|tdSdS)N__exit__rLr) scoperr FunctionDef is_methodr| ExceptHandlerparentrr)rtrCrcurrentignoresexpecteds rrz-ExceptionsChecker._check_misplaced_bare_raise_s  ue/ 0 0 !!  j(( F&(9: %jAA %nG %jAA %') QjBB Q   3$4  P P P P P Q Qr ctj|j}|t|tjrdSt|t jr(|j| d|tdSdSt|t j s3tj |s!| d|tdSdSdS)zyVerify that the exception cause is properly set. An exception cause can be only `None` or an exception. NrNr) rr7rrr r8rrrrrrr)rtrCrs rrz,ExceptionsChecker._check_bad_exception_causets  ,, =Jud.BCC= F eU[ ) ) U{&  !6Ti XXXXX'&E5>22 U5;T < <  U   2)  T T T T T U U U Ur c|jdStj|}|sdS|jd}t |jt jt jfr|j }| d|d|d| dftdSt |jt j r$t |jj t js9t |jt jrY|jj|jjkrA| d|d| |jjftdSdSdS)N Exceptionraz'except z as exc' and r'r)r'r!find_except_wrapper_node_in_scoper|rrrrr5 as_stringrrCallr)rtrCcontaining_except_nodeclass_of_old_errors rrz+ExceptionsChecker._check_raise_missing_froms 8  F!&!H!N!N%  F " & ."- 05 EK7PQQ M%;%@%J%J%L%L"   $@1@@@NN$$         tx , , 48=%*55 $(EJ//  !7!zCExceptionsChecker._check_catching_non_exception..s#BBB#(--BBBr c3JK|]}t|tjVdSr)rr r8rBs rrDzBExceptionsChecker._check_catching_non_exception..s/OOd:dD$899OOOOOOr c3lK|]/}|o(tj|ptj| V0dSr)rrrrBs rrDzBExceptionsChecker._check_catching_non_exception..s`Y.t44WEEl>P>X\++C00?Y $$0$\"nn..0%   , ..**,! F)#..  888$S))   ,7.gather_exceptions_from_handler..sA )))ej%/5RSS%r )rrr7rrr5rr6)rrexceptions_in_handlers rgather_exceptions_from_handlerzQExceptionsChecker._check_try_except_raise..gather_exceptions_from_handlers13J| (-(8(F(F%3U[AA  !%-B-G""JJ+ "7!8JJ 4 r Fc3fK|]+}tjtj|V,dSr)ris_subclass_ofr7)r%einferred_currents rrDz.sP,U-=a-@-@BRSSr rTr_)rC)rrrr)handlersrr7rErFr=r'r) rtrCr bare_raisehandler_having_bare_raiseexceptions_in_bare_handlerrexcs_in_current_handlerexc_in_current_handlerrs @r_check_try_except_raisez)ExceptionsChecker._check_try_except_raises_    * $(!CE"} U UG  +I*H*Q*Q'.EE-5EE.E*','78N'O'O$!;&+  GLO,-- Y<?&.!%J07-1O1OPW1X1X. U  !3:S TTTTT U Ur rg nodes.BinOpct|jtjrRd|jd|jd}|d||fdSdS)NDid you mean '(, )' instead?rgr)rrrrleftrrightrrtrC suggestions r visit_binopzExceptionsChecker.visit_binop!s~ dk5#6 7 7 Yg49+>+>+@+@ggDJDXDXDZDZgggJ   8t:-  X X X X X Y Yr nodes.Comparect|jtjr]d|jddd|jDd}|d||fdSdS)Nr rc3DK|]\}}|VdSr)r)r%r&os rrDz2ExceptionsChecker.visit_compare...s.@@tq!Q[[]]@@@@@@r rrgr) rrrrrrjoinopsrrs r visit_comparezExceptionsChecker.visit_compare(s dk5#6 7 7 YN$)"5"5"7"7NN99@@tx@@@@@NNN    8t:-  X X X X X  Y Yr rXrZr_rcrHrVr]c ||g}t|j}t|jD]@\}}|j[t |js|d|t||dz kr d}|d||tht|jtj r)|d||jj t tt|j}n#tj$rYwxYw|D]E\}} t| tjrt%j| r| j} ||| |t| tjsmd | D} |D]:} | | vr4| jd | j}|d|j|t2;|| r.es:%%%%c5>::%%%%r z is an ancestor class of rZrr]cg|]\}}|Sr"r"r$s rrz5ExceptionsChecker.visit_tryexcept..s&D&D&Dvq#s&D&D&Dr )r rr enumeraterrFr=rrrrBoolOpoprr<rrInstancerrrrr ancestorsr|rr) rtrCexceptions_classes nb_handlersindexrrrrr exc_ancestors previous_excs rvisit_tryexceptz!ExceptionsChecker.visit_tryexcept2s $$T***(*$-(( ' 66F EF ENE7|#"7<00S$$]T$RRRK!O,,IC$$*CD%GL%,779 E  )  # !!%&=gl&K&K!L!LJJ-H(2**OD)!!7#373I>>7%.$6 66w 4PPP%i@@! %%#,#6#6#8#8%%%M ); '=88%1%6"a"aQZQ_"a"aC ,, 2%,\%(+4 - 55i@@ JJ((4!*!('0 )!$666((.!*!('0 )#&D&D&D&D&DD""MF EF Es1!DD%$D%rrrc||jjjvpGd|jvo>|j|jjjvo&|jt jkS)Nr)qnamerrrr|rootrEXCEPTIONS_MODULE)rtrs rrz+ExceptionsChecker._is_overgeneral_exceptionsg OO  !3!J J A).(A$+"4"KKA  %)@@  r )rrp)rCrorrp)rrr'r rr/rrp)rCrrrp)rCr rrp)rCrrrp)rrrr)r#rrrr|rjmsgsoptionsrronly_required_for_messagesrrrrrr rrr*r __classcell__)rxs@rrnrn"s## D D %K:J     G &U%   >>>  >$QQQQ*UUUU",,,,\3333j7U7U7U7Ur&U%&ABBYYYCBY &U%&ABBYYYCBY&U%  KEKEKEKEZ        r rnrrrpcJ|t|dSr)register_checkerrn)rs rregisterr5s% -f5566666r )rrr)r.r/r0r1rr2)r=r>rr)rrrrp)*r __future__rr+r)rcollections.abcrtypingrrrrrr astroid.contextr astroid.typingr r rr pylint.checkersrpylint.interfacesrr pylint.typingr pylint.lintrr-r<rFrj__annotations__rlrr BaseCheckerrnr5r"r rrAs 322""""""%%%%%%%%%%%%%%((((((((((,,,,,,EEEEEEEE!!!!!!--------000000%$$$$$$2222<@*???? w+ w+ w+ w+0 N  9:; 1w+@ Aw+L Mw+V Ww+b cw+t +  M 012 uw+D Ew+P Qw+` aw+r sw+@ Aw+N Ow+\ ]w+wwwwt88888888&&&&&&{&&&R* * * * * * * * Zm m m m m ,m m m ` 777777r