diff options
author | Guido van Rossum <guido@python.org> | 2001-10-16 20:32:05 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-10-16 20:32:05 (GMT) |
commit | 7a59445e3783fc842bc4fd0181b18d6798883a3e (patch) | |
tree | f579fa041261af2544a415533b48bc5f9abe92ac | |
parent | c993315b188b08b6d78248522f6d0ed31d52f939 (diff) | |
download | cpython-7a59445e3783fc842bc4fd0181b18d6798883a3e.zip cpython-7a59445e3783fc842bc4fd0181b18d6798883a3e.tar.gz cpython-7a59445e3783fc842bc4fd0181b18d6798883a3e.tar.bz2 |
Document required return values -1, 0, 1 for tp_compare handler, as
suggested in SF patch #424475. Also document exception return.
-rw-r--r-- | Doc/ext/newtypes.tex | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Doc/ext/newtypes.tex b/Doc/ext/newtypes.tex index ffc1f82..c8f7c6c 100644 --- a/Doc/ext/newtypes.tex +++ b/Doc/ext/newtypes.tex @@ -622,10 +622,19 @@ which matches the requested comparison. (It is always used if defined and the \cfunction{PyObject_Compare()} or \cfunction{PyObject_Cmp()} functions are used, or if \function{cmp()} is used from Python.) It is analogous to the \method{__cmp__()} method. This function -should return a negative integer if \var{obj1} is less than -\var{obj2}, \code{0} if they are equal, and a positive integer if +should return \code{-1} if \var{obj1} is less than +\var{obj2}, \code{0} if they are equal, and \code{1} if \var{obj1} is greater than \var{obj2}. +(It was previously allowed to return arbitrary negative or positive +integers for less than and greater than, respectively; as of Python +2.2, this is no longer allowed. In the future, other return values +may be assigned a different meaning.) + +A \member{tp_compare} handler may raise an exception. In this case it +should return a negative value. The caller has to test for the +exception using \cfunction{PyErr_Occurred()}. + Here is a sample implementation: |