gruns / icecream

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

Have ic() output class name as well #119

Open leotrs opened 2 years ago

leotrs commented 2 years ago

The following

class MyClass:
    def method(self):
        ic()

MyClass().method()

prints something along the lines of ic| test.py:3 in method() at 10:00:24.509. Is there a way to include the class name and get this instead? ic| test.py:3 in MyClass.method() at 10:00:24.509

alexmojaki commented 2 years ago

Yes. In this code:

https://github.com/gruns/icecream/blob/58fb2f454e7b0c7d00946f5cd885bb9a933c1e69/icecream/icecream.py#L329-L335

Using https://github.com/alexmojaki/executing#getting-the-__qualname__-of-the-current-function to get the qualname for parentFunction should work.

leotrs commented 2 years ago

Great! Could you please provide an example of how to make ic use that instead than the default behavior?

alexmojaki commented 2 years ago

No I'm suggesting how this feature could be added to the library.

Loriasun commented 2 years ago

@alexmojaki Hi there! I am new to ice cream and GitHub but I would love to work on this issue as my first issue! Would you like to offer any suggestions! Thank you!

alexmojaki commented 2 years ago

I think the above comment is sufficient. Start by making sure you understand the existing _getContext code, and then how to get the qualname from executing in isolation (i.e. separately from icecream).