Commit e9ce25e5 authored by Neal Norwitz's avatar Neal Norwitz

Fix SF #642742, property() builtin not documented

Added doc for functions new to 2.2:  classmethod property staticmethod super
Taken from docstrings.  Could use review.
Hope there wasn't a reason why these shouldn't have been added.

Backport candidate.
parent 0f30dbd9
......@@ -85,6 +85,7 @@ def my_import(name):
subclassed further. Its only instances are \code{False} and
\code{True}.
\indexii{Boolean}{type}
\versionadded{2.2.1}
\end{funcdesc}
\begin{funcdesc}{buffer}{object\optional{, offset\optional{, size}}}
......@@ -114,6 +115,29 @@ def my_import(name):
if \var{i} is outside that range.
\end{funcdesc}
\begin{funcdesc}{classmethod}{function}
Return a class method for \var{function}.
A class method receives the class as implicit first argument,
just like an instance method receives the instance.
To declare a class method, use this idiom:
\begin{verbatim}
class C:
def f(cls, arg1, arg2, ...): ...
f = classmethod(f)
\end{verbatim}
It can be called either on the class (e.g. C.f()) or on an instance
(e.g. C().f()). The instance is ignored except for its class.
If a class method is called for a derived class, the derived class
object is passed as the implied first argument.
Class methods are different than C++ or Java static methods.
If you want those, see \ref{staticmethod}.
\versionadded{2.2}
\end{funcdesc}
\begin{funcdesc}{cmp}{x, y}
Compare the two objects \var{x} and \var{y} and return an integer
according to the outcome. The return value is negative if \code{\var{x}
......@@ -679,6 +703,25 @@ def my_import(name):
rounding accidents.)
\end{funcdesc}
\begin{funcdesc}{property}{\optional{fget\optional{, fset\optional{, fdel\optional{, doc}}}}}
Return a property attribute for new-style classes (classes that
derive from \function{object}.
\var{fget} is a function for getting an attribute value, likewise
\var{fset} is a function for setting, and \var{fdel} a function
for del'ing, an attribute. Typical use is to define a managed attribute x:
\begin{verbatim}
class C(object):
def getx(self): return self.__x
def setx(self, value): self.__x = value
def delx(self): del self.__x
x = property(getx, setx, delx, "I'm the 'x' property.")
\end{verbatim}
\versionadded{2.2}
\end{funcdesc}
\begin{funcdesc}{range}{\optional{start,} stop\optional{, step}}
This is a versatile function to create lists containing arithmetic
progressions. It is most often used in \keyword{for} loops. The
......@@ -826,6 +869,41 @@ def my_import(name):
\samp{a[start:stop, i]}.
\end{funcdesc}
\begin{funcdesc}{staticmethod}{function}
Return a static method for \var{function}.
A static method does not receive an implicit first argument.
To declare a static method, use this idiom:
\begin{verbatim}
class C:
def f(arg1, arg2, ...): ...
f = staticmethod(f)
\end{verbatim}
It can be called either on the class (e.g. C.f()) or on an instance
(e.g. C().f()). The instance is ignored except for its class.
Static methods in Python are similar to those found in Java or C++.
For a more advanced concept, see \ref{classmethod}.
\versionadded{2.2}
\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, 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:
\begin{verbatim}
class C(B):
def meth(self, arg):
super(C, self).meth(arg)
\end{verbatim}
\versionadded{2.2}
\end{funcdesc}
\begin{funcdesc}{str}{object}
Return a string containing a nicely printable representation of an
object. For strings, this returns the string itself. The
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment