summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-11-27 10:40:20 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-11-27 10:40:20 (GMT)
commitff737954f3ee3005236133fc51b55a508b11aa06 (patch)
treeb65ae9e39e774bd73674b5088e549d09a7bfd7d6 /Doc
parent0d3fb8a944a810f421377d5823cbc006700b3c1d (diff)
downloadcpython-ff737954f3ee3005236133fc51b55a508b11aa06.zip
cpython-ff737954f3ee3005236133fc51b55a508b11aa06.tar.gz
cpython-ff737954f3ee3005236133fc51b55a508b11aa06.tar.bz2
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Also removed im_class and renamed im_self to __self__ and im_func to __func__. im_class can be substituted with method.__self__.__class__. I've also updated some parts of the documenation.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/inspect.rst9
-rw-r--r--Doc/library/new.rst6
-rw-r--r--Doc/library/stdtypes.rst14
-rw-r--r--Doc/reference/datamodel.rst55
-rw-r--r--Doc/tutorial/classes.rst4
5 files changed, 40 insertions, 48 deletions
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index cf14de9..988b737 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -49,14 +49,11 @@ attributes:
| | __name__ | name with which this |
| | | method was defined |
+-----------+-----------------+---------------------------+
-| | im_class | class object that asked |
-| | | for this method |
-+-----------+-----------------+---------------------------+
-| | im_func | function object |
+| | __func__ | function object |
| | | containing implementation |
| | | of method |
+-----------+-----------------+---------------------------+
-| | im_self | instance to which this |
+| | __self__ | instance to which this |
| | | method is bound, or |
| | | ``None`` |
+-----------+-----------------+---------------------------+
@@ -264,7 +261,7 @@ attributes:
Methods implemented via descriptors that also pass one of the other tests
return false from the :func:`ismethoddescriptor` test, simply because the
other tests promise more -- you can, e.g., count on having the
- :attr:`im_func` attribute (etc) when an object passes :func:`ismethod`.
+ :attr:`__func__` attribute (etc) when an object passes :func:`ismethod`.
.. function:: isdatadescriptor(object)
diff --git a/Doc/library/new.rst b/Doc/library/new.rst
index 6153ff1..6c5a4bf 100644
--- a/Doc/library/new.rst
+++ b/Doc/library/new.rst
@@ -17,10 +17,10 @@ non-sensical arguments which crash the interpreter when the object is used.
The :mod:`new` module defines the following functions:
-.. function:: instancemethod(function, instance, class)
+.. function:: instancemethod(function, instance)
- This function will return a method object, bound to *instance*, or unbound if
- *instance* is ``None``. *function* must be callable.
+ This function will return a method object, bound to *instance*.
+ *function* must be callable.
.. function:: function(code, globals[, name[, argdefs[, closure]]])
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.
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 1e85f83..75cb52f 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -538,20 +538,18 @@ Callable types
A user-defined method object combines a class, a class instance (or ``None``)
and any callable object (normally a user-defined function).
- Special read-only attributes: :attr:`im_self` is the class instance object,
- :attr:`im_func` is the function object; :attr:`im_class` is the class of
- :attr:`im_self` for bound methods or the class that asked for the method for
- unbound methods; :attr:`__doc__` is the method's documentation (same as
- ``im_func.__doc__``); :attr:`__name__` is the method name (same as
- ``im_func.__name__``); :attr:`__module__` is the name of the module the method
- was defined in, or ``None`` if unavailable.
+ Special read-only attributes: :attr:`__self__` is the class instance object,
+ :attr:`__func__` is the function object; :attr:`__doc__` is the method's
+ documentation (same as ``__func__.__doc__``); :attr:`__name__` is the
+ method name (same as ``__func__.__name__``); :attr:`__module__` is the
+ name of the module the method was defined in, or ``None`` if unavailable.
.. index::
single: __doc__ (method attribute)
single: __name__ (method attribute)
single: __module__ (method attribute)
- single: im_func (method attribute)
- single: im_self (method attribute)
+ single: __func__ (method attribute)
+ single: __self__ (method attribute)
Methods also support accessing (but not setting) the arbitrary function
attributes on the underlying function object.
@@ -565,49 +563,46 @@ Callable types
the original method object is used as it is.
.. index::
- single: im_class (method attribute)
- single: im_func (method attribute)
- single: im_self (method attribute)
+ single: __func__ (method attribute)
+ single: __self__ (method attribute)
When a user-defined method object is created by retrieving a user-defined
- function object from a class, its :attr:`im_self` attribute is ``None``
+ function object from a class, its :attr:`__self__` attribute is ``None``
and the method object is said to be unbound. When one is created by
retrieving a user-defined function object from a class via one of its
- instances, its :attr:`im_self` attribute is the instance, and the method
- object is said to be bound. In either case, the new method's
- :attr:`im_class` attribute is the class from which the retrieval takes
- place, and its :attr:`im_func` attribute is the original function object.
+ instances, its :attr:`__self__` attribute is the instance, and the method
+ object is said to be bound. Its :attr:`__func__` attribute is the
+ original function object.
- .. index:: single: im_func (method attribute)
+ .. index:: single: __func__ (method attribute)
When a user-defined method object is created by retrieving another method object
from a class or instance, the behaviour is the same as for a function object,
- except that the :attr:`im_func` attribute of the new instance is not the
- original method object but its :attr:`im_func` attribute.
+ except that the :attr:`__func__` attribute of the new instance is not the
+ original method object but its :attr:`__func__` attribute.
.. index::
- single: im_class (method attribute)
- single: im_func (method attribute)
- single: im_self (method attribute)
+ single: __func__ (method attribute)
+ single: __self__ (method attribute)
When a user-defined method object is created by retrieving a class method object
- from a class or instance, its :attr:`im_self` attribute is the class itself (the
- same as the :attr:`im_class` attribute), and its :attr:`im_func` attribute is
+ from a class or instance, its :attr:`__self__` attribute is the class itself (the
+ same as the :attr:`im_class` attribute), and its :attr:`__func__` attribute is
the function object underlying the class method.
When an unbound user-defined method object is called, the underlying function
- (:attr:`im_func`) is called, with the restriction that the first argument must
+ (:attr:`__func__`) is called, with the restriction that the first argument must
be an instance of the proper class (:attr:`im_class`) or of a derived class
thereof.
When a bound user-defined method object is called, the underlying function
- (:attr:`im_func`) is called, inserting the class instance (:attr:`im_self`) in
+ (:attr:`__func__`) is called, inserting the class instance (:attr:`__self__`) in
front of the argument list. For instance, when :class:`C` is a class which
contains a definition for a function :meth:`f`, and ``x`` is an instance of
:class:`C`, calling ``x.f(1)`` is equivalent to calling ``C.f(x, 1)``.
When a user-defined method object is derived from a class method object, the
- "class instance" stored in :attr:`im_self` will actually be the class itself, so
+ "class instance" stored in :attr:`__self__` will actually be the class itself, so
that calling either ``x.f(1)`` or ``C.f(1)`` is equivalent to calling ``f(C,1)``
where ``f`` is the underlying function.
@@ -741,7 +736,7 @@ Custom classes
transformed into an unbound user-defined method object whose :attr:`im_class`
attribute is :class:`C`. When it would yield a class method object, it is
transformed into a bound user-defined method object whose :attr:`im_class`
- and :attr:`im_self` attributes are both :class:`C`. When it would yield a
+ and :attr:`__self__` attributes are both :class:`C`. When it would yield a
static method object, it is transformed into the object wrapped by the static
method object. See section :ref:`descriptors` for another way in which
attributes retrieved from a class may differ from those actually contained in
@@ -786,7 +781,7 @@ Class instances
is the class (call it :class:`C`) of the instance for which the attribute
reference was initiated or one of its bases, it is transformed into a bound
user-defined method object whose :attr:`im_class` attribute is :class:`C` and
- whose :attr:`im_self` attribute is the instance. Static method and class method
+ whose :attr:`__self__` attribute is the instance. Static method and class method
objects are also transformed, as if they had been retrieved from class
:class:`C`; see above under "Classes". See section :ref:`descriptors` for
another way in which attributes of a class retrieved via its instances may
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst
index ef6498e..4e95419 100644
--- a/Doc/tutorial/classes.rst
+++ b/Doc/tutorial/classes.rst
@@ -576,8 +576,8 @@ data from a string buffer instead, and pass it as an argument.
.. % \code{sys.stdin} will not cause the interpreter to read further input
.. % from it.)
-Instance method objects have attributes, too: ``m.im_self`` is the instance
-object with the method :meth:`m`, and ``m.im_func`` is the function object
+Instance method objects have attributes, too: ``m.__self__`` is the instance
+object with the method :meth:`m`, and ``m.__func__`` is the function object
corresponding to the method.