[Python-checkins] r69958 - python/branches/release30-maint/Doc/library/functions.rst

raymond.hettinger python-checkins at python.org
Wed Feb 25 02:01:05 CET 2009


Author: raymond.hettinger
Date: Wed Feb 25 02:01:05 2009
New Revision: 69958

Log:
Backport 3.1 changes to super() docs.

Modified:
   python/branches/release30-maint/Doc/library/functions.rst

Modified: python/branches/release30-maint/Doc/library/functions.rst
==============================================================================
--- python/branches/release30-maint/Doc/library/functions.rst	(original)
+++ python/branches/release30-maint/Doc/library/functions.rst	Wed Feb 25 02:01:05 2009
@@ -1039,30 +1039,34 @@
 
 .. function:: super([type[, object-or-type]])
 
-   Return a proxy object that delegates method calls to a parent class of
-   *type*.  This is useful for accessing inherited methods that have been
-   overriden in a child class.  The search order for parent classes is
-   determined by the ``__mro__`` attribute of the *type* and can change
-   whenever the parent classes are updated.
+   Return a proxy object that delegates method calls to a parent or sibling
+   class of *type*.  This is useful for accessing inherited methods that have
+   been overridden in a class. The search order is same as that used by
+   :func:`getattr` except that the *type* itself is skipped.
+
+   The :attr:`__mro__` attribute of the *type* lists the method resolution
+   search order used by both :func:`getattr` and :func:`super`.  The attribute
+   is dynamic and can change whenever the inheritance hierarchy is updated.
 
-   If the second argument is omitted the super object returned is unbound.  If
+   If the second argument is omitted, the super object returned is unbound.  If
    the second argument is an object, ``isinstance(obj, type)`` must be true.  If
    the second argument is a type, ``issubclass(type2, type)`` must be true (this
    is useful for classmethods).
 
-   There are two typical use cases for "super".  In a class hierarchy with
-   single inheritance, "super" can be used to refer to parent classes without
+   There are two typical use cases for *super*.  In a class hierarchy with
+   single inheritance, *super* can be used to refer to parent classes without
    naming them explicitly, thus making the code more maintainable.  This use
-   closely parallels the use of "super" in other programming languages.
+   closely parallels the use of *super* in other programming languages.
 
-   The second use case is to support cooperative multiple inheritence in a
+   The second use case is to support cooperative multiple inheritance in a
    dynamic execution environment.  This use case is unique to Python and is
    not found in statically compiled languages or languages that only support
    single inheritance.  This makes in possible to implement "diamond diagrams"
    where multiple base classes implement the same method.  Good design dictates
    that this method have the same calling signature in every case (because the
-   order of parent calls is determined at runtime and because that order adapts
-   to changes in the class hierarchy).
+   order of calls is determined at runtime, because that order adapts
+   to changes in the class hierarchy, and because that order can include
+   sibling classes that are unknown prior to runtime).
 
    For both use cases, a typical superclass call looks like this::
 
@@ -1073,12 +1077,12 @@
    Note that :func:`super` is implemented as part of the binding process for
    explicit dotted attribute lookups such as ``super().__getitem__(name)``.
    It does so by implementing its own :meth:`__getattribute__` method for searching
-   parent classes in a predictable order that supports cooperative multiple inheritance.
+   classes in a predictable order that supports cooperative multiple inheritance.
    Accordingly, :func:`super` is undefined for implicit lookups using statements or
    operators such as ``super()[name]``.
 
-   Also note that :func:`super` is not limited to use inside methods.  The
-   two argument specifies the arguments exactly and makes the appropriate
+   Also note that :func:`super` is not limited to use inside methods.  The two
+   argument form specifies the arguments exactly and makes the appropriate
    references.  The zero argument form automatically searches the stack frame
    for the class (``__class__``) and the first argument.
 


More information about the Python-checkins mailing list