Functional
Supporting utilities for manipulating arguments of functions.
free_arguments(fun)
¶
Computes the set of free arguments for a function or functools.partial object.
All arguments of a function are considered free unless they are set by a
partial. For example, if f = partial(g, a=1)
, then a
is not a free
argument of f
.
PARAMETER | DESCRIPTION |
---|---|
fun |
A callable or a [partial object][]. |
RETURNS | DESCRIPTION |
---|---|
Set[str]
|
The set of free arguments of |
New in version 0.7.0
Source code in src/pydvl/utils/functional.py
maybe_add_argument(fun, new_arg)
¶
Wraps a function to accept the given keyword parameter if it doesn't already.
If fun
already takes a keyword parameter of name new_arg
, then it is
returned as is. Otherwise, a wrapper is returned which merely ignores the
argument.
PARAMETER | DESCRIPTION |
---|---|
fun |
The function to wrap
TYPE:
|
new_arg |
The name of the argument that the new function will accept (and ignore).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
A new function accepting one more keyword argument. |
Changed in version 0.7.0
Ability to work with partials.
Source code in src/pydvl/utils/functional.py
Created: 2023-12-21