Index: lib/libfuncs.tex =================================================================== --- lib/libfuncs.tex (revision 50998) +++ lib/libfuncs.tex (working copy) @@ -1099,25 +1099,50 @@ \end{funcdesc} \begin{funcdesc}{super}{type\optional{, object-or-type}} - Return the superclass of \var{type}. If the second argument is omitted - the super object returned is unbound. If the second argument is an - object, \code{isinstance(\var{obj}, \var{type})} must be true. If - the second argument is a type, \code{issubclass(\var{type2}, - \var{type})} must be true. + Return an object that exposes the attributes available through the + type's superclasses, without exposing the attributes of the type + itself. Attributes will be looked up using the normal resolution + order, omitting \var{type} in the method resolution order. + \function{super()} only works for new-style classes. - A typical use for calling a cooperative superclass method is: + If the second argument is present, it should either be an instance + of object, in which case + \code{isinstance(\var{object-or-type}, \var{type})} + must be true, or it should be an instance of type, in which case + \code{issubclass(\var{object-or-type}, \var{type})} + must be true. The typical use for this form of \function{super()} + is to call a cooperative superclass method by passing in an instance + as the second argument: + \begin{verbatim} class C(B): def meth(self, arg): super(C, self).meth(arg) \end{verbatim} - Note that \function{super} is implemented as part of the binding process for - explicit dotted attribute lookups such as - \samp{super(C, self).__getitem__(name)}. Accordingly, \function{super} is - undefined for implicit lookups using statements or operators such as - \samp{super(C, self)[name]}. + Note that if no superclass provides the requested attribute, and + \exception{AttributeError} is raised. + + For class methods, the second argument should be the class rather than an instance. For example: + +\begin{verbatim} +class C(B): + @classmethod + def method(cls, arg): + super(C, cls).method(arg) +\end{verbatim} + + In this case, using \function{super()} provides access to a class + method defined on \class{B} or one of its base classes. + + Note that \function{super()} does not support implicit lookups based + on syntactic constructs or built-in functions. Constructs which + normally retrieve a \code{__\var{special}__} method behind the curtain + will not work; the special method must be used directly. + For example, \code{super(C, \var{self})[\var{key}]} must be spelled + \code{super(C, \var{self}).__getitem__(\var{key})}. + \versionadded{2.2} \end{funcdesc}