Binding behaviour of built-in functions versus normal functions

Steffen Viken Valvåg steffenv at stud.cs.uit.nospam.no
Fri May 3 08:40:25 EDT 2002


Assigning functions to classes after their creation is allowed and works as
expected - the functions become methods of the class with 'binding'
behaviour. For instance

def myadd(self, other):
    pass

myclass.__add__ = myadd

works as expected. However, the same code doesn't work if 'myadd' is a
built-in function, i.e. a function that is implemented in C by some
extension module. The reason is that normal functions have a __get__ method
that lets them act as descriptors that return bound methods. Built-in
functions don't have such a __get__ method, but I can't see any reason why
they shouldn't.

Does anyone have any viewpoints on the philosophy behind this? Is there a
good reason why built-in functions shouldn't have such binding behaviour?

--
Steffen Viken Valvåg
remove nospam from reply address to reply






More information about the Python-list mailing list