[Python-ideas] Access to function objects

Terry Reedy tjreedy at udel.edu
Sat Aug 6 22:28:33 CEST 2011

On 8/6/2011 4:19 AM, Chris Rebert wrote:
> On Sat, Aug 6, 2011 at 1:16 AM, Chris Rebert<pyideas at rebertia.com>  wrote:
>> On Sat, Aug 6, 2011 at 1:10 AM, David Townshend<aquavitae69 at gmail.com>  wrote:
>>> Has anyone else ever thought that it might be useful to access a function

> [Rejected] PEP 3130: Access to Current Module/Class/Function
> http://www.python.org/dev/peps/pep-3130/

The first problem with this is that it is three proposals in one. Each 
should have been considered separately on its own merits. The second 
problem stems from the first: there is a blanket rejection of all three 
with no reference to the relative merits of the three different proposals.

The __module__ proposal is particularly weak as the only use case given 
is replacing
if __name__ == '__main__': ...
if __module__ is sys.main: ...
I would reject the collective proposal just to reject this.

The __class__ proposal seems to have been dealt with partly by revisions 
to super. I have not read it enough to know if anything more is left, 
but there is not much, if any, demand for more that I have seen.

The proposal for access to a function from within the function has two 
important use cases, mentioned in the PEP. First is to make truly 
recursive functions. Second is to dependably access function attributes 
from within the function. (Without that, there are hardly used even a 
decade after their introduction.) In both cases, the idea is to make the 
function operate as desired independently of external namespace 
manipulations (even from outside the module) that the function and its 
author literally have no control over. Except purely for speed, function 
attributes could then replace pseudo-parameters with default args.

This proposal/desire comes up constantly on python-list, generally with 
support. I believe it was part of two recent threads. I would like to 
know if the rejection of the idea so far is a rejection in principle 
(and if so, why) or a rejection of specifics.

Terry Jan Reedy

More information about the Python-ideas mailing list