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>For example, this function has one jump:</p>

<pre><code>def f(x):
    if x &gt; 0:     # This will jump to "return 2" if not x &gt; 0
        return 1
    else:
        return 2
</code></pre>

<p>See it here:</p>

<pre><code>&gt;&gt;&gt; dis.disco(f.__code__)
  2           0 LOAD_FAST                0 (x)
              3 LOAD_CONST               1 (0)
              6 COMPARE_OP               4 (&gt;)
              9 POP_JUMP_IF_FALSE       16

  3          12 LOAD_CONST               2 (1)
             15 RETURN_VALUE

  5     &gt;&gt;   16 LOAD_CONST               3 (2)
             19 RETURN_VALUE
             20 LOAD_CONST               0 (None)
             23 RETURN_VALUE
</code></pre>

<p>There is one jump to 16 in <code>9 POP_JUMP_IF_FALSE       16</code></p>

<p>Therefore, <code>findlabels</code> finds that jump target:</p>

<pre><code>&gt;&gt;&gt; dis.findlabels(f.__code__.co_code)
[16]
</code></pre>

python