summaryrefslogtreecommitdiffstats
path: root/Objects/methodobject.c
diff options
context:
space:
mode:
authorSteven Bethard <steven.bethard@gmail.com>2008-03-18 22:08:20 (GMT)
committerSteven Bethard <steven.bethard@gmail.com>2008-03-18 22:08:20 (GMT)
commit6a644f92efb35e75f81d183aebfff3260b1454e2 (patch)
tree47f1242459fa09e9087f58fdf7b935042e8ec9d0 /Objects/methodobject.c
parente8e22cf3c0d9e977bc9f13cfc535c026f92bc7aa (diff)
downloadcpython-6a644f92efb35e75f81d183aebfff3260b1454e2.zip
cpython-6a644f92efb35e75f81d183aebfff3260b1454e2.tar.gz
cpython-6a644f92efb35e75f81d183aebfff3260b1454e2.tar.bz2
Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code.
Diffstat (limited to 'Objects/methodobject.c')
-rw-r--r--Objects/methodobject.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index d661c47..5b9a364 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -223,6 +223,40 @@ meth_compare(PyCFunctionObject *a, PyCFunctionObject *b)
return 1;
}
+static PyObject *
+meth_richcompare(PyObject *self, PyObject *other, int op)
+{
+ PyCFunctionObject *a, *b;
+ PyObject *res;
+ int eq;
+
+ if ((op != Py_EQ && op != Py_NE) ||
+ !PyCFunction_Check(self) ||
+ !PyCFunction_Check(other))
+ {
+ /* Py3K warning if types are not equal and comparison isn't == or != */
+ if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
+ "builtin_function_or_method "
+ "inequality comparisons not supported in 3.x.") < 0) {
+ return NULL;
+ }
+
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ a = (PyCFunctionObject *)self;
+ b = (PyCFunctionObject *)other;
+ eq = a->m_self == b->m_self;
+ if (eq)
+ eq = a->m_ml->ml_meth == b->m_ml->ml_meth;
+ if (op == Py_EQ)
+ res = eq ? Py_True : Py_False;
+ else
+ res = eq ? Py_False : Py_True;
+ Py_INCREF(res);
+ return res;
+}
+
static long
meth_hash(PyCFunctionObject *a)
{
@@ -268,7 +302,7 @@ PyTypeObject PyCFunction_Type = {
0, /* tp_doc */
(traverseproc)meth_traverse, /* tp_traverse */
0, /* tp_clear */
- 0, /* tp_richcompare */
+ meth_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */