Skip to content

Commit

Permalink
changed positional argument name in filter_kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee authored and craffel committed Feb 7, 2016
1 parent 814faaf commit 8e7a8c8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mir_eval/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,28 +684,28 @@ def validate_events(events, max_time=30000.):
raise ValueError('Events should be in increasing order.')


def filter_kwargs(function, *args, **kwargs):
def filter_kwargs(_function, *args, **kwargs):
"""Given a function and args and keyword args to pass to it, call the function
but using only the keyword arguments which it accepts. This is equivalent
to redefining the function with an additional \*\*kwargs to accept slop
keyword args.
Parameters
----------
function : function
_function : callable
Function to call. Can take in any number of args or kwargs
"""
# Get the list of function arguments
func_code = six.get_function_code(function)
func_code = six.get_function_code(_function)
function_args = func_code.co_varnames[:func_code.co_argcount]
# Construct a dict of those kwargs which appear in the function
filtered_kwargs = {}
for kwarg, value in list(kwargs.items()):
if kwarg in function_args:
filtered_kwargs[kwarg] = value
# Call the function with the supplied args and the filtered kwarg dict
return function(*args, **filtered_kwargs)
return _function(*args, **filtered_kwargs)


def intervals_to_durations(intervals):
Expand Down

0 comments on commit 8e7a8c8

Please sign in to comment.