Open jfthuong opened 2 years ago
neat idea!
how often do you find yourself doing this?
I think it would be straightforward to make the existing enable()
and disable()
return context managers, so they could be used like this, without affecting existing usage. So ic.enable()
would immediately set enabled = True
while returning an object whose __exit__
sets enabled = False
.
Sounds a little bit to simple because then you can't nest this, i.e. if any code call_my_super_function_without_icecream()
uses, does the same to disable debugging output for some chunk of code the __exit__
there would enable too early. Maybe a counter that keeps track of how many nested disabled blocks are currently active would solve that.
Good point. The implementation would need to be slightly more complicated than what I described. Still seems doable without changing the existing API or creating new functions or arguments.
neat idea!
how often do you find yourself doing this?
Actually, I just discovered 🍦 few days ago so ... not that often! :) But I believed it would be interesting.
@jfthuong this is an interesting idea and would be great to support!
do you have the time and/or inclination to build this with tests? if so, that'd be awesome 🙌
Sounds a little bit to simple because then you can't nest this, i.e. if any code call_my_super_function_without_icecream() uses, does the same to disable debugging output for some chunk of code the exit there would enable too early.
if this feature would be used heavily -- which im still not sure if would be -- then nesting support would be nice
but as i dont think it will be used heavily, i'm ok to ship ic.enable()
and ic.disable()
as context managers without nesting support. and we would then note:
shipped and useful but imperfect is better than perfect but not shipped. and i think most people would use it without nesting
This can also be achieved by creating different instances for different purposes:
from icecream import IceCreamDebugger
ic1 = IceCreamDebugger()
ic2 = IceCreamDebugger()
ic1.disable()
x = 3
y = 4
ic1(x)
ic2(y)
will only produce ic| y: 4
It could be nice to temporarily enable/disable
icecream
with something like:To disable the icecream printing temporarily.