[Python-ideas] Access to function objects

Steven D'Aprano steve at pearwood.info
Tue Aug 9 02:42:47 CEST 2011

Ben Finney wrote:

> The ability to access the undecorated function would be of great help in
> our Django-based project. Django is very decorator-happy, and we are
> trying to introspect code and, given a particular URL, determine the
> innermost function (more precisely, what location in our code) that
> actually handles that URL.
> Is that a use-case of interest?

I shouldn't think the proposed __func__ local would be of any use here, 
because it is local to the function. As I understand your use-case, you 
need to inspect a function from the outside, where __func__ is not 
available, and peel back all the decorators to the innermost function.

To do that, I would start by looking at:


and recurse as necessary.


More information about the Python-ideas mailing list