Why can function definitions only use identifiers, and not attribute references or any other primaries?

Scott David Daniels Scott.Daniels at Acm.Org
Thu Apr 23 19:48:57 CEST 2009

Jeremy Banks wrote: (proposing def <lhs>(<args>): ...
> On Thu, Apr 23, 2009 at 11:52, Gary Herron <gherron at islandtraining.com> wrote:
>> Try this:
>>   def foo_bar():
>>       return(...)
>>   foo.bar = foo_bar
>> and this:
>>   def foo_bar():
>>       return(...)
>>   foo["bar"] = foo_bar
> I understand that this is possible now, but I just don't see why it's
> necessary to do it at all.

I am afraid it will make it too easy to define functions in other
modules remotely, a tempting sharp stick to poke your eye out with.
Note also, that it will not be so easy to find the definition of a
function provided as a argument to a failing function.  Right now
you can get the function name and (with a bit more effort) its module.
Imagine debugging a pile of code that includes a module with:
     import random
     def random.random():
         return .42

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list