Coverage for signals/utils/inspect.py: 93%

1 import functools

2 import inspect

3

4

5@functools.lru_cache(maxsize=512)

6 def _get_func_parameters(func, remove_first):

7 parameters = tuple(inspect.signature(func).parameters.values())

8 if remove_first:

9 parameters = parameters[1:]

10 return parameters

11

12

13 def _get_callable_parameters(meth_or_func):

14 is_method = inspect.ismethod(meth_or_func)

15 func = meth_or_func.__func__ if is_method else meth_or_func

16 return _get_func_parameters(func, remove_first=is_method)

17

18

19 def func_accepts_kwargs(func):

20 """Return True if function 'func' accepts keyword arguments **kwargs."""

21 return any(p for p in _get_callable_parameters(func) if p.kind == p.VAR_KEYWORD)