diff --git a/README.md b/README.md index 778e044..122e271 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ +This is a fork repo of [gruns](https://github.com/gruns)'s [icecream](https://github.com/gruns/icecream). + +Refactor implementation method of `ic`, changing it from an instance to a function, improving visibility and intuitiveness in the users' IDE. + +Installing this fork with pip: +``` +$ pip install git+https://github.com/YunfangHou/icecream.git +``` + +Below is the original readme file. +

icecream

diff --git a/icecream/icecream.py b/icecream/icecream.py index 7cc1c29..9a33b51 100644 --- a/icecream/icecream.py +++ b/icecream/icecream.py @@ -205,19 +205,19 @@ def __init__(self, prefix=DEFAULT_PREFIX, self.argToStringFunction = argToStringFunction self.contextAbsPath = contextAbsPath - def __call__(self, *args): - if self.enabled: - callFrame = inspect.currentframe().f_back - self.outputFunction(self._format(callFrame, *args)) + # def __call__(self, *args): + # if self.enabled: + # callFrame = inspect.currentframe().f_back + # self.outputFunction(self._format(callFrame, *args)) - if not args: # E.g. ic(). - passthrough = None - elif len(args) == 1: # E.g. ic(1). - passthrough = args[0] - else: # E.g. ic(1, 2, 3). - passthrough = args + # if not args: # E.g. ic(). + # passthrough = None + # elif len(args) == 1: # E.g. ic(1). + # passthrough = args[0] + # else: # E.g. ic(1, 2, 3). + # passthrough = args - return passthrough + # return passthrough def format(self, *args): callFrame = inspect.currentframe().f_back @@ -370,4 +370,20 @@ def configureOutput(self, prefix=_absent, outputFunction=_absent, self.contextAbsPath = contextAbsPath -ic = IceCreamDebugger() + def ic_aux(self, *args): + if self.enabled: + callFrame = inspect.currentframe().f_back.f_back + self.outputFunction(self._format(callFrame, *args)) + + if not args: # E.g. ic(). + passthrough = None + elif len(args) == 1: # E.g. ic(1). + passthrough = args[0] + else: # E.g. ic(1, 2, 3). + passthrough = args + + return passthrough + +def ic(*args): + icd_instance = IceCreamDebugger() + icd_instance.ic_aux(*args)