[New-bugs-announce] [issue12857] Expose called function on frame object
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. 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.
components: Interpreter Core
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