As discussed briefly on python-dev, add Pending Deprecation Warning

when a string exception is raised.  Note that raising string exceptions
is deprecated in an exception message.
This commit is contained in:
Neal Norwitz 2003-01-10 15:31:15 +00:00
parent 8e914d9a1d
commit 37aa066164

View file

@ -2733,7 +2733,8 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
/* Raising builtin string is deprecated but still allowed -- /* Raising builtin string is deprecated but still allowed --
* do nothing. Raising an instance of a new-style str * do nothing. Raising an instance of a new-style str
* subclass is right out. */ * subclass is right out. */
; PyErr_Warn(PyExc_PendingDeprecationWarning,
"raising a string exception is deprecated");
else if (PyClass_Check(type)) else if (PyClass_Check(type))
PyErr_NormalizeException(&type, &value, &tb); PyErr_NormalizeException(&type, &value, &tb);
@ -2757,8 +2758,9 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
/* Not something you can raise. You get an exception /* Not something you can raise. You get an exception
anyway, just not what you specified :-) */ anyway, just not what you specified :-) */
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"exceptions must be strings, classes, or " "exceptions must be classes, instances, or "
"instances, not %s", type->ob_type->tp_name); "strings (deprecated), not %s",
type->ob_type->tp_name);
goto raise_error; goto raise_error;
} }
PyErr_Restore(type, value, tb); PyErr_Restore(type, value, tb);