def generate_accepted_kwargs(function, *named_arguments):
 if (hasattr(function, '__code__') and takes_kwargs(function)):
  function_takes_kwargs = True
  function_takes_arguments = []
 else:
  function_takes_kwargs = False
  function_takes_arguments = takes_arguments(function, *named_arguments)
 def accepted_kwargs(kwargs):
  if function_takes_kwargs:
   return kwargs
  elif function_takes_arguments:
   return {key: value for (key, value) in kwargs.items() if (key in function_takes_arguments)}
  else:
   return {}
 return accepted_kwargs

def generate_accepted_kwargs ( function , * named_arguments ) : if ( hasattr ( function , '__code__' ) and takes_kwargs ( function ) ) : function_takes_kwargs = True function_takes_arguments = [ ] else : function_takes_kwargs = False function_takes_arguments = takes_arguments ( function , * named_arguments ) def accepted_kwargs ( kwargs ) : if function_takes_kwargs : return kwargs elif function_takes_arguments : return { key : value for ( key , value ) in kwargs . items ( ) if ( key in function_takes_arguments ) } else : return { } return accepted_kwargs
dynamically creates a function that when called with dictionary of arguments will produce a kwarg thats compatible with the supplied function .