How User-defined method objects are created?

Terry Reedy tjreedy at udel.edu
Sat Mar 20 12:39:44 EDT 2010


On 3/20/2010 9:54 AM, Joaquin Abian wrote:
> I'm trying to understand the description of method object creation in
> the python 2.6 language reference (3.2. The standard type hierarchy)
> with little success. The points knocking me are:
>
> "User-defined method objects may be created when getting an attribute
> of a class (perhaps via an instance of that class), if that attribute
> is a user-defined function object, an unbound user-defined method
> object, or a class method object. When the attribute is a user-defined
> method object, a new method object is only created if the class from
> which it is being retrieved is the same as, or a derived class of, the
> class stored in the original method object; otherwise, the original
> method object is used as it is."
>
> It is a bit of a tongue-twister for me. What the last sentence means?
> Please, I beg for a simple example of the different objects (user
> defined function, user defined method, class method) refered.
> Are maybe the refered objects exemplified by :
>
> #python 3.1
> class Klass():
>
> 	def met(self):
> 		print('method')
>
>         def func():
> 		print('function')
>
>         @classmethod
> 	def kmet(klass):
> 		print('classmethod')
>
> or it is talking about another thing?
> What is the difference with python 3 where there is no mention to the
> unbound user-defined method object (same section in python 3 language
> reference):

Python3 does not have unbound method objects. Klass.met above is just a 
function.l

> "User-defined method objects may be created when getting an attribute
> of a class (perhaps via an instance of that class), if that attribute
> is a user-defined function object or a class method object."
>
> I'm trying to learn, however the task is revealing as an enormous
> undertaking :-)

One can successfully use the language in the normal way without 
understanding every detail of every oddball corner case. Recent 2.x is 
complicated by duplication (two user object systems) and 
back-compatibility constraints. Most new users do not need to bother 
with obsolete complications.

Terry Jan Reedy




More information about the Python-list mailing list