get_kwarg_names#
- deeptrack.utils.get_kwarg_names(function: Callable[[...], Any]) list[str]#
Retrieve the names of the keyword arguments accepted by a function.
Retrieves the names of the keyword arguments accepted by function as a list of strings.
Parameters#
- function: Callable[…, Any]
The function whose keyword argument names are to be retrieved.
Returns#
- list[str]
A list of names of keyword arguments the function accepts.
Examples#
from deeptrack.utils import get_kwarg_names
Basic usage:
>>> def f(a, b=1, c=2): ... pass
>>> get_kwarg_names(f) ['a', 'b', 'c']
Functions with only positional arguments:
>>> def g(x, y): ... pass
>>> get_kwarg_names(g) ['x', 'y']
Functions with *args and **kwargs (note: **kwargs are not listed):
>>> def k(*args, alpha=0.1, beta=0.2, **kwargs): ... pass
>>> get_kwarg_names(k) ['alpha', 'beta']
Built-in functions (may return an empty list):
>>> get_kwarg_names(len) ['obj']
Lambda functions:
>>> get_kwarg_names(lambda x, y=5: x + y) ['x', 'y']
Methods (including ‘self’):
>>> class MyClass: ... def method(self, a, b=2): ... pass
>>> get_kwarg_names(MyClass.method) ['self', 'a', 'b']