title: Programmatically create function specification
body: <p>For my own entertainment, I was wondering how to achieve the following:</p>
  
  <pre><code>functionA = make_fun(['paramA', 'paramB'])
  functionB = make_fun(['arg1', 'arg2', 'arg3'])
  </code></pre>
  
  <p>equivalent to</p>
  
  <pre><code>def functionA(paramA, paramB):
      print(paramA)
      print(paramB)
  
  def functionB(arg1, arg2, arg3):
      print(arg1)
      print(arg2)
      print(arg3) 
  </code></pre>
  
  <p>This means the following behaviour is required:</p>
  
  <pre><code>functionA(3, paramB=1)       # Works
  functionA(3, 2, 1)           # Fails
  functionB(0)                 # Fails
  </code></pre>
  
  <p>The focus of the question is on the variable argspec - I comfortable creating the function body using the usual decorator techniques.</p>
  
  <p>For those that are interested, I was playing around with trying to programmatically create classes like the following. Again the difficulty is in generating the <code>__init__</code> method with programmatic parameters - the rest of the class appears straightforward using a decorator or maybe a metaclass.</p>
  
  <pre><code>class MyClass:
      def __init__(self, paramA=None, paramB=None):
          self._attr = ['paramA', 'paramB']
          for a in self._attr:
              self.__setattr__(a, None)
  
      def __str__(self):
          return str({k:v for (k,v) in self.__dict__.items() if k in self._attributes})
  </code></pre>