Index: Lib/test/test_py3kwarn.py =================================================================== --- Lib/test/test_py3kwarn.py (revision 61671) +++ Lib/test/test_py3kwarn.py (working copy) @@ -94,6 +94,19 @@ with catch_warning() as w: self.assertWarning(sorted(lst, cmp), w, expected) + def test_operator(self): + from operator import isCallable, sequenceIncludes + + callable_warn = "operator.isCallable() is not supported in 3.x. "\ + "Use hasattr(o, '__call__')." + seq_warn = "operator.sequenceIncludes() is not supported "\ + "in 3.x. Use operator.contains()." + + with catch_warning() as w: + self.assertWarning(isCallable(self), w, callable_warn) + with catch_warning() as w: + self.assertWarning(sequenceIncludes(range(3), 2), w, seq_warn) + def test_main(): run_unittest(TestPy3KWarnings) Index: Modules/operator.c =================================================================== --- Modules/operator.c (revision 61671) +++ Modules/operator.c (working copy) @@ -65,7 +65,32 @@ 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. */ +int +op_isCallable(PyObject *x) +{ + if (Py_Py3kWarningFlag && + PyErr_WarnEx(PyExc_DeprecationWarning, + "operator.isCallable() is not supported in 3.x. " + "Use hasattr(o, '__call__').", 1) < 0) + return -1; + else + return PyCallable_Check(x); +} + +int +op_sequenceIncludes(PyObject *seq, PyObject* ob) +{ + if (Py_Py3kWarningFlag && + PyErr_WarnEx(PyExc_DeprecationWarning, + "operator.sequenceIncludes() is not supported " + "in 3.x. Use operator.contains().", 1) < 0) + return -1; + else + return PySequence_Contains(seq, ob); +} + +spami(isCallable , op_isCallable) spami(isNumberType , PyNumber_Check) spami(truth , PyObject_IsTrue) spam2(op_add , PyNumber_Add) @@ -104,7 +129,7 @@ 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)