Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess a solution could be only imprecise because of lack of static typing rules.</p> <p>I'm not aware of some tool that checks exceptions, but you could come up with your own tool matching your needs (a good chance to play a little with static analysis).</p> <p>As a first attempt, you could write a function that builds an AST, finds all <code>Raise</code> nodes, and then tries to figure out common patterns of raising exceptions (e. g. calling a constructor directly)</p> <p>Let <code>x</code> be the following program:</p> <pre><code>x = '''\ if f(x): raise IOError(errno.ENOENT, 'not found') else: e = g(x) raise e ''' </code></pre> <p>Build the AST using the <code>compiler</code> package:</p> <pre><code>tree = compiler.parse(x) </code></pre> <p>Then define a <code>Raise</code> visitor class:</p> <pre><code>class RaiseVisitor(object): def __init__(self): self.nodes = [] def visitRaise(self, n): self.nodes.append(n) </code></pre> <p>And walk the AST collecting <code>Raise</code> nodes:</p> <pre><code>v = RaiseVisitor() compiler.walk(tree, v) &gt;&gt;&gt; print v.nodes [ Raise( CallFunc( Name('IOError'), [Getattr(Name('errno'), 'ENOENT'), Const('not found')], None, None), None, None), Raise(Name('e'), None, None), ] </code></pre> <p>You may continue by resolving symbols using compiler symbol tables, analyzing data dependencies, etc. Or you may just deduce, that <code>CallFunc(Name('IOError'), ...)</code> "should definitely mean raising <code>IOError</code>", which is quite OK for quick practical results :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload