[Python-ideas] Standard way to get caller name and easy call stack access

Nick Coghlan ncoghlan at gmail.com
Thu Mar 22 09:01:31 CET 2012


Anatoly,

Trying to find out your calling function is hard because well-designed
decoupled code with properly separated concerns *should never care who
is calling it*, so improving the APIs for doing so is an *extremely
low priority task*.

There are some truly exceptional cases where it matters. For those,
the onus is on the developers *implementing those exceptional cases*
to figure out how to do this in a platform independent way (which may
involve conditional code that does different things depending on the
platform). These legitimate use cases are simply too rare for it to be
worthwhile for the various implementations to agree on a standard way
to expose the functionality and promise never to change it.

If all you are trying to do is print some debugging info and you can
use Python 3.2, then use the "stack_info=True" argument to the logging
APIs. That's what it's for. If you can't use Python 3.2, then look at
the way logging does it in 3.2 and see if you can adapt that for your
own needs.

There's no compelling reason that writing helpers for debugging call
stacks needs to be easy. It should definitely be *possible*, but
99.99% of all Python programmers are just going to use the native
debugging facilities of the interpreter, or use those of an IDE that
someone else wrote.

Once again, you're painting with a broad sweeping brush "ah, it's
horrible, it's too hard to do anything worthwhile" (despite the
obvious contradiction that many projects already implement such things
quite effectively) instead of suggesting *small*, *incremental*
changes that might actually improve the status quo.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list