gruns / icecream

🍦 Never use print() to debug again.
MIT License
9.21k stars 187 forks source link

Display Breadcrumbs of classes/methods/functions in IC #174

Open kailukowiak opened 9 months ago

kailukowiak commented 9 months ago

I love using icecream -thanks so much for making and maintaining it- but I'm having some troubles using it. Currently I'm writing a neural net in Flax and every time I call ic() I just get the same method name __call__. This makes it a bit harder to debug. Would you consider adding the ability to include the class or even parent function? For example:

class Class1:
    def __init__(self):
        self.x = 1

    def display(self):
        ic(self.x)
        print(self.x)

class Class2:
    def __init__(self):
        self.x = 2

    def display(self):
        ic(self.x)
        print(self.x)

one = Class1()
one.display()

two = Class2()
two.display()

# ic| 4014262339.py:6 in display()- self.x: 1
# ic| 4014262339.py:14 in display()- self.x: 2
# 1
# 2

Ideally, I'd like to see Class1.display() and Class2.display() in the IC output.

Thanks again.