summaryrefslogtreecommitdiffstats
path: root/Doc/library/functions.rst
diff options
context:
space:
mode:
authorMark Summerfield <list@qtrac.plus.com>2008-02-26 13:27:00 (GMT)
committerMark Summerfield <list@qtrac.plus.com>2008-02-26 13:27:00 (GMT)
commit1041f74837497657ed9fb0e8e01f65794ffbf81e (patch)
tree2121aa989eeedf67b518b0df1beb2fb6c530242d /Doc/library/functions.rst
parent836baa53d822e57294bfab19f25f7a92a8b54698 (diff)
downloadcpython-1041f74837497657ed9fb0e8e01f65794ffbf81e.zip
cpython-1041f74837497657ed9fb0e8e01f65794ffbf81e.tar.gz
cpython-1041f74837497657ed9fb0e8e01f65794ffbf81e.tar.bz2
Updated super() as per http://www.artima.com/weblogs/viewpost.jsp?thread=208549
but would be worth someone else checking if poss.
Diffstat (limited to 'Doc/library/functions.rst')
-rw-r--r--Doc/library/functions.rst24
1 files changed, 15 insertions, 9 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 97209a4..62b37c0 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -1025,25 +1025,31 @@ available. They are listed here in alphabetical order.
sequence of strings is by calling ``''.join(sequence)``.
-.. function:: super(type[, object-or-type])
+.. function:: super([type[, object-or-type]])
- .. XXX need to document PEP "new super"
+ .. XXX updated as per http://www.artima.com/weblogs/viewpost.jsp?thread=208549 but needs checking
- Return the superclass of *type*. 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,
+ Return the superclass of *type*.
+
+ Calling :func:`super()` without arguments is equivalent to
+ ``super(this_class, first_arg)``. If called with one
+ argument the super object returned is unbound. If called with two
+ arguments and 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.
A typical use for calling a cooperative superclass method is::
class C(B):
- def meth(self, arg):
- super(C, self).meth(arg)
+ def method(self, arg):
+ super().method(arg) # This does the same thing as: super(C, self).method(arg)
Note that :func:`super` is implemented as part of the binding process for
- explicit dotted attribute lookups such as ``super(C, self).__getitem__(name)``.
+ explicit dotted attribute lookups such as ``super().__getitem__(name)``.
Accordingly, :func:`super` is undefined for implicit lookups using statements or
- operators such as ``super(C, self)[name]``.
+ operators such as ``super()[name]``. Also, :func:`super` is not
+ limited to use inside methods: under the hood it searches the stack
+ frame for the class (``__class__``) and the first argument.
.. function:: tuple([iterable])