Skip to content

Commit 11ecb18

Browse files
author
benjamin.peterson
committed
Use PyErr_WarnPy3k throughout
git-svn-id: http://svn.python.org/projects/python/trunk@62518 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent ba8dfc2 commit 11ecb18

14 files changed

Lines changed: 47 additions & 88 deletions

Modules/arraymodule.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,10 +1257,8 @@ array. Also called as read.");
12571257
static PyObject *
12581258
array_fromfile_as_read(arrayobject *self, PyObject *args)
12591259
{
1260-
if (Py_Py3kWarningFlag &&
1261-
PyErr_Warn(PyExc_DeprecationWarning,
1262-
"array.read() not supported in 3.x; "
1263-
"use array.fromfile()") < 0)
1260+
if (PyErr_WarnPy3k("array.read() not supported in 3.x; "
1261+
"use array.fromfile()", 1) < 0)
12641262
return NULL;
12651263
return array_fromfile(self, args);
12661264
}
@@ -1298,10 +1296,8 @@ write.");
12981296
static PyObject *
12991297
array_tofile_as_write(arrayobject *self, PyObject *f)
13001298
{
1301-
if (Py_Py3kWarningFlag &&
1302-
PyErr_Warn(PyExc_DeprecationWarning,
1303-
"array.write() not supported in 3.x; "
1304-
"use array.tofile()") < 0)
1299+
if (PyErr_WarnPy3k("array.write() not supported in 3.x; "
1300+
"use array.tofile()", 1) < 0)
13051301
return NULL;
13061302
return array_tofile(self, f);
13071303
}

Objects/bufferobject.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
233233
Py_ssize_t offset = 0;
234234
Py_ssize_t size = Py_END_OF_BUFFER;
235235

