Add -3 option to the interpreter to warn about features that are
deprecated and will be changed/removed in Python 3.0.
This patch is mostly from Anthony. I tweaked some format and added
a little doc.
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 7d6ff61..daf64e0 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1688,7 +1688,7 @@
}
static PyObject *
-dict_has_key(register dictobject *mp, PyObject *key)
+dict_contains(register dictobject *mp, PyObject *key)
{
long hash;
dictentry *ep;
@@ -1706,6 +1706,16 @@
}
static PyObject *
+dict_has_key(register dictobject *mp, PyObject *key)
+{
+ if (Py_Py3kWarningFlag &&
+ PyErr_Warn(PyExc_DeprecationWarning,
+ "dict.has_key() not supported in 3.x") < 0)
+ return NULL;
+ return dict_contains(mp, key);
+}
+
+static PyObject *
dict_get(register dictobject *mp, PyObject *args)
{
PyObject *key;
@@ -1978,7 +1988,7 @@
"D.iteritems() -> an iterator over the (key, value) items of D");
static PyMethodDef mapp_methods[] = {
- {"__contains__",(PyCFunction)dict_has_key, METH_O | METH_COEXIST,
+ {"__contains__",(PyCFunction)dict_contains, METH_O | METH_COEXIST,
contains__doc__},
{"__getitem__", (PyCFunction)dict_subscript, METH_O | METH_COEXIST,
getitem__doc__},
diff --git a/Objects/object.c b/Objects/object.c
index 9e25467..8de6723 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -29,6 +29,7 @@
#endif /* Py_REF_DEBUG */
int Py_DivisionWarningFlag;
+int Py_Py3kWarningFlag;
/* Object allocation routines used by NEWOBJ and NEWVAROBJ macros.
These are used by the individual routines for object creation.