From 94b13403aa0bc2f269c7281434eead3bbcdd745e Mon Sep 17 00:00:00 2001 From: JoaquinPugliese Date: Sat, 24 Jun 2023 16:13:42 -0300 Subject: [PATCH] Allow extra arguments to ic call --- icecream/icecream.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/icecream/icecream.py b/icecream/icecream.py index 435518f..697f1f9 100644 --- a/icecream/icecream.py +++ b/icecream/icecream.py @@ -184,8 +184,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 @@ -206,7 +206,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,7 +263,7 @@ def _constructArgumentOutput(self, prefix, context, pairs): def argPrefix(arg): return '%s: ' % arg - pairs = [(arg, self.argToStringFunction(val)) for arg, val in pairs] + 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