diff options
Diffstat (limited to 'Doc/library/stdtypes.rst')
-rw-r--r-- | Doc/library/stdtypes.rst | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index e6f7e7b..1e81ed9 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2216,21 +2216,21 @@ 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.im_self`` is the object on which the method operates, and -``m.im_func`` is the function implementing the method. Calling ``m(arg-1, -arg-2, ..., arg-n)`` is completely equivalent to calling ``m.im_func(m.im_self, -arg-1, arg-2, ..., arg-n)``. +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 ``im_self`` attribute will be ``None`` and if called, an +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.im_func``), setting method attributes on either bound or unbound +object (``meth.__func__``), setting method attributes on either bound or unbound 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:: @@ -2240,7 +2240,7 @@ explicitly set it on the underlying function object:: pass c = C() - c.method.im_func.whoami = 'my name is c' + c.method.__func__.whoami = 'my name is c' See :ref:`types` for more information. |