Inexplicable behaviour of <type 'function'>
Leif K-Brooks
eurleif at ecritters.biz
Sun Apr 23 06:25:48 EDT 2006
Fabiano Sidler wrote:
> Have a look to the following lines of code:
> --- snip ---
> class Foo: pass
> def bar(): pass
> Foo.bar = bar
> --- snap ---
>
> Why does 'bar.__get__(Foo) is Foo.bar' evaluate to False here? Did I
> misunderstand the descriptor protocol?
bar.__get__(None, Bar) is what you meant (the first argument is the
object, not the type), but even then the result will be False, because
the __get__ method on functions returns a different object each time
it's called:
>>> class Foo(object):
... def bar(self):
... pass
...
>>> Foo.bar is Foo.bar
False
More information about the Python-list
mailing list