title: Best way to add attributes to a Python function
body: <p>Take the simple case of a Python function which evaluates a mathematical function:</p>
  
  <pre><code>def func(x, a, b, c):
      """Return the value of the quadratic function, ax^2 + bx + c."""
  
      return a*x**2 + b*x + c
  </code></pre>
  
  <p>Suppose I want to "attach" some further information in the form of a function attribute. For example, the LaTeX representation. I know that thanks to <a href="https://www.python.org/dev/peps/pep-0232/#examples" rel="noreferrer">PEP232</a> I can do this outside the function definition:</p>
  
  <pre><code>def func(x, a, b, c):
      return a*x**2 + b*x + c
  func.latex = r'$ax^2 + bx + c$'
  </code></pre>
  
  <p>but I'd like to do it within the function definition itself. If I write</p>
  
  <pre><code>def func(x, a, b, c):
      func.latex = r'$ax^2 + bx + c$'
      return a*x**2 + b*x + c
  </code></pre>
  
  <p>this certainly works, but <em>only after</em> I've called the <code>func</code> for the first time (because Python is "lazy" in executing functions(?))</p>
  
  <p>Is my only option to write a callable class?</p>
  
  <pre><code>class MyFunction:
       def __init__(self, func, latex):
           self.func = func
           self.latex = latex
  
       def __call__(self, *args, **kwargs):
           return self.func(*args, **kwargs)
  
  func = MyFunction(lambda x,a,b,c: a*x**2+b*x+c, r'$ax^2 + bx + c$')
  </code></pre>
  
  <p>Or is there a feature of the language that I'm overlooking to do this neatly?</p>