bISc@sdZddlZddlmZejZddlZddlmZmZm Z ddl m Z ddl m Z mZmZddlmZdZejdLkZdMZidNd6dOd6dddidPd6fd6dQd6dRd 6dSd$6dTd(6dUd,6dVd06dWd46d5d6d7idXd86fd96dYd=6d>d?d@idZd86fdA6dBdCdDid[d86fdE6Zejd\krydFZndGZdHe fdIYZdJZdKZdS(]sDexceptions handling (raising, catching, exceptions classes) checker iN(tbuiltins(tYEStInstancet unpack_infer(t BaseChecker(tis_emptyt is_raisingtcheck_messages(tIAstroidCheckerccsxxq|jD]f}y|jj}Wntjk r?q nX|tkrT|Vq xt|D] }|VqaWq WdS(s Fully infer the bases of the klass node. This doesn't use .ancestors(), because we need the non-inferable nodes (YES nodes), which can't be retrieved from .ancestors() N(tbasestinfertnexttastroidtInferenceErrorRt infer_bases(tklasstbasetinferit((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pyRs iit ExceptionsBad except clauses order (%s)sbad-except-ordersUsed 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 catched by the most specific handler.tE0701s>Raising %s while only classes, instances or string are allowedsraising-bad-typesUsed when something which is neither a class, an instance or a string is raised (i.e. a `TypeError` will be raised).tE0702sFException context set to something which is not an exception, nor Nonesbad-exception-contextskUsed when using the syntax "raise ... from ...", where the exception context is not an exception, nor None.t minversiontE0703sBRaising a new style class which doesn't inherit from BaseExceptionsraising-non-exceptions^Used when a new style class which doesn't inherit from BaseException is raised.tE0710s8NotImplemented raised - should raise NotImplementedErrorsnotimplemented-raisedsOUsed when NotImplemented is raised instead of NotImplementedErrortE0711sBCatching an exception which doesn't inherit from BaseException: %sscatching-non-exceptionsvUsed when a class which doesn't inherit from BaseException is used as an exception in an except clause.tE0712sRaising a string exceptionsraising-strings'Used when a string exception is raised.tW0701sNo exception type(s) specifieds bare-exceptsRUsed when an except clause doesn't specify exceptions type to catch.tW0702s!Catching too general exception %ss broad-exceptseUsed when an except catches a too general exception, possibly burying unrelated errors.tW0703sExcept doesn't do anythingspointless-excepts^Used when an except clause does nothing but "pass" and there is no "else" clause.tW0704s9Exception doesn't inherit from standard "Exception" classsnonstandard-exceptionsrUsed when a custom exception class is raised but doesn't inherit from the builtin "Exception" class.t maxversiontW0710s;Exception to catch is the result of a binary "%s" operationsbinary-op-exceptionsUsed when the exception to catch is of the form "except A or B:". If intending to catch multiple, rewrite as "except (A, B):"tW0711s=Implicit unpacking of exceptions is not supported in Python 3sunpacking-in-exceptswPython3 will not allow implicit unpacking of exceptions in except clauses. See http://www.python.org/dev/peps/pep-3110/tW0712s-Indexing exceptions will not work on Python 3sindexing-exceptionsSIndexing exceptions will not work on Python 3. Use `exception.args[index]` instead.tW0713t exceptionsRtExceptionsCheckercBseZdZeZdZeZdZdie d6dd6dd6d d j e fd 6ffZ e d d dddddZ dZe ddZe ddZe dddddddZRS(svchecks for * excepts without exception filter * type of raise argument : string, Exceptions, other values R#isovergeneral-exceptionstdefaulttcsvttypestmetavarsGExceptions that will emit a warning when being caught. Defaults to "%s"s, thelpsraising-stringsnonstandard-exceptionsraising-bad-typesraising-non-exceptionsnotimplemented-raisedsbad-exception-contextcCs6|jdkrdStr|jry|jjj}Wntjk rQqX|tkrbdSt |tj r|j dk r|j dd|qqt |tj  rt| r|j dd|qn|j}|j||rdSyt|j}Wntjk r!dSX|j||dS(s$visit raise possibly inferring valueNsbad-exception-contexttnode(texctNonetPY3KtcauseR R R R Rt isinstancetConsttvaluet add_messagetClasstinherit_from_std_ext_check_raise_valueR(tselfR*R.texprR1((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pyt visit_raises2       c Cs+t}t|tjrh|j}t|trF|jdd|q'|jdd|d|jjnt|tj r|j d kst|tj tj tj tjtjfr|jdd|d|j nRt|tj r|j dks/t|tjrEt|jtj rE|jj dkrE|jd d|nt|tjr||jd kr||jdd|nt|ttjfr!t|tr|j}nt|tjrt| r|jj tkr|jr|jd d|q|jd d|q't}nt}|S(sEcheck for bad values, string exception and class inheritance sraising-stringR*sraising-bad-typetargsR,tTruetFalsetNotImplementedsnotimplemented-raisedt%sraising-non-exceptionsnonstandard-exception(sNonesTruesFalse(R:R/R R0R1tstrR2t __class__t__name__tNametnametListtDicttTupletModuletFunctiontCallFunctfunctBinOptopRR3t_proxiedR4troott BUILTINS_NAMEtnewstyleR;(R6R*R7t value_foundR1((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pyR5s> !!    sunpacking-in-exceptcCs8t|jtjtjfr4|jdd|ndS(s@Visit an except handler block and check for exception unpacking.sunpacking-in-exceptR*N(R/RBR RERCR2(R6R*((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pytvisit_excepthandlerssindexing-exceptioncCstyXxQ|jjD]@}t|tjs1qnt|r|jdd|qqWWntjk rodSXdS(s Look for indexing exceptions. sindexing-exceptionR*N(R1R R/R RR4R2R (R6R*tinfered((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pytvisit_subscripts s bare-excepts broad-exceptspointless-exceptsbinary-op-exceptionsbad-except-orderscatching-non-exceptioncCsg}t|j}xt|jD]\}}|dkr|t|jr||j r||jdd|jpu|jdn|jdkr|dkrt |j r|jdd|q||dkrd}|jdd|d|qq%t |jt j r)|jd d|d|jj q%ytt|j}Wnt jk r[q%nXx|D]}|tksct |t j rqcng|jD]} t | t jr| ^q} xO|D]G} | | krd | j|jf}|jdd|jd|qqW|j|jjkry|jjtkry|dkryt |j ry|jd d|jd|jnt| rc|jjtkrct|} td | D} | r|jd d|jd|jfqqcqcW||7}q%WdS(scheck for empty exceptispointless-exceptR*is bare-excepts-empty except clause should always appear lastsbad-except-orderR9sbinary-op-exceptions%s is an ancestor class of %ss broad-exceptcss|]}|tk VqdS(N(R(t.0R((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pys sscatching-non-exceptionN(tlenthandlerst enumerateRtbodytorelseR2R'R,RR/R tBoolOpRKtlistRR RR3t ancestorsRBtconfigtovergeneral_exceptionsRMtEXCEPTIONS_MODULER4RNRtall(R6R*texceptions_classest nb_handlerstindexthandlertmsgtexcsR+tanct exc_ancestorst previous_excR t fully_infered((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pytvisit_tryexceptsR%&"   #"      (R@t __module__t__doc__Rt__implements__RBtMSGStmsgstprioritytOVERGENERAL_EXCEPTIONStjointoptionsRR8R5RQRSRk(((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pyR${s$   ' cCsY|jdkr(|jjtkr(tSx*|jdtD]}t|r;tSq;WtS(sPreturn true if the given class node is subclass of exceptions.Exception Rt BaseExceptiontrecurs(s Exceptions BaseException(RBRMR_R:R\R;R4(R*tparent((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pyR4$s cCs|jt|dS(s-required method to auto register this checkerN(tregister_checkerR$(tlinter((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pytregister0s(ii(s Exception(sBad except clauses order (%s)sbad-except-ordersUsed 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 catched by the most specific handler.(s>Raising %s while only classes, instances or string are allowedsraising-bad-typesUsed when something which is neither a class, an instance or a string is raised (i.e. a `TypeError` will be raised).(ii(sBRaising a new style class which doesn't inherit from BaseExceptionsraising-non-exceptions^Used when a new style class which doesn't inherit from BaseException is raised.(s8NotImplemented raised - should raise NotImplementedErrorsnotimplemented-raisedsOUsed when NotImplemented is raised instead of NotImplementedError(sBCatching an exception which doesn't inherit from BaseException: %sscatching-non-exceptionsvUsed when a class which doesn't inherit from BaseException is used as an exception in an except clause.(sRaising a string exceptionsraising-strings'Used when a string exception is raised.(sNo exception type(s) specifieds bare-exceptsRUsed when an except clause doesn't specify exceptions type to catch.(s!Catching too general exception %ss broad-exceptseUsed when an except catches a too general exception, possibly burying unrelated errors.(sExcept doesn't do anythingspointless-excepts^Used when an except clause does nothing but "pass" and there is no "else" clause.(ii(s;Exception to catch is the result of a binary "%s" operationsbinary-op-exceptionsUsed when the exception to catch is of the form "except A or B:". If intending to catch multiple, rewrite as "except (A, B):"(ii(ii(ii(Rmtsystlogilab.common.compatRR@RNR RRRtpylint.checkersRtpylint.checkers.utilsRRRtpylint.interfacesRRt version_infoR-RrRoR_R$R4Rz(((sT/Users/jacob/code/ruby/exercism-analysis/vendor/python/pylint/checkers/exceptions.pyts