Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a59445

Browse files
committed
Document required return values -1, 0, 1 for tp_compare handler, as
suggested in SF patch #424475. Also document exception return.
1 parent c993315 commit 7a59445

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Doc/ext/newtypes.tex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,19 @@ \subsection{Object Comparison}
622622
and the \cfunction{PyObject_Compare()} or \cfunction{PyObject_Cmp()}
623623
functions are used, or if \function{cmp()} is used from Python.)
624624
It is analogous to the \method{__cmp__()} method. This function
625-
should return a negative integer if \var{obj1} is less than
626-
\var{obj2}, \code{0} if they are equal, and a positive integer if
625+
should return \code{-1} if \var{obj1} is less than
626+
\var{obj2}, \code{0} if they are equal, and \code{1} if
627627
\var{obj1} is greater than
628628
\var{obj2}.
629+
(It was previously allowed to return arbitrary negative or positive
630+
integers for less than and greater than, respectively; as of Python
631+
2.2, this is no longer allowed. In the future, other return values
632+
may be assigned a different meaning.)
633+
634+
A \member{tp_compare} handler may raise an exception. In this case it
635+
should return a negative value. The caller has to test for the
636+
exception using \cfunction{PyErr_Occurred()}.
637+
629638

630639
Here is a sample implementation:
631640

0 commit comments

Comments
 (0)