title: Ignore additional keyword arguments in python
body: <p>Imagine I have a function like</p>
  
  <pre><code>def foo(x):
      ...
  </code></pre>
  
  <p>When I call it with the dictionary <code>{ 'x': 42, 'y': 23 }</code> as keyword arguments I get an <code>TypeError</code>:</p>
  
  <pre><code>&gt;&gt;&gt; foo(**{ 'x': 42, 'y': 23 })
  ...
  TypeError: foo() got an unexpected keyword argument 'y'
  </code></pre>
  
  <p>Is there a good way to make a function call with keyword arguments where additional keyword arguments are just ignored?</p>
  
  <p><strong>My solution so far:</strong> I can define a helper function:</p>
  
  <pre><code>import inspect
  
  def call_with_kwargs(func, kwargs):
      params = inspect.getargspec(func).args
  
      return func(**{ k: v for k,v in kwargs.items() if k in params})
  </code></pre>
  
  <p>Now I can do</p>
  
  <pre><code>&gt;&gt;&gt; call_with_kwargs(foo, { 'x': 42, 'y': 23 })
  42
  </code></pre>
  
  <p>Is there a better way?</p>