Use PyErr_WarnPy3k throughout

This commit is contained in:
Benjamin Peterson 2008-04-27 03:01:45 +00:00
parent a692c4df63
commit 9f4f48114f
14 changed files with 47 additions and 88 deletions

View file

@ -1257,10 +1257,8 @@ array. Also called as read.");
static PyObject * static PyObject *
array_fromfile_as_read(arrayobject *self, PyObject *args) array_fromfile_as_read(arrayobject *self, PyObject *args)
{ {
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("array.read() not supported in 3.x; "
PyErr_Warn(PyExc_DeprecationWarning, "use array.fromfile()", 1) < 0)
"array.read() not supported in 3.x; "
"use array.fromfile()") < 0)
return NULL; return NULL;
return array_fromfile(self, args); return array_fromfile(self, args);
} }
@ -1298,10 +1296,8 @@ write.");
static PyObject * static PyObject *
array_tofile_as_write(arrayobject *self, PyObject *f) array_tofile_as_write(arrayobject *self, PyObject *f)
{ {
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("array.write() not supported in 3.x; "
PyErr_Warn(PyExc_DeprecationWarning, "use array.tofile()", 1) < 0)
"array.write() not supported in 3.x; "
"use array.tofile()") < 0)
return NULL; return NULL;
return array_tofile(self, f); return array_tofile(self, f);
} }

View file

@ -233,9 +233,7 @@ buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
Py_ssize_t offset = 0; Py_ssize_t offset = 0;
Py_ssize_t size = Py_END_OF_BUFFER; Py_ssize_t size = Py_END_OF_BUFFER;
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("buffer() not supported in 3.x; "
PyErr_WarnEx(PyExc_DeprecationWarning,
"buffer() not supported in 3.x; "
"use memoryview()", 1) < 0) "use memoryview()", 1) < 0)
return NULL; return NULL;

View file

@ -55,9 +55,8 @@ static int
cell_compare(PyCellObject *a, PyCellObject *b) cell_compare(PyCellObject *a, PyCellObject *b)
{ {
/* Py3K warning for comparisons */ /* Py3K warning for comparisons */
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("cell comparisons not supported in 3.x",
PyErr_Warn(PyExc_DeprecationWarning, 1) < 0) {
"cell comparisons not supported in 3.x") < 0) {
return -2; return -2;
} }

View file

@ -340,10 +340,8 @@ code_richcompare(PyObject *self, PyObject *other, int op)
/* Py3K warning if types are not equal and comparison /* Py3K warning if types are not equal and comparison
isn't == or != */ isn't == or != */
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("code inequality comparisons not supported "
PyErr_Warn(PyExc_DeprecationWarning, "in 3.x", 1) < 0) {
"code inequality comparisons not supported "
"in 3.x") < 0) {
return NULL; return NULL;
} }

View file

@ -1778,10 +1778,8 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
} }
else { else {
/* Py3K warning if comparison isn't == or != */ /* Py3K warning if comparison isn't == or != */
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("dict inequality comparisons not supported "
PyErr_Warn(PyExc_DeprecationWarning, "in 3.x", 1) < 0) {
"dict inequality comparisons not supported "
"in 3.x") < 0) {
return NULL; return NULL;
} }
res = Py_NotImplemented; res = Py_NotImplemented;
@ -1811,10 +1809,8 @@ dict_contains(register PyDictObject *mp, PyObject *key)
static PyObject * static PyObject *
dict_has_key(register PyDictObject *mp, PyObject *key) dict_has_key(register PyDictObject *mp, PyObject *key)
{ {
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("dict.has_key() not supported in 3.x; "
PyErr_Warn(PyExc_DeprecationWarning, "use the in operator", 1) < 0)
"dict.has_key() not supported in 3.x; "
"use the in operator") < 0)
return NULL; return NULL;
return dict_contains(mp, key); return dict_contains(mp, key);
} }

View file

@ -189,12 +189,9 @@ static PyMethodDef BaseException_methods[] = {
static PyObject * static PyObject *
BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index) BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
{ {
if (Py_Py3kWarningFlag) { if (PyErr_WarnPy3k("__getitem__ not supported for exception "
if (PyErr_Warn(PyExc_DeprecationWarning, "classes in 3.x; use args attribute", 1) < 0)
"__getitem__ not supported for exception " return NULL;
"classes in 3.x; use args attribute") == -1)
return NULL;
}
return PySequence_GetItem(self->args, index); return PySequence_GetItem(self->args, index);
} }
@ -202,12 +199,9 @@ static PyObject *
BaseException_getslice(PyBaseExceptionObject *self, BaseException_getslice(PyBaseExceptionObject *self,
Py_ssize_t start, Py_ssize_t stop) Py_ssize_t start, Py_ssize_t stop)
{ {
if (Py_Py3kWarningFlag) { if (PyErr_WarnPy3k("__getslice__ not supported for exception "
if (PyErr_Warn(PyExc_DeprecationWarning, "classes in 3.x; use args attribute", 1) < 0)
"__getslice__ not supported for exception " return NULL;
"classes in 3.x; use args attribute") == -1)
return NULL;
}
return PySequence_GetSlice(self->args, start, stop); return PySequence_GetSlice(self->args, start, stop);
} }

