pyagc.utils.filter_kwargs

filter_kwargs(func: Callable, kwargs: dict) dict[source]

Filter keyword arguments based on function signature.

This utility function inspects a function’s signature and returns only the keyword arguments that are valid parameters for that function. This is useful for passing flexible kwargs to functions without worrying about unsupported parameters.

Parameters:
  • func (callable) – The function whose signature will be inspected.

  • kwargs (dict) – Dictionary of keyword arguments to filter.

Returns:

A filtered dictionary containing only the keys that match

the function’s parameter names.

Return type:

dict

Example

>>> def my_func(a, b, c=3):
...     return a + b + c
>>> kwargs = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
>>> filtered = filter_kwargs(my_func, kwargs)
>>> print(filtered)
{'a': 1, 'b': 2, 'c': 3}
>>> my_func(**filtered)
6