Up: Tail Recursion [Contents][Index]
Although Python is claimed to be “properly” tail-recursive, some might dispute this, since there are situations where tail recursion is inhibited:
catch
or
unwind-protect
, or
block
or tagbody
and the block name or go
tag has been closed over.
These dynamic extent binding forms inhibit tail recursion because they allocate stack space to represent the binding. Shallow-binding implementations of dynamic scoping also require cleanup code to be evaluated when the scope is exited.
In addition, optimization of tail-recursive calls is inhibited when
the debug
optimization quality is greater than 2
(see debugger-policy.)