[Feature Request] Allow `ic()` to accept keyword arguments for `argumentToString` customization
Is your feature request related to a problem?
I really like using icecream for debugging, but currently ic() only accepts positional arguments. It does not provide a way to pass additional keyword arguments that could be used by a custom argumentToString function.
Describe the solution you'd like
I'd like to be able to define a custom argumentToString for special types (e.g., numpy arrays) and pass options to it directly from the ic() call, such as:
@icecream.argumentToString.register(np.ndarray)
def _format_array(arr: np.ndarray, *, short_arrays: bool = True, **_kwargs) -> str:
if short_arrays:
return f"{arr.dtype}{arr.shape}(numpy)"
return repr(arr)
ic(arr) # I want short output here
ic(arr, short_arrays=False) # I want full output hereDescribe alternatives you've considered
Currently, to switch between different formatting behaviors, I must reconfigure the output globally, which is less flexible:
ic.configureOutput(argToStringFunction=format_array)
ic(arr) # short output
ic.configureOutput(argToStringFunction=icecream.argumentToString)
ic(arr) # full outputAdditional context
This feature would make icecream more flexible and ergonomic when working with complex data types and custom formatting needs.
Source: gruns/icecream