View file

@ -1910,9 +1910,7 @@ get_newlines(PyFileObject *f, void *closure)
static PyObject * static PyObject *
get_softspace(PyFileObject *f, void *closure) get_softspace(PyFileObject *f, void *closure)
{ {
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("file.softspace not supported in 3.x", 1) < 0)
PyErr_Warn(PyExc_DeprecationWarning,
"file.softspace not supported in 3.x") < 0)
return NULL; return NULL;
return PyInt_FromLong(f->f_softspace); return PyInt_FromLong(f->f_softspace);
} }
@ -1921,9 +1919,7 @@ static int
set_softspace(PyFileObject *f, PyObject *value) set_softspace(PyFileObject *f, PyObject *value)
{ {
int new; int new;
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("file.softspace not supported in 3.x", 1) < 0)
PyErr_Warn(PyExc_DeprecationWarning,
"file.softspace not supported in 3.x") < 0)
return -1; return -1;
if (value == NULL) { if (value == NULL) {

View file

@ -2038,9 +2038,7 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
if (compare == Py_None) if (compare == Py_None)
compare = NULL; compare = NULL;
if (compare != NULL && if (compare != NULL &&
Py_Py3kWarningFlag && PyErr_WarnPy3k("the cmp argument is not supported in 3.x", 1) < 0)
PyErr_Warn(PyExc_DeprecationWarning,
"the cmp argument is not supported in 3.x") < 0)
return NULL; return NULL;
if (keyfunc == Py_None) if (keyfunc == Py_None)
keyfunc = NULL; keyfunc = NULL;

View file

@ -235,10 +235,8 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
!PyCFunction_Check(other)) !PyCFunction_Check(other))
{ {
/* Py3K warning if types are not equal and comparison isn't == or != */ /* Py3K warning if types are not equal and comparison isn't == or != */
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("builtin_function_or_method inequality "
PyErr_Warn(PyExc_DeprecationWarning, "comparisons not supported in 3.x", 1) < 0) {
"builtin_function_or_method inequality "
"comparisons not supported in 3.x") < 0) {
return NULL; return NULL;
} }

View file

