[Python-ideas] Storing a reference to the function object (if any) inside frame objects

Nick Coghlan ncoghlan at gmail.com
Thu May 4 11:23:19 EDT 2017


On 4 May 2017 at 18:59, Nathaniel Smith <njs at pobox.com> wrote:
> Hi all,
>
> Currently, given a frame object (e.g. from sys._getframe or
> inspect.getouterframes), there's no way to get back to the function
> object that created it. This creates an obstacle for various sorts of
> introspection. In particular, in the unusual but real situation where
> you need to "mark" a function in a way that can be detected via stack
> introspection, then the natural way to do that – attaching an
> attribute to the function object – doesn't work. Instead, you have to
> mangle the frame's locals.

Eric Snow put together a mostly working patch for this quite some time
ago: http://bugs.python.org/issue12857

It needs some naming adjustments to better account for generators and
coroutines, and rebasing against a recent version of the tree, but I
don't see any major barriers to getting the change made other than
someone actually working through all the nitty gritty details of
finalising the patch.

Cheers,
Nick.

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


More information about the Python-ideas mailing list