title: How do you implement __str__ for a function?
body: <p>Given a function <code>foo</code>:</p>
  
  <pre><code>def foo(x):
       pass
  </code></pre>
  
  <p>Printing its representation by invoking <code>str</code> or <code>repr</code> gives you something boring like this: </p>
  
  <pre><code>str(foo)
  '&lt;function foo at 0x119e0c8c8&gt;'
  </code></pre>
  
  <p>I'd like to know if it is possible to override a function's <code>__str__</code> method to print something else. Essentially, I'd like to do:</p>
  
  <pre><code>str(foo)
  "I'm foo!'
  </code></pre>
  
  <p>Now, I understand that the description of a function should come from <code>__doc__</code> which is the function's docstring. However, this is merely an experiment.</p>
  
  <p>In attempting to figure out a solution to this problem, I came across implementing <code>__str__</code> for <em><code>classes</code></em>: <a href="https://stackoverflow.com/questions/8144026/how-to-define-a-str-method-for-a-class">How to define a __str__ method for a class?</a> </p>
  
  <p>This approach involved defining a metaclass with an <code>__str__</code> method, and then attempting to assign the <code>__metaclass__</code> hook in the actual class.</p>
  
  <p>I wondered whether the same could be done to the class <code>function</code>, so here's what I tried - </p>
  
  <pre><code>In [355]: foo.__class__
  Out[355]: function
  
  In [356]: class fancyfunction(type):
       ...:     def __str__(self):
       ...:         return self.__name__
       ...:     
  
  In [357]: foo.__class__.__metaclass__ = fancyfunction
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  </code></pre>
  
  <p>I figured it wouldn't work, but it was worth a shot! </p>
  
  <p>So, what's the best way to implement <code>__str__</code> for a function?</p>