summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-04-04 01:24:59 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-04-04 01:24:59 (GMT)
commit20ae90d887a00c713899f8901ee4635ed0332595 (patch)
tree94ce865848ced1df5aad8a29cde4b6a31d6a1c85 /Doc
parent88623d76b49a553445fff037bc9cf2e79a24ceef (diff)
downloadcpython-20ae90d887a00c713899f8901ee4635ed0332595.zip
cpython-20ae90d887a00c713899f8901ee4635ed0332595.tar.gz
cpython-20ae90d887a00c713899f8901ee4635ed0332595.tar.bz2
Issue 5479: Add functools.total_ordering class decorator.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/functools.rst20
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst
index a09d3cf..8f9528a 100644
--- a/Doc/library/functools.rst
+++ b/Doc/library/functools.rst
@@ -17,6 +17,26 @@ function for the purposes of this module.
The :mod:`functools` module defines the following functions:
+.. function:: total_ordering(cls)
+
+ Given a class defining one or more rich comparison ordering methods, this
+ class decorator supplies the rest. This simplies the effort involved
+ in specifying all of the possible rich comparison operations:
+
+ The class must define one of :meth:`__lt__`, :meth:`__le__`,
+ :meth:`__gt__`, or :meth:`__ge__`.
+ In addition, the class should supply an :meth:`__eq__` method.
+
+ For example::
+
+ @total_ordering
+ class Student:
+ def __eq__(self, other):
+ return ((self.lastname.lower(), self.firstname.lower()) ==
+ (other.lastname.lower(), other.firstname.lower()))
+ def __lt__(self, other):
+ return ((self.lastname.lower(), self.firstname.lower()) <
+ (other.lastname.lower(), other.firstname.lower()))
.. function:: reduce(function, iterable[, initializer])