[New-bugs-announce] [issue12857] Expose called function on frame object

Eric Snow report at bugs.python.org
Tue Aug 30 07:54:27 CEST 2011

New submission from Eric Snow <ericsnowcurrently at gmail.com>:

This patch adds f_func to PyFrameObject and sets it for functions that get called (in PyFrame_New).  For classes and modules it is set to None.  The difference in performance was not noticable, as far as I could tell.  However, I am willing to do more than just time 'make test' a few times if there is any concern.

A couple weeks ago a thread on python-ideas centered on the subject matter of PEP 3130[1].  The discussion started with, and mainly involved, the idea of adding __function__ to the frame locals during execution of the function.  __function__ would point to the function that was called, which had resulted in the frame.

I spent quite a bit of time getting this to work using a closure, but the result was overkill.  It also made it too easy to use __function__ for recursion, which Guido did not like (and I agree).

At this point it dawned on me that it would be much simpler to just add the called function to the frame object.  This patch is the result.  In the end it is much more efficient than the locals approach I had been taking.

[1] http://mail.python.org/pipermail/python-ideas/2011-August/011062.html

components: Interpreter Core
files: called_function.diff
keywords: patch
messages: 143201
nosy: eric.snow
priority: normal
severity: normal
status: open
title: Expose called function on frame object
type: feature request
versions: Python 3.3
Added file: http://bugs.python.org/file23071/called_function.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list