Saturday, 5 September 2020

Why is binding a class instance method different from binding a class method?

I was reading the python docs and stumbled upon the following lines:

It is also important to note that user-defined functions which are attributes of a class instance are not converted to bound methods; this only happens when the function is an attribute of the class.

Please, someone explain what does that mean in plain english.

I'm going to introduce some shorthand notation:

let 'user-defined functions' be denoted by f,

let 'class instance' be denoted by ci while class denoted simply by c. Obviously(?), ci = c(), with some abuse of notation.

Also, allow membership statements to be recast in simple set notation eg 'user-defined functions which are attributes of a class instance' in shorthand is 'vf: fεa(ci)', where v: 'for all' and where 'a' is the shorthand for (set of) attributes (eg of a class or class instance) and 'ε' denotes the set membership function.

Also, the process of binding a function is described in shorthand by ci.f(*args) or c.f(*args) => f(ci, *args) or f(c, *args) (the former referring to an instance method call while the later referring to a class method call)

Using the newly introduced shorthand notation, does the quote from the docs imply that

vf: fεa(c), c.f(*args) => f(c, *args) is a true statement

while

vf: fεa(ci), ci.f(*args) => f(ci, *args) is false?



from Why is binding a class instance method different from binding a class method?

No comments:

Post a Comment