What does dis.findlabels() do?
<p>I was playing around with the <code>dis</code> library to gather information about a function (like what other functions it called).  The documentation for <a href="https://docs.python.org/2/library/dis.html#dis.findlabels" rel="nofollow"><code>dis.findlabels</code></a> sounds like it would return other function calls, but I've tried it with a handful of functions and it always returns an empty list.</p>

<blockquote>
<pre><code>dis.findlabels(code)

Detect all offsets in the code object code which
are jump targets, and return a list of these offsets.
</code></pre>
</blockquote>

<p>What is this function <em>supposed</em> to do and <em>how</em> would you use it?</p>

<p>The jump targets are annotated by <code>&gt;&gt;</code> in disassembly output.</p>

<p>For example, in:</p>

<pre><code>def f(i):
    if i == 1:
        return 1
    elif i == 2:
        return 2
</code></pre>

<p><code>dis.dis(f)</code> shows:</p>

<pre><code>  2           0 LOAD_FAST                0 (i)
              3 LOAD_CONST               1 (1)
              6 COMPARE_OP               2 (==)
              9 POP_JUMP_IF_FALSE       16

  3          12 LOAD_CONST               1 (1)
             15 RETURN_VALUE        

  4     &gt;&gt;   16 LOAD_FAST                0 (i)
             19 LOAD_CONST               2 (2)
             22 COMPARE_OP               2 (==)
             25 POP_JUMP_IF_FALSE       32

  5          28 LOAD_CONST               2 (2)
             31 RETURN_VALUE        
        &gt;&gt;   32 LOAD_CONST               0 (None)
             35 RETURN_VALUE        
</code></pre>

<p>And <code>dis.findlabels(f.__code__.co_code)</code> returns <code>[16, 32]</code>.</p>

python