Confused with classmethods
jfj
jfj at freemail.gr
Sat Mar 12 07:55:42 EST 2005
Ruud wrote:
>
> So far for *how* it works. As to *why* it works like this, I don't know
> for sure. But my guess is that the reasoning was something as follows:
> if you define a function (regular or something special like a
> classmethod) only for an instance of a class, you obviously don't
> want to use it in a class context: it is -by definition- invisible to
> the class, or to other instances of the same class.
> One possible use case would be to store a callback function.
> And in that case you definitely don't want the class magic to happen
> when you reference the function.
Yep. Got it. Indeed the reason seems to be a valid optimization:
-in 99% of the cases you request something from an instance it is a
plain old variable
-in 99% of the cases you request something from a class it's a
function.
So it would be a waste of time to check for the conversion when
something exists in the __dict__ of the instance, indeed.
OTOH, I'm talking about the "concept of python" and not CPython
implementation, and that's why I have these questions:)
Thanks,
jfj
More information about the Python-list
mailing list