@ -868,9 +868,9 @@ try_3way_to_rich_compare(PyObject *v, PyObject *w, int op)
/* Py3K warning if types are not equal and comparison isn't == or != */ /* Py3K warning if types are not equal and comparison isn't == or != */
if (Py_Py3kWarningFlag && if (Py_Py3kWarningFlag &&
v->ob_type != w->ob_type && op != Py_EQ && op != Py_NE && v->ob_type != w->ob_type && op != Py_EQ && op != Py_NE &&
PyErr_Warn(PyExc_DeprecationWarning, PyErr_WarnEx(PyExc_DeprecationWarning,
"comparing unequal types not supported " "comparing unequal types not supported "
"in 3.x") < 0) { "in 3.x", 1) < 0) {
return NULL; return NULL;
} }
@ -1691,9 +1691,9 @@ merge_list_attr(PyObject* dict, PyObject* obj, const char *attrname)
if (Py_Py3kWarningFlag && if (Py_Py3kWarningFlag &&
(strcmp(attrname, "__members__") == 0 || (strcmp(attrname, "__members__") == 0 ||
strcmp(attrname, "__methods__") == 0)) { strcmp(attrname, "__methods__") == 0)) {
if (PyErr_Warn(PyExc_DeprecationWarning, if (PyErr_WarnEx(PyExc_DeprecationWarning,
"__members__ and __methods__ not " "__members__ and __methods__ not "
"supported in 3.x") < 0) { "supported in 3.x", 1) < 0) {
Py_XDECREF(list); Py_XDECREF(list);
return -1; return -1;
} }

View file

@ -608,9 +608,9 @@ type_richcompare(PyObject *v, PyObject *w, int op)
/* Py3K warning if comparison isn't == or != */ /* Py3K warning if comparison isn't == or != */
if (Py_Py3kWarningFlag && op != Py_EQ && op != Py_NE && if (Py_Py3kWarningFlag && op != Py_EQ && op != Py_NE &&
PyErr_Warn(PyExc_DeprecationWarning, PyErr_WarnEx(PyExc_DeprecationWarning,
"type inequality comparisons not supported " "type inequality comparisons not supported "
"in 3.x") < 0) { "in 3.x", 1) < 0) {
return NULL; return NULL;
} }

View file

@ -165,10 +165,8 @@ builtin_apply(PyObject *self, PyObject *args)
PyObject *func, *alist = NULL, *kwdict = NULL; PyObject *func, *alist = NULL, *kwdict = NULL;
PyObject *t = NULL, *retval = NULL; PyObject *t = NULL, *retval = NULL;
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("apply() not supported in 3.x; "
PyErr_Warn(PyExc_DeprecationWarning, "use func(*args, **kwargs)", 1) < 0)
"apply() not supported in 3.x; "
"use func(*args, **kwargs)") < 0)
return NULL; return NULL;
if (!PyArg_UnpackTuple(args, "apply", 1, 3, &func, &alist, &kwdict)) if (!PyArg_UnpackTuple(args, "apply", 1, 3, &func, &alist, &kwdict))
@ -225,10 +223,8 @@ Return the binary representation of an integer or long integer.");
static PyObject * static PyObject *
builtin_callable(PyObject *self, PyObject *v) builtin_callable(PyObject *self, PyObject *v)
{ {
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("callable() not supported in 3.x; "
PyErr_Warn(PyExc_DeprecationWarning, "use hasattr(o, '__call__')", 1) < 0)
"callable() not supported in 3.x; "
"use hasattr(o, '__call__')") < 0)
return NULL; return NULL;
return PyBool_FromLong((long)PyCallable_Check(v)); return PyBool_FromLong((long)PyCallable_Check(v));
} }
@ -438,9 +434,7 @@ builtin_coerce(PyObject *self, PyObject *args)
PyObject *v, *w; PyObject *v, *w;
PyObject *res; PyObject *res;
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("coerce() not supported in 3.x", 1) < 0)
PyErr_Warn(PyExc_DeprecationWarning,
"coerce() not supported in 3.x") < 0)
return NULL; return NULL;
if (!PyArg_UnpackTuple(args, "coerce", 2, 2, &v, &w)) if (!PyArg_UnpackTuple(args, "coerce", 2, 2, &v, &w))
@ -709,9 +703,8 @@ builtin_execfile(PyObject *self, PyObject *args)
PyCompilerFlags cf; PyCompilerFlags cf;
int exists; int exists;
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("execfile() not supported in 3.x; use exec()",
PyErr_Warn(PyExc_DeprecationWarning, 1) < 0)
"execfile() not supported in 3.x; use exec()") < 0)
return NULL; return NULL;
if (!PyArg_ParseTuple(args, "s|O!O:execfile", if (!PyArg_ParseTuple(args, "s|O!O:execfile",
@ -937,10 +930,8 @@ builtin_map(PyObject *self, PyObject *args)
n--; n--;
if (func == Py_None) { if (func == Py_None) {
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("map(None, ...) not supported in 3.x; "
PyErr_Warn(PyExc_DeprecationWarning, "use list(...)", 1) < 0)
"map(None, ...) not supported in 3.x; "
"use list(...)") < 0)
return NULL; return NULL;
if (n == 1) { if (n == 1) {
/* map(None, S) is the same as list(S). */ /* map(None, S) is the same as list(S). */
@ -1967,10 +1958,8 @@ builtin_reduce(PyObject *self, PyObject *args)
{ {
PyObject *seq, *func, *result = NULL, *it; PyObject *seq, *func, *result = NULL, *it;
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("reduce() not supported in 3.x; "
PyErr_Warn(PyExc_DeprecationWarning, "use functools.reduce()", 1) < 0)
"reduce() not supported in 3.x; "
"use functools.reduce()") < 0)
return NULL; return NULL;
if (!PyArg_UnpackTuple(args, "reduce", 2, 3, &func, &seq, &result)) if (!PyArg_UnpackTuple(args, "reduce", 2, 3, &func, &seq, &result))
@ -2045,9 +2034,8 @@ sequence is empty.");
static PyObject * static PyObject *
builtin_reload(PyObject *self, PyObject *v) builtin_reload(PyObject *self, PyObject *v)
{ {
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("In 3.x, reload() is renamed to imp.reload()",
PyErr_Warn(PyExc_DeprecationWarning, 1) < 0)
"reload() not supported in 3.x; use imp.reload()") < 0)
return NULL; return NULL;
return PyImport_ReloadModule(v); return PyImport_ReloadModule(v);

View file

@ -3164,9 +3164,9 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
assert(PyExceptionClass_Check(type)); assert(PyExceptionClass_Check(type));
if (Py_Py3kWarningFlag && PyClass_Check(type)) { if (Py_Py3kWarningFlag && PyClass_Check(type)) {
if (PyErr_Warn(PyExc_DeprecationWarning, if (PyErr_WarnEx(PyExc_DeprecationWarning,
"exceptions must derive from BaseException " "exceptions must derive from BaseException "
"in 3.x") == -1) "in 3.x", 1) == -1)
goto raise_error; goto raise_error;
} }

View file

@ -172,10 +172,8 @@ sys_exc_clear(PyObject *self, PyObject *noargs)
PyThreadState *tstate; PyThreadState *tstate;
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
if (Py_Py3kWarningFlag && if (PyErr_WarnPy3k("sys.exc_clear() not supported in 3.x; "
PyErr_Warn(PyExc_DeprecationWarning, "use except clauses", 1) < 0)
"sys.exc_clear() not supported in 3.x; "
"use except clauses") < 0)
return NULL; return NULL;
tstate = PyThreadState_GET(); tstate = PyThreadState_GET();