[Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

Nick Coghlan ncoghlan at gmail.com
Fri Apr 27 08:53:39 EDT 2018


On 27 April 2018 at 21:27, Steven D'Aprano <steve at 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   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180427/8f0589ce/attachment-0001.html>


More information about the Python-ideas mailing list