title: Catch NameError during function declaration?
body: <p>I am trying to build an embedded DSL in Python, which involves some customized type that the identifier not in the scope of Python like:</p>
  <pre><code>@convert_to_dsl
  def func(a: ExternType):
      return a
  </code></pre>
  <p><code>convert_to_dsl</code> will parse the function and convert it to my DSL. But, Python will raise <code>NameError</code> since <code>ExternType</code> is not in current module during the function declartion.</p>
  <p>I am wondering how to solve this.</p>
  <p>I import those <code>ExternType</code> as a workaround, but I don't like it since there are many identifiers and they will pollute the current module.</p>
  <p>Is it possible to modify <code>covert_to_dsl</code> as a context manager which will handle the thrown error? (It seems impossible that the function declaration happens before the decoration.)</p>
  <p>Or is there any way to override the default error handling in Python so that I can avoid throwing the <code>NameError</code>?</p>