Skip to content

Commit 46fc337

Browse files
author
Skip Montanaro
committed
PyErr_Warn is deprecated in 2.5 - goes away for 3.0
1 parent 447e7c3 commit 46fc337

File tree

11 files changed

+40
-55
lines changed

11 files changed

+40
-55
lines changed

Doc/api/exceptions.tex

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,6 @@ \chapter{Exception Handling \label{exceptionHandling}}
296296
command line documentation. There is no C API for warning control.
297297
\end{cfuncdesc}
298298

299-
\begin{cfuncdesc}{int}{PyErr_Warn}{PyObject *category, char *message}
300-
Issue a warning message. The \var{category} argument is a warning
301-
category (see below) or \NULL; the \var{message} argument is a
302-
message string. The warning will appear to be issued from the function
303-
calling \cfunction{PyErr_Warn()}, equivalent to calling
304-
\cfunction{PyErr_WarnEx()} with a \var{stacklevel} of 1.
305-
306-
Deprecated; use \cfunction{PyErr_WarnEx()} instead.
307-
\end{cfuncdesc}
308-
309299
\begin{cfuncdesc}{int}{PyErr_WarnExplicit}{PyObject *category,
310300
const char *message, const char *filename, int lineno,
311301
const char *module, PyObject *registry}

Include/pyerrors.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,6 @@ PyAPI_FUNC(int) PyErr_WarnEx(PyObject *category, const char *msg,
213213
PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *,
214214
const char *, int,
215215
const char *, PyObject *);
216-
/* PyErr_Warn is only for backwards compatability and will be removed.
217-
Use PyErr_WarnEx instead. */
218-
#define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1)
219216

220217
/* In sigcheck.c or signalmodule.c */
221218
PyAPI_FUNC(int) PyErr_CheckSignals(void);

Modules/_bsddb.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static int makeDBError(int err)
546546
}
547547
_db_errmsg[0] = 0;
548548
#ifdef HAVE_WARNINGS
549-
exceptionRaised = PyErr_Warn(PyExc_RuntimeWarning, errTxt);
549+
exceptionRaised = PyErr_WarnEx(PyExc_RuntimeWarning, errTxt, 1);
550550
#else
551551
fprintf(stderr, errTxt);
552552
fprintf(stderr, "\n");
@@ -859,8 +859,10 @@ DB_dealloc(DBObject* self)
859859
MYDB_END_ALLOW_THREADS;
860860
#ifdef HAVE_WARNINGS
861861
} else {
862-
PyErr_Warn(PyExc_RuntimeWarning,
863-
"DB could not be closed in destructor: DBEnv already closed");
862+
PyErr_WarnEx(PyExc_RuntimeWarning,
863+
"DB could not be closed in destructor:"
864+
" DBEnv already closed",
865+
1);
864866
#endif
865867
}
866868
self->db = NULL;
@@ -1031,8 +1033,10 @@ DBTxn_dealloc(DBTxnObject* self)
10311033
txn_abort(self->txn);
10321034
#endif
10331035
MYDB_END_ALLOW_THREADS;
1034-
PyErr_Warn(PyExc_RuntimeWarning,
1035-
"DBTxn aborted in destructor. No prior commit() or abort().");
1036+
PyErr_WarnEx(PyExc_RuntimeWarning,
1037+
"DBTxn aborted in destructor. "
1038+
" No prior commit() or abort().",
1039+
1);
10361040
}
10371041
#endif
10381042

Modules/_ctypes/callbacks.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print()
225225
else if (keep == Py_None) /* Nothing to keep */
226226
Py_DECREF(keep);
227227
else if (setfunc != getentry("O")->setfunc) {
228-
if (-1 == PyErr_Warn(PyExc_RuntimeWarning,
229-
"memory leak in callback function."))
228+
if (-1 == PyErr_WarnEx(PyExc_RuntimeWarning,
229+
"memory leak in callback function.",
230+
1))
230231
PyErr_WriteUnraisable(callable);
231232
}
232233
}

