Function mistaken for a method

Peter Otten __peter__ at web.de
Thu Jun 1 07:34:53 EDT 2006


Eric Brunel wrote:

> My actual question is: why does it work in one case and not in the other?
> As I see it, int is just a function with one parameter, and the lambda is
> just another one. So why does the first work, and not the second? What
> 'black magic' takes place so that int is not mistaken for a method in the
> first case?
 
A python-coded function has a __get__ attribute, a C-function doesn't.
Therefore C1.f performs just the normal attribute lookup while C2.f also
triggers the f.__get__(C2(), C2) call via the descriptor protocol which
happens to return a bound method.

Peter





More information about the Python-list mailing list