gruns / icecream

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

Print the value without the argument when accessing/analysing source code fails #97

Open alexmojaki opened 3 years ago

alexmojaki commented 3 years ago

When ic() doesn't work it just says:

ic| Error: Failed to access the underlying source code for analysis. Was ic() invoked in a REPL (e.g. from the command line), a frozen application (e.g. packaged with PyInstaller), or did the underlying source code change during execution?

To make ic() usable in cases where the same code works under some conditions but not others (e.g. in https://github.com/gruns/icecream/issues/95#issuecomment-874344435 where it doesn't work with pdb but works otherwise), I think it should:

  1. Only show the message once, perhaps as a python warning.
  2. Always print out the value even without the argument, similar to snoop.pp, e.g:
import snoop
exec("snoop.pp(1+2)")
exec("snoop.pp(3+4, 5+6)")
00:12:53.21 LOG:
00:12:53.21 .... <argument> = 3
00:12:53.21 LOG:
00:12:53.21 .... <argument 1> = 7
00:12:53.21 .... <argument 2> = 11

Perhaps it could also automatically act as if includeContext=true in such cases to compensate for the missing argument source.