On Fri, Apr 27, 2018 at 10:53:39PM +1000, Nick Coghlan wrote:
On 27 April 2018 at 21:27, Steven D'Aprano <steve@pearwood.info> wrote:
Obviously dp() would have to be magic. There's no way that I know of for a Python function to see the source code of its own arguments. I have no idea what sort of deep voodoo would be required to make this work. But if it could work, wow, that would really be useful. And not just for beginners.
If you relax the enhancement to just noting the line where the debug print came from, it doesn't need to be deep compiler magic - the same kind of stack introspection that warnings and tracebacks use would suffice.
I don't think this is worth bothering with if we relax the enhancement to just the line. As such, there are already ways to get the desired result, and people can just add it to the startup file or personal toolbox module. It doesn't need to be a builtin. Maybe in the std lib? from pdb import debugprint as dp perhaps, but not a builtin. Although it will require compiler support, I think that being able to drill down to the level of individual expressions would be a fantastic aid to debugging. -- Steve