Building a decorator with three parameters - closure not working in Python 2.x
<pre><code>def ensure_type(parameter_name, the_type, type_converter_fn=None):
   def decorator(fn):
      def wrapped(self, *args, **kwargs):

         if not type_converter_fn: # fails here
            type_converter_fn = the_type

         return fn(self, *args, **kwargs)
      return wrapped
   return decorator
</code></pre>

<p>When stepping through the <code>wrapped</code> function the <code>parameter_name</code> and <code>the_type</code> closure variables are correctly bound but <code>type_converter_fn</code> is not. This happens regardless of whether <code>ensure_type</code> is called with or without that optional parameter and it also happens if I make the parameter mandatory.</p>

<p>Why do the first two parameters work whilst the third never gets assigned?</p>

<p>For reference, I get an exception on this line - <code>if not type_converter_fn</code> saying that it has been referenced before assignment.</p>