Modules/mmapmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,9 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
998998
XXX: fileno == 0 is a valid fd, but was accepted prior to 2.5.
999999
XXX: Should this code be added?
10001000
if (fileno == 0)
1001-
PyErr_Warn(PyExc_DeprecationWarning,
1002-
"don't use 0 for anonymous memory");
1001+
PyErr_WarnEx(PyExc_DeprecationWarning,
1002+
"don't use 0 for anonymous memory",
1003+
1);
10031004
*/
10041005
if (fileno != -1 && fileno != 0) {
10051006
fh = (HANDLE)_get_osfhandle(fileno);

Modules/posixmodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,8 +5344,9 @@ posix_tempnam(PyObject *self, PyObject *args)
53445344
if (!PyArg_ParseTuple(args, "|zz:tempnam", &dir, &pfx))
53455345
return NULL;
53465346

5347-
if (PyErr_Warn(PyExc_RuntimeWarning,
5348-
"tempnam is a potential security risk to your program") < 0)
5347+
if (PyErr_WarnEx(PyExc_RuntimeWarning,
5348+
"tempnam is a potential security risk to your program",
5349+
1) < 0)
53495350
return NULL;
53505351

53515352
#ifdef MS_WINDOWS
@@ -5391,8 +5392,9 @@ posix_tmpnam(PyObject *self, PyObject *noargs)
53915392
char buffer[L_tmpnam];
53925393
char *name;
53935394

5394-
if (PyErr_Warn(PyExc_RuntimeWarning,
5395-
"tmpnam is a potential security risk to your program") < 0)
5395+
if (PyErr_WarnEx(PyExc_RuntimeWarning,
5396+
"tmpnam is a potential security risk to your program",
5397+
1) < 0)
53965398
return NULL;
53975399

53985400
#ifdef USE_TMPNAM_R

Objects/unicodeobject.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5990,15 +5990,16 @@ PyObject *PyUnicode_RichCompare(PyObject *left,
59905990
if (!PyErr_ExceptionMatches(PyExc_UnicodeDecodeError))
59915991
return NULL;
59925992
PyErr_Clear();
5993-
if (PyErr_Warn(PyExc_UnicodeWarning,
5994-
(op == Py_EQ) ?
5995-
"Unicode equal comparison "
5996-
"failed to convert both arguments to Unicode - "
5997-
"interpreting them as being unequal" :
5998-
"Unicode unequal comparison "
5999-
"failed to convert both arguments to Unicode - "
6000-
"interpreting them as being unequal"
6001-
) < 0)
5993+
if (PyErr_WarnEx(PyExc_UnicodeWarning,
5994+
(op == Py_EQ) ?
5995+
"Unicode equal comparison "
5996+
"failed to convert both arguments to Unicode - "
5997+
"interpreting them as being unequal"
5998+
:
5999+
"Unicode unequal comparison "
6000+
"failed to convert both arguments to Unicode - "
6001+
"interpreting them as being unequal",
6002+
1) < 0)
60026003
return NULL;
60036004
result = (op == Py_NE);
60046005
return PyBool_FromLong(result);

Python/errors.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -670,17 +670,6 @@ PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level)
670670
}
671671
}
672672

673-
/* PyErr_Warn is only for backwards compatability and will be removed.
674-
Use PyErr_WarnEx instead. */
675-
676-
#undef PyErr_Warn
677-
678-
PyAPI_FUNC(int)
679-
PyErr_Warn(PyObject *category, char *message)
680-
{
681-
return PyErr_WarnEx(category, message, 1);
682-
}
683-
684673
/* Warning with explicit origin */
685674
int
686675
PyErr_WarnExplicit(PyObject *category, const char *message,

Python/import.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,8 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
13201320
sprintf(warnstr, "Not importing directory "
13211321
"'%.*s': missing __init__.py",
13221322
MAXPATHLEN, buf);
1323-
if (PyErr_Warn(PyExc_ImportWarning,
1324-
warnstr)) {
1323+
if (PyErr_WarnEx(PyExc_ImportWarning,
1324+
warnstr, 1)) {
13251325
return NULL;
13261326
}
13271327
}
@@ -1339,8 +1339,8 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
13391339
sprintf(warnstr, "Not importing directory "
13401340
"'%.*s': missing __init__.py",
13411341
MAXPATHLEN, buf);
1342-
if (PyErr_Warn(PyExc_ImportWarning,
1343-
warnstr)) {
1342+
if (PyErr_WarnEx(PyExc_ImportWarning,
1343+
warnstr, 1)) {
13441344
return NULL;
13451345
}
13461346
}

Python/modsupport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Py_InitModule4(const char *name, PyMethodDef *methods, const char *doc,
4242
api_version_warning, name,
4343
PYTHON_API_VERSION, name,
4444
module_api_version);
45-
if (PyErr_Warn(PyExc_RuntimeWarning, message))
45+
if (PyErr_WarnEx(PyExc_RuntimeWarning, message, 1))
4646
return NULL;
4747
}
4848
/* Make sure name is fully qualified.

0 commit comments

Comments
 (0)