title: store field requirements before calling python function?
body: <p>I've got a huge dictionary with a lot of keys. There are certain fields I need to use to compute KPI's. Is there a way to store the required fields for the KPI's calculations and drop all the others? Ideally, I just want to do this on the read so I don't even load these fields if I am not going to use them. Some users will use these functions directly so I don't want to wrap them in a class which will have to be instantiated while others will call several KPIs all at once.</p>
  <pre class="lang-py prettyprint-override"><code>data = {
    A : some values...
    .
    . 
    .
    Z : some values... 
  }
  
  def foo(dict): 
    # requires field A
  
  def bar(dict): 
    # requires field B
  
  
  kpis_to_calculate = [foo, bar]
  requirements = set(requirements(foo) -&gt; returns A, requirements(bar) -&gt; returns B)
  
  min_data_needed = filter(data, requirements)
  
  </code></pre>
  <p>One way I came up with to do this was to wrap the functions e.g. but this solution is ugly</p>
  <pre><code>
  def _foo(dict): 
    # requires field A
  
  def _bar(dict): 
    # requires field B
  
  foo = setattr(_foo, '__requires__', 'A')
  bar = setattr(_bar, '__requires__', 'B')
  
  kpis = [foo, bar]
  requires = [requirement for requirement in func.__requires__ for func in kpis]
  
  # only loads fields needed
  load(data_src, required_fields=requires)
  </code></pre>