Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35c09f2

Browse files
committed
Revise the description of when functions retrieved from class instances
are and are not turned into bound methods; some confusion was noted by Andrew Dalke. In particular, it has to be noted that functions located on the class instance are not turned into any sort of method, only those which are found via the underlying class.
1 parent 6da0b91 commit 35c09f2

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

Doc/ref/ref3.tex

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,12 @@ \section{The standard type hierarchy\label{types}}
438438

439439
User-defined method objects are created in two ways: when getting an
440440
attribute of a class that is a user-defined function object, or when
441-
getting an attributes of a class instance that is a user-defined
442-
function object. In the former case (class attribute), the
443-
\member{im_self} attribute is \code{None}, and the method object is said
444-
to be unbound; in the latter case (instance attribute), \method{im_self}
445-
is the instance, and the method object is said to be bound. For
441+
getting an attribute of a class instance that is a user-defined
442+
function object defined by the class of the instance. In the former
443+
case (class attribute), the \member{im_self} attribute is \code{None},
444+
and the method object is said to be unbound; in the latter case
445+
(instance attribute), \method{im_self} is the instance, and the method
446+
object is said to be bound. For
446447
instance, when \class{C} is a class which contains a definition for a
447448
function \method{f()}, \code{C.f} does not yield the function object
448449
\code{f}; rather, it yields an unbound method object \code{m} where
@@ -452,9 +453,7 @@ \section{The standard type hierarchy\label{types}}
452453
\code{m.im_class} is \code{C}, \code{m.im_func} is \method{f()}, and
453454
\code{m.im_self} is \code{x}.
454455
\withsubitem{(method attribute)}{
455-
\ttindex{im_class}
456-
\ttindex{im_func}
457-
\ttindex{im_self}}
456+
\ttindex{im_class}\ttindex{im_func}\ttindex{im_self}}
458457

459458
When an unbound user-defined method object is called, the underlying
460459
function (\member{im_func}) is called, with the restriction that the
@@ -474,7 +473,10 @@ \section{The standard type hierarchy\label{types}}
474473
assign the attribute to a local variable and call that local variable.
475474
Also notice that this transformation only happens for user-defined
476475
functions; other callable objects (and all non-callable objects) are
477-
retrieved without transformation.
476+
retrieved without transformation. It is also important to note that
477+
user-defined functions which are attributes of a class instance are
478+
not converted to bound methods; this \emph{only} happens when the
479+
function is an attribute of the class.
478480

479481
\item[Built-in functions]
480482
A built-in function object is a wrapper around a \C{} function. Examples

0 commit comments

Comments
 (0)