470,821 Members | 1,995 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,821 developers. It's quick & easy.

Inexplicable behaviour of <type 'function'>

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?

Thank you for answering,
F. Sidler
Apr 23 '06 #1
1 938
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
Apr 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Rainer Queck | last post: by
1 post views Thread by =?Utf-8?B?RnJhbmNvaXNWaWxqb2Vu?= | last post: by
8 posts views Thread by =?Utf-8?B?V2hpdG5leSBLZXc=?= | last post: by
1 post views Thread by lovecreatesbea... | last post: by
5 posts views Thread by Ronald S. Cook | last post: by
6 posts views Thread by A.Rocha | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.