Inexplicable behaviour of <type 'function'>

F

Fabiano Sidler

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
 
L

Leif K-Brooks

Fabiano said:
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:

... def bar(self):
... pass
... False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top