Hacking tail-optimization
<p>I've recently discovered the <code>inspect</code> and thought if it's possible to manually remove "outer" frames of the current frame and thus implementing tail-recursion optimization.    </p>

<p><strong>Is it possible? How?</strong></p>

<p>It's not possible. <code>inspect</code> doesn't let you rewrite the stack that way, and in any case, it only gives Python stack frames. Even if you could change how the Python stack frames hook up to each other, the C call stack would be unaffected.</p>

python optimization tail-recursion