Find out into how many values a return value will be unpacked
<p>I have a function, and when it is called, I'd like to know what the return value is going to be assigned to - specifically when it is unpacked as a tuple. So:</p>

<pre><code>a = func()         # n = 1
</code></pre>

<p>vs.</p>

<pre><code>a, b, c = func()   # n = 3
</code></pre>

<p>I want to use the value of <code>n</code> in <code>func</code>. There must be some magic with <code>inspect</code> or <code>_getframe</code> that lets me do this. Any ideas?</p>

<hr>

<p>Disclaimer (because this seems to be neccessary nowadays): I know this is funky, and bad practice, and shouldn't be used in production code. It actually looks like something I'd expect in Perl. I'm not looking for a different way to solve my supposed "actual" problem, but I'm curious how to achive what I asked for above. One cool usage of this trick would be:</p>

<pre><code>ONE, TWO, THREE = count()
ONE, TWO, THREE, FOUR = count()
</code></pre>

<p>with</p>

<pre><code>def count():
    n = get_return_count()
    if not n:
        return
    return range(n)
</code></pre>