236-
if (Py_Py3kWarningFlag &&
237-
PyErr_WarnEx(PyExc_DeprecationWarning,
238-
"buffer() not supported in 3.x; "
236+
if (PyErr_WarnPy3k("buffer() not supported in 3.x; "
239237
"use memoryview()", 1) < 0)
240238
return NULL;
241239

Objects/cellobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ static int
5555
cell_compare(PyCellObject *a, PyCellObject *b)
5656
{
5757
/* Py3K warning for comparisons */
58-
if (Py_Py3kWarningFlag &&
59-
PyErr_Warn(PyExc_DeprecationWarning,
60-
"cell comparisons not supported in 3.x") < 0) {
58+
if (PyErr_WarnPy3k("cell comparisons not supported in 3.x",
59+
1) < 0) {
6160
return -2;
6261
}
6362

Objects/codeobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,8 @@ code_richcompare(PyObject *self, PyObject *other, int op)
340340

341341
/* Py3K warning if types are not equal and comparison
342342
isn't == or != */
343-
if (Py_Py3kWarningFlag &&
344-
PyErr_Warn(PyExc_DeprecationWarning,
345-
"code inequality comparisons not supported "
346-
"in 3.x") < 0) {
343+
if (PyErr_WarnPy3k("code inequality comparisons not supported "
344+
"in 3.x", 1) < 0) {
347345
return NULL;
348346
}
349347

Objects/dictobject.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,10 +1778,8 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
17781778
}
17791779
else {
17801780
/* Py3K warning if comparison isn't == or != */
1781-
if (Py_Py3kWarningFlag &&
1782-
PyErr_Warn(PyExc_DeprecationWarning,
1783-
"dict inequality comparisons not supported "
1784-
"in 3.x") < 0) {
1781+
if (PyErr_WarnPy3k("dict inequality comparisons not supported "
1782+
"in 3.x", 1) < 0) {
17851783
return NULL;
17861784
}
17871785
res = Py_NotImplemented;
@@ -1811,10 +1809,8 @@ dict_contains(register PyDictObject *mp, PyObject *key)
18111809
static PyObject *
18121810
dict_has_key(register PyDictObject *mp, PyObject *key)
18131811
{
1814-
if (Py_Py3kWarningFlag &&
1815-
PyErr_Warn(PyExc_DeprecationWarning,
1816-
"dict.has_key() not supported in 3.x; "
1817-
"use the in operator") < 0)
1812+
if (PyErr_WarnPy3k("dict.has_key() not supported in 3.x; "
1813+
"use the in operator", 1) < 0)
18181814
return NULL;
18191815
return dict_contains(mp, key);
18201816
}

Objects/exceptions.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,19 @@ static PyMethodDef BaseException_methods[] = {
189189
static PyObject *
190190
BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
191191
{
192-
if (Py_Py3kWarningFlag) {
193-
if (PyErr_Warn(PyExc_DeprecationWarning,
194-
"__getitem__ not supported for exception "
195-
"classes in 3.x; use args attribute") == -1)
196-
return NULL;
197-
}
192+
if (PyErr_WarnPy3k("__getitem__ not supported for exception "
193+
"classes in 3.x; use args attribute", 1) < 0)
194+
return NULL;
198195
return PySequence_GetItem(self->args, index);
199196
}
200197

201198
static PyObject *
202199
BaseException_getslice(PyBaseExceptionObject *self,
203200
Py_ssize_t start, Py_ssize_t stop)
204201
{
205-
if (Py_Py3kWarningFlag) {
206-
if (PyErr_Warn(PyExc_DeprecationWarning,
207-
"__getslice__ not supported for exception "
208-
"classes in 3.x; use args attribute") == -1)
209-
return NULL;
210-
}
202+
if (PyErr_WarnPy3k("__getslice__ not supported for exception "
203+
"classes in 3.x; use args attribute", 1) < 0)
204+
return NULL;
211205
return PySequence_GetSlice(self->args, start, stop);
212206
}
213207

Objects/fileobject.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,9 +1910,7 @@ get_newlines(PyFileObject *f, void *closure)
19101910
static PyObject *
19111911
get_softspace(PyFileObject *f, void *closure)
19121912
{
1913-
if (Py_Py3kWarningFlag &&
1914-
PyErr_Warn(PyExc_DeprecationWarning,
1915-
"file.softspace not supported in 3.x") < 0)
1913+
if (PyErr_WarnPy3k("file.softspace not supported in 3.x", 1) < 0)
19161914
return NULL;
19171915
return PyInt_FromLong(f->f_softspace);
19181916
}
@@ -1921,9 +1919,7 @@ static int
19211919
set_softspace(PyFileObject *f, PyObject *value)
19221920
{
19231921
int new;
1924-
if (Py_Py3kWarningFlag &&
1925-
PyErr_Warn(PyExc_DeprecationWarning,
1926-
"file.softspace not supported in 3.x") < 0)
1922+
if (PyErr_WarnPy3k("file.softspace not supported in 3.x", 1) < 0)
19271923
return -1;
19281924

19291925
if (value == NULL) {

Objects/listobject.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,9 +2038,7 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
20382038
if (compare == Py_None)
20392039
compare = NULL;
20402040
if (compare != NULL &&
2041-
Py_Py3kWarningFlag &&
2042-
PyErr_Warn(PyExc_DeprecationWarning,
2043-
"the cmp argument is not supported in 3.x") < 0)
2041+
PyErr_WarnPy3k("the cmp argument is not supported in 3.x", 1) < 0)
20442042
return NULL;
20452043
if (keyfunc == Py_None)
20462044
keyfunc = NULL;

Objects/methodobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,8 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
235235
!PyCFunction_Check(other))
236236
{
237237
/* Py3K warning if types are not equal and comparison isn't == or != */
238-
if (Py_Py3kWarningFlag &&
239-
PyErr_Warn(PyExc_DeprecationWarning,
240-
"builtin_function_or_method inequality "
241-
"comparisons not supported in 3.x") < 0) {
238+
if (PyErr_WarnPy3k("builtin_function_or_method inequality "
239+
"comparisons not supported in 3.x", 1) < 0) {
242240
return NULL;
243241
}
244242

Objects/object.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,9 @@ try_3way_to_rich_compare(PyObject *v, PyObject *w, int op)
868868
/* Py3K warning if types are not equal and comparison isn't == or != */
869869
if (Py_Py3kWarningFlag &&
870870
v->ob_type != w->ob_type && op != Py_EQ && op != Py_NE &&
871-
PyErr_Warn(PyExc_DeprecationWarning,
871+
PyErr_WarnEx(PyExc_DeprecationWarning,
872872
"comparing unequal types not supported "
873-
"in 3.x") < 0) {
873+
"in 3.x", 1) < 0) {
874874
return NULL;
875875
}
876876

@@ -1691,9 +1691,9 @@ merge_list_attr(PyObject* dict, PyObject* obj, const char *attrname)
16911691
if (Py_Py3kWarningFlag &&
16921692
(strcmp(attrname, "__members__") == 0 ||
16931693
strcmp(attrname, "__methods__") == 0)) {
1694-
if (PyErr_Warn(PyExc_DeprecationWarning,
1694+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
16951695
"__members__ and __methods__ not "
1696-
"supported in 3.x") < 0) {
1696+
"supported in 3.x", 1) < 0) {
16971697
Py_XDECREF(list);
16981698
return -1;
16991699
}

0 commit comments

Comments
 (0)