Skip to content

Commit a7446e3

Browse files
committed
Check the return code for PyErr_Warn() when warning about raising string
exceptions. This was triggered when 'warnings' had a filter set to "error" that caught the string exception deprecation warning.
1 parent a7444f4 commit a7446e3

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 2.5 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- Properly check if 'warnings' raises an exception (usually when a filter set
16+
to "error" is triggered) when raising a warning for raising string
17+
exceptions.
18+
1519
- CO_GENERATOR_ALLOWED is no longer defined, this behavior is the default.
1620
The name was removed from Include/code.h.
1721

Python/ceval.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,13 +2997,14 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
29972997
Py_DECREF(tmp);
29982998
}
29992999

3000-
if (PyString_CheckExact(type))
3000+
if (PyString_CheckExact(type)) {
30013001
/* Raising builtin string is deprecated but still allowed --
30023002
* do nothing. Raising an instance of a new-style str
30033003
* subclass is right out. */
3004-
PyErr_Warn(PyExc_PendingDeprecationWarning,
3005-
"raising a string exception is deprecated");
3006-
3004+
if (-1 == PyErr_Warn(PyExc_PendingDeprecationWarning,
3005+
"raising a string exception is deprecated"))
3006+
goto raise_error;
3007+
}
30073008
else if (PyClass_Check(type))
30083009
PyErr_NormalizeException(&type, &value, &tb);
30093010

0 commit comments

Comments
 (0)