cool-RR / PySnooper

Never use print for debugging again
MIT License
16.34k stars 951 forks source link

fix #195 #196

Closed yaelmi3 closed 3 years ago

yaelmi3 commented 3 years ago

Fix '_thread._local' object has no attribute 'depth' raised by snooper if there's exception upon calling snooped func by initializing thread_global dict with depth when entering the trace() func

cool-RR commented 3 years ago

Good job.

@yaelmi3 : As you can see, your test is failing on Python 2 because the exception message is different. Please change your test to not check the exception message at all. Confirming it's a TypeError is sufficient.

@alexmojaki : It looks like Yael took the thread_global.__dict__.setdefault('depth', -1) line to the top of trace, which solved the problem. Do you think it'll make more sense to put it in __enter__ instead? Any other insights would be appreciated.

cool-RR commented 3 years ago

@yaelmi3 Great, now waiting for Alex's input.

alexmojaki commented 3 years ago

Do you think it'll make more sense to put it in __enter__ instead?

I guess so. Should be a bit faster.

cool-RR commented 3 years ago

@yaelmi3 mind moving that line?

yaelmi3 commented 3 years ago

Done

cool-RR commented 3 years ago

@yaelmi3 Congrats on your first contribution. I added you to the list of authors and made a new release with your bugfix :+1: