diff options
author | stratakis <cstratak@redhat.com> | 2017-11-02 10:32:54 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-11-02 10:32:54 (GMT) |
commit | e8b19656396381407ad91473af5da8b0d4346e88 (patch) | |
tree | 16638970d5014728a49808d0c80c4af0fe6ccb91 /Doc | |
parent | 4f469c096628af730b17798d0ebfd8925bfde836 (diff) | |
download | cpython-e8b19656396381407ad91473af5da8b0d4346e88.zip cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.gz cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.bz2 |
bpo-23699: Use a macro to reduce boilerplate code in rich comparison functions (GH-793)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/c-api/typeobj.rst | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index 0b4577f..3bdf45a 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -623,6 +623,22 @@ type objects) *must* have the :attr:`ob_size` field. | :const:`Py_GE` | ``>=`` | +----------------+------------+ + The following macro is defined to ease writing rich comparison functions: + + .. c:function:: PyObject *Py_RETURN_RICHCOMPARE(VAL_A, VAL_B, int op) + + Return ``Py_True`` or ``Py_False`` from the function, depending on the + result of a comparison. + VAL_A and VAL_B must be orderable by C comparison operators (for example, + they may be C ints or floats). The third argument specifies the requested + operation, as for :c:func:`PyObject_RichCompare`. + + The return value's reference count is properly incremented. + + On error, sets an exception and returns NULL from the function. + + .. versionadded:: 3.7 + .. c:member:: Py_ssize_t PyTypeObject.tp_weaklistoffset |