Skip to content

[Feature Request] Allow ic() to accept keyword arguments for argumentToString customization #221

@liblaf

Description

@liblaf

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 here

Describe 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 output

Additional context

This feature would make icecream more flexible and ergonomic when working with complex data types and custom formatting needs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions