When you take a reference to a class instance method, the method is bound to this class instance.
B().b
equivalent to: lambda *args, **kwargs: b(<B instance>, *args, **kwargs)
I suspect that you get a similar (but not identical) wrapped link when evaluating Bb. However, this is not the behavior that I expected.
Interesting:
Aa = lambda s: Bb(s) A().a()
gives:
TypeError: unbound method b () should be called with instance B as the first argument (received an instance instead)
This suggests that Bb
evaluates the wrapper for the actual method, and the shell checks that the self is of the expected type. I do not know, but it is probably about the effectiveness of the interpreter.
This is an interesting question. I hope someone can answer a more categorical answer.
source share