summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-06-28 20:15:47 (GMT)
committerFred Drake <fdrake@acm.org>2000-06-28 20:15:47 (GMT)
commit35c09f2e518af8dd09250b780bbca27039c0f951 (patch)
tree6a2715ddb7168b8d058657778c18c7727b7ffba3
parent6da0b9148c9e733ac98d9889a79c7b93bb80b0f3 (diff)
downloadcpython-35c09f2e518af8dd09250b780bbca27039c0f951.zip
cpython-35c09f2e518af8dd09250b780bbca27039c0f951.tar.gz
cpython-35c09f2e518af8dd09250b780bbca27039c0f951.tar.bz2
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.
-rw-r--r--Doc/ref/ref3.tex20
1 files changed, 11 insertions, 9 deletions
diff --git a/Doc/ref/ref3.tex b/Doc/ref/ref3.tex
index c51f514..59b98de 100644
--- a/Doc/ref/ref3.tex
+++ b/Doc/ref/ref3.tex
@@ -438,11 +438,12 @@ base class of the class of which \member{im_self} is an instance);
User-defined method objects are created in two ways: when getting an
attribute of a class that is a user-defined function object, or when
-getting an attributes of a class instance that is a user-defined
-function object. In the former case (class attribute), the
-\member{im_self} attribute is \code{None}, and the method object is said
-to be unbound; in the latter case (instance attribute), \method{im_self}
-is the instance, and the method object is said to be bound. For
+getting an attribute of a class instance that is a user-defined
+function object defined by the class of the instance. In the former
+case (class attribute), the \member{im_self} attribute is \code{None},
+and the method object is said to be unbound; in the latter case
+(instance attribute), \method{im_self} is the instance, and the method
+object is said to be bound. For
instance, when \class{C} is a class which contains a definition for a
function \method{f()}, \code{C.f} does not yield the function object
\code{f}; rather, it yields an unbound method object \code{m} where
@@ -452,9 +453,7 @@ instance, \code{x.f} yields a bound method object \code{m} where
\code{m.im_class} is \code{C}, \code{m.im_func} is \method{f()}, and
\code{m.im_self} is \code{x}.
\withsubitem{(method attribute)}{
- \ttindex{im_class}
- \ttindex{im_func}
- \ttindex{im_self}}
+ \ttindex{im_class}\ttindex{im_func}\ttindex{im_self}}
When an unbound user-defined method object is called, the underlying
function (\member{im_func}) is called, with the restriction that the
@@ -474,7 +473,10 @@ the class or instance. In some cases, a fruitful optimization is to
assign the attribute to a local variable and call that local variable.
Also notice that this transformation only happens for user-defined
functions; other callable objects (and all non-callable objects) are
-retrieved without transformation.
+retrieved without transformation. It is also important to note that
+user-defined functions which are attributes of a class instance are
+not converted to bound methods; this \emph{only} happens when the
+function is an attribute of the class.
\item[Built-in functions]
A built-in function object is a wrapper around a \C{} function. Examples