diff --git a/icecream/icecream.py b/icecream/icecream.py index 7cc1c29..3d38c37 100644 --- a/icecream/icecream.py +++ b/icecream/icecream.py @@ -183,8 +183,8 @@ def unregister(cls): @singledispatch -def argumentToString(obj): - s = DEFAULT_ARG_TO_STRING_FUNCTION(obj) +def argumentToString(obj, **kwargs): + s = DEFAULT_ARG_TO_STRING_FUNCTION(obj, **kwargs) s = s.replace('\\n', '\n') # Preserve string newlines in output. return s @@ -205,7 +205,9 @@ def __init__(self, prefix=DEFAULT_PREFIX, self.argToStringFunction = argToStringFunction self.contextAbsPath = contextAbsPath - def __call__(self, *args): + def __call__(self, *args, **kwargs): + self.kwargs = kwargs + if self.enabled: callFrame = inspect.currentframe().f_back self.outputFunction(self._format(callFrame, *args)) @@ -261,11 +263,11 @@ def _constructArgumentOutput(self, prefix, context, pairs): def argPrefix(arg): return '%s: ' % arg - pairs = [(arg, self.argToStringFunction(val)) for arg, val in pairs] - # For cleaner output, if is a literal, eg 3, "a string", - # b'bytes', etc, only output the value, not the argument and the - # value, because the argument and the value will be identical or - # nigh identical. Ex: with ic("hello"), just output + pairs = [(arg, self.argToStringFunction(val, **self.kwargs)) for arg, val in pairs] + # For cleaner output, if is a literal, eg 3, "string", b'bytes', + # etc, only output the value, not the argument and the value, as the + # argument and the value will be identical or nigh identical. Ex: with + # ic("hello"), just output # # ic| 'hello', #