dunder-docs (was Python is DOOMED! Again!)
Gregory Ewing
greg.ewing at canterbury.ac.nz
Tue Feb 3 06:32:09 EST 2015
Steven D'Aprano wrote:
> Both K.f and K.g are methods, even though only one meets the definition
> given in the glossary. The glossary is wrong.
>
> Or rather, it is not so much that it is *wrong*, but that it is incomplete
> and over-simplified.
I agree with that; a more complete definition would be
"a function that is found in a class as a result of an
attribute lookup on an instance of that class".
> I defined a method:
>
> py> from types import MethodType
> py> type(instance.f) is MethodType
> True
Being of type MethodType is not the defining characterisic
of a method. MethodType is actually misnamed; an instance
of MethodType is *not* a method, in the same way that an
eggcup is not an egg.
A better name would be MethodWrapper, but that still
doesn't mean that anything you wrap with it is a method.
An eggcup *usually* contains an egg, but it could
contain something else.
> instance.f is a method by the glossary definition.
Not by the glossary definition as written, since the
function you wrapped in a MethodType was not defined
inside a class body.
--
Greg
More information about the Python-list
mailing list