Confused with methods

jfj jfj at freemail.gr
Mon Feb 7 16:15:15 EST 2005


Alex Martelli wrote:
> jfj <jfj at freemail.gr> wrote:
> 
>>Then, without looking at the previous code, one can say that "x" is a
>>function which takes one argument.
> 
> 
> One can say whatever one wishes, but saying it does not make it true.
> 
> One can say that x is a green frog, but that's false: x is a
> boundmethod.
> 
> One can say that x is a function, but that's false: x is a boundmethod.
> 
> One can say that x is a spade, but that's false: x is a boundmethod.
> 

I understand that a function and a boundmethod are *different* things.
For one a *boundmethod* has the attributes im_self, im_class, which
a function does not have (a green frog neither). Thus they are not
the same thing.

HOWEVER, what I ask is WHY don't we set the tp_descr_get of
the boundmethod object to be the same as the func_descr_get???
Or WHY do they *have* to differ in this specific part?

I quickly looked at the source of python and it seems that a
one-liner would be enough to enable this. So it's not that it
would be hard to implement it, or inefficient.

A bound method would *still* be a boundmethod.
We could additionally have:

 >>>type(x)
  <boundmethod of <boundmethod of <boundmethod of....<__main__.A 
instance at 0x>>>

If there a good reason that the __get__ of a boundmethod does not
create a new boundmethod wrapper over the first boundmethod?


G.



More information about the Python-list mailing list