[Python-ideas] Standard way to get caller name and easy call stack access
jimjjewett at gmail.com
Tue Mar 27 22:06:51 CEST 2012
On Tue, Mar 27, 2012 at 12:32 PM, Sven Marnach <sven at marnach.net> wrote:
> ... Steven D'Aprano suggested giving full access to the function
> objects instead. The function object cannot be referenced in the
> code object, though, because this would create reference cycles in
Not if you use weakrefs.
And frankly, even without weakrefs, so what? Functions are typically
immortal; waiting until gc to collect the oddballs isn't such a terrible cost.
> It *can* be referenced in the frame object (and this way,
> the change would only affect implementations having stack frames in
> the first place).
If the name needs to be available, that affects all implementations, perhaps
even to the point of requiring them to create pseudo-frames, or causing
them to add the equivalent of an always-active trace function. So yes,
there is cost.
> This would only partially solve the use case of
> including qualified names in the traceback, since it only covers
> functions, not modules and classes. (For classes, we can't do
> something like this anyway, since the class object does not yet
> exist while the class body code executes.)
Both the name and the namespace do, these may serve as a proxies
for most uses. Or repurpose the super() magic.
More information about the Python-ideas