On 27 April 2018 at 21:27, Steven D'Aprano <st...@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. (Stack
introspection to find the caller's module, filename and line number,
linecache to actually retrieve the line if we want to print that).

Cheers,
Nick.

P.S. While super() is a *little* magic, it isn't *that* magic - it gets
converted from "super()" to "super(name_of_first_param, __class__)". And
even that limited bit of magic has proven quirky enough to be a recurring
source of irritation when it comes to interpreter maintenance.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to