Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
890a49a6
Kaydet (Commit)
890a49a6
authored
Mar 31, 2009
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#1717: fix-up docs for comparison in newtypes document.
üst
32d68c27
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
44 deletions
+47
-44
newtypes.rst
Doc/extending/newtypes.rst
+47
-44
No files found.
Doc/extending/newtypes.rst
Dosyayı görüntüle @
890a49a6
...
@@ -1231,50 +1231,53 @@ example that simply raises an exception; if this were really all you wanted, the
...
@@ -1231,50 +1231,53 @@ example that simply raises an exception; if this were really all you wanted, the
return -1;
return -1;
}
}
.. XXX tp_compare is dead; need to rewrite for tp_richcompare!
Object Comparison
-----------------
Object Comparison
-----------------
::
::
richcmpfunc tp_richcompare;
cmpfunc tp_compare;
The :attr:`tp_richcompare` handler is called when comparisons are needed. It is
analogous to the :ref:`rich comparison methods <richcmpfuncs>`, like
The :attr:`tp_compare` handler is called when comparisons are needed and the
:meth:`__lt__`, and also called by :cfunc:`PyObject_RichCompare` and
object does not implement the specific rich comparison method which matches the
:cfunc:`PyObject_RichCompareBool`.
requested comparison. (It is always used if defined and the
:cfunc:`PyObject_Compare` or :cfunc:`PyObject_Cmp` functions are used, or if
This function is called with two Python objects and the operator as arguments,
:func:`cmp` is used from Python.) It is analogous to the :meth:`__cmp__` method.
where the operator is one of ``Py_EQ``, ``Py_NE``, ``Py_LE``, ``Py_GT``,
This function should return ``-1`` if *obj1* is less than *obj2*, ``0`` if they
``Py_LT`` or ``Py_GT``. It should compare the two objects with respect to the
are equal, and ``1`` if *obj1* is greater than *obj2*. (It was previously
specified operator and return ``Py_True`` or ``Py_False`` if the comparison is
allowed to return arbitrary negative or positive integers for less than and
successfull, ``Py_NotImplemented`` to indicate that comparison is not
greater than, respectively; as of Python 2.2, this is no longer allowed. In the
implemented and the other object's comparison method should be tried, or *NULL*
future, other return values may be assigned a different meaning.)
if an exception was set.
A :attr:`tp_compare` handler may raise an exception. In this case it should
Here is a sample implementation, for a datatype that is considered equal if the
return a negative value. The caller has to test for the exception using
size of an internal pointer is equal::
:cfunc:`PyErr_Occurred`.
static int
Here is a sample implementation::
newdatatype_richcmp(PyObject *obj1, PyObject *obj2, int op)
{
static int
PyObject *result;
newdatatype_compare(newdatatypeobject * obj1, newdatatypeobject * obj2)
int c, size1, size2;
{
long result;
/* code to make sure that both arguments are of type
newdatatype omitted */
if (obj1->obj_UnderlyingDatatypePtr->size <
obj2->obj_UnderlyingDatatypePtr->size) {
size1 = obj1->obj_UnderlyingDatatypePtr->size;
result = -1;
size2 = obj2->obj_UnderlyingDatatypePtr->size;
}
else if (obj1->obj_UnderlyingDatatypePtr->size >
switch (op) {
obj2->obj_UnderlyingDatatypePtr->size) {
case Py_LT: c = size1 < size2; break;
result = 1;
case Py_LE: c = size1 <= size2; break;
}
case Py_EQ: c = size1 == size2; break;
else {
case Py_NE: c = size1 != size2; break;
result = 0;
case Py_GT: c = size1 > size2; break;
}
case Py_GE: c = size1 >= size2; break;
return result;
}
}
result = c ? Py_True : Py_False;
Py_INCREF(result);
return result;
}
Abstract Protocol Support
Abstract Protocol Support
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment