Prototype OO

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Apr 3 08:32:02 EDT 2008


En Thu, 03 Apr 2008 05:20:48 -0300, sam <sam at mas.pl> escribió:

> Gabriel Genellina napisał(a):
>
>> Class methods and instance methods are not just standard functions;
>> instance methods were plain functions before 2.2 and the Class object
>> was in charge of doing the "self magic". Now the descriptor protocol
>> provides far more possibilities.
>
> Actually I don't know what is "descriptor protocol", so maybe I should  
> have
> finished discussing. I will aslo search for "self magic" -- some pieces  
> of old
> code, or something.

I meant the way instance methods acquire their "self" argument; the  
transformation from someobject.foo(arg1,arg2) into  
(ClassOfSomeobject.foo)(someobject, arg1, arg2) that classic classes do  
themselves and could not be changed nor extended. The descriptor protocol  
provides a way for attributes to modify the way they're handled; this is  
how instance methods get their self argument, and allows for the existence  
of class methods, static methods, and properties, among other things.
The descriptor protocol is very important for Python and understanding it  
is a good idea, but not before you are rather fluent with the language or  
it will be fairly incomprehensible.

-- 
Gabriel Genellina




More information about the Python-list mailing list