diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2009-07-05 04:22:40 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2009-07-05 04:22:40 (GMT) |
commit | 0fe799151fc9e485f9c001fa9138e4ca77069b98 (patch) | |
tree | 91498cda1e4d3df688d8c3b80629307c816f7f5a /Modules | |
parent | e7a0cc2aa86d984691b0612e13020fbce16d9b09 (diff) | |
download | cpython-0fe799151fc9e485f9c001fa9138e4ca77069b98.zip cpython-0fe799151fc9e485f9c001fa9138e4ca77069b98.tar.gz cpython-0fe799151fc9e485f9c001fa9138e4ca77069b98.tar.bz2 |
Issue 2370: Add Python 3 warnings for the removal of operator.isCallable and
operator.sequenceIncludes.
Patch contributed by Jeff Balogh (and updated slightly by me).
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/operator.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/Modules/operator.c b/Modules/operator.c index fd98efd..78b7796 100644 --- a/Modules/operator.c +++ b/Modules/operator.c @@ -65,7 +65,26 @@ used for special class methods; variants without leading and trailing\n\ if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ return PyObject_RichCompare(a1,a2,A); } -spami(isCallable , PyCallable_Check) +/* Deprecated operators that need warnings. */ +static int +op_isCallable(PyObject *x) +{ + if (PyErr_WarnPy3k("operator.isCallable() is not supported in 3.x. " + "Use hasattr(obj, '__call__').", 1) < 0) + return -1; + return PyCallable_Check(x); +} + +static int +op_sequenceIncludes(PyObject *seq, PyObject* ob) +{ + if (PyErr_WarnPy3k("operator.sequenceIncludes() is not supported " + "in 3.x. Use operator.contains().", 1) < 0) + return -1; + return PySequence_Contains(seq, ob); +} + +spami(isCallable , op_isCallable) spami(isNumberType , PyNumber_Check) spami(truth , PyObject_IsTrue) spam2(op_add , PyNumber_Add) @@ -104,7 +123,7 @@ spamoi(op_repeat , PySequence_Repeat) spam2(op_iconcat , PySequence_InPlaceConcat) spamoi(op_irepeat , PySequence_InPlaceRepeat) spami2b(op_contains , PySequence_Contains) -spami2b(sequenceIncludes, PySequence_Contains) +spami2b(sequenceIncludes, op_sequenceIncludes) spamn2(indexOf , PySequence_Index) spamn2(countOf , PySequence_Count) spami(isMappingType , PyMapping_Check) |