Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extra arguments to ic call #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions icecream/icecream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
Expand Down Expand Up @@ -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 <arg> 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 <arg> 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',
#
Expand Down