diff options
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/new.rst | 2 | ||||
-rw-r--r-- | Doc/library/operator.rst | 2 | ||||
-rw-r--r-- | Doc/library/stdtypes.rst | 30 | ||||
-rw-r--r-- | Doc/library/weakref.rst | 8 |
4 files changed, 20 insertions, 22 deletions
diff --git a/Doc/library/new.rst b/Doc/library/new.rst index 6c5a4bf..832dca6 100644 --- a/Doc/library/new.rst +++ b/Doc/library/new.rst @@ -22,6 +22,8 @@ The :mod:`new` module defines the following functions: This function will return a method object, bound to *instance*. *function* must be callable. + .. XXX no unbound methods anymore + .. function:: function(code, globals[, name[, argdefs[, closure]]]) diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index 40acc6b..cb89a7f 100644 --- a/Doc/library/operator.rst +++ b/Doc/library/operator.rst @@ -390,7 +390,7 @@ objects. Use the :func:`callable` built-in function instead. Returns true if the object *obj* can be called like a function, otherwise it - returns false. True is returned for functions, bound and unbound methods, class + returns false. True is returned for functions, instance methods, class objects, and instance objects which support the :meth:`__call__` method. diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 1e81ed9..5c69ed6 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2215,23 +2215,19 @@ two flavors: built-in methods (such as :meth:`append` on lists) and class instance methods. Built-in methods are described with the types that support them. -The implementation adds two special read-only attributes to class instance -methods: ``m.__self__`` is the object on which the method operates, and -``m.__func__`` is the function implementing the method. Calling ``m(arg-1, -arg-2, ..., arg-n)`` is completely equivalent to calling ``m.__func__( -m.__self__, arg-1, arg-2, ..., arg-n)``. - -Class instance methods are either *bound* or *unbound*, referring to whether the -method was accessed through an instance or a class, respectively. When a method -is unbound, its ``__self__`` attribute will be ``None`` and if called, an -explicit ``self`` object must be passed as the first argument. In this case, -``self`` must be an instance of the unbound method's class (or a subclass of -that class), otherwise a :exc:`TypeError` is raised. - -Like function objects, methods objects support getting arbitrary attributes. -However, since method attributes are actually stored on the underlying function -object (``meth.__func__``), setting method attributes on either bound or unbound -methods is disallowed. Attempting to set a method attribute results in a +If you access a method (a function defined in a class namespace) through an +instance, you get a special object: a :dfn:`bound method` (also called +:dfn:`instance method`) object. When called, it will add the ``self`` argument +to the argument list. Bound methods have two special read-only attributes: +``m.__self__`` is the object on which the method operates, and ``m.__func__`` is +the function implementing the method. Calling ``m(arg-1, arg-2, ..., arg-n)`` +is completely equivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ..., +arg-n)``. + +Like function objects, bound method objects support getting arbitrary +attributes. However, since method attributes are actually stored on the +underlying function object (``meth.__func__``), setting method attributes on +bound methods is disallowed. Attempting to set a method attribute results in a :exc:`TypeError` being raised. In order to set a method attribute, you need to explicitly set it on the underlying function object:: diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index 3adf318..9a1e076 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -50,10 +50,10 @@ directly. The low-level machinery used by the weak dictionary implementations is exposed by the :mod:`weakref` module for the benefit of advanced uses. Not all objects can be weakly referenced; those objects which can include class -instances, functions written in Python (but not in C), methods (both bound and -unbound), sets, frozensets, file objects, :term:`generator`\s, type objects, -:class:`DBcursor` objects from the :mod:`bsddb` module, sockets, arrays, deques, -and regular expression pattern objects. +instances, functions written in Python (but not in C), instance methods, sets, +frozensets, file objects, :term:`generator`\s, type objects, :class:`DBcursor` +objects from the :mod:`bsddb` module, sockets, arrays, deques, and regular +expression pattern objects. Several builtin types such as :class:`list` and :class:`dict` do not directly support weak references but can add support through subclassing:: |