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

Enhance IceCream Debugger to Log Local Scope Variables #202

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nbys
Copy link

@nbys nbys commented Jan 13, 2025

This PR enhances ic() when called without arguments, providing insights into the current execution context:
• Local variables in the caller’s scope are extracted using callFrame.f_locals.
• Special variables (e.g., name, file) are excluded from the output.
• Local scope variables are merged with the explicitly passed arguments for a comprehensive debugging output.

@nbys
Copy link
Author

nbys commented Jan 13, 2025

Hi @gruns, before I proceed with this PR, could you please let me know if you find this idea appropriate and suitable for your project?

@salabim
Copy link

salabim commented Jan 13, 2025

Nice idea. But ...
Can't a user do more or less the same with

ic(locals())

?

@nbys
Copy link
Author

nbys commented Jan 13, 2025

@salabim As you can see, I removed built-ins and ic itself from the output, which makes it clearer. However, you’re right; there’s not much difference overall. To be honest, I expected ic() with no arguments to have this behavior by default—printing all local variables.

@salabim
Copy link

salabim commented Jan 13, 2025

A much better solution is arguably something like
ic(locals) .
That makes it possible to use it anywhereand with all options.
I have implemented this in 'the other' Python debugger package. Have look at my repo to see how that's done there.

@nbys
Copy link
Author

nbys commented Jan 13, 2025

A much better solution is arguably something like ic(locals)

Thank you for your input @salabim ! While I understand the flexibility of using ic(locals()) to explicitly print all local variables, I believe that having ic() print the current scope by default provides a more intuitive debugging experience. It aligns with the expectation of having quick insights without additional boilerplate.

That said, I’m curious—are you actively maintaining or contributing to this project?

@salabim
Copy link

salabim commented Jan 13, 2025

Please note that I didn't propose
ic(locals())
but
ic(locals)
, which allows a nice filtered output of pairs of local variables with their values.

No, I am not a maintainer of icecream as I don't agree with some fundamental design choices, particularly the API.
That's why I have developped and maintain my own debug/print/benchmark module, which supports indeed the locals (and globals) functionality. Feel free to see how I implemented it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants