Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37aa066

Browse files
committed
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.
1 parent 8e914d9 commit 37aa066

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Python/ceval.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,8 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
27332733
/* Raising builtin string is deprecated but still allowed --
27342734
* do nothing. Raising an instance of a new-style str
27352735
* subclass is right out. */
2736-
;
2736+
PyErr_Warn(PyExc_PendingDeprecationWarning,
2737+
"raising a string exception is deprecated");
27372738

27382739
else if (PyClass_Check(type))
27392740
PyErr_NormalizeException(&type, &value, &tb);
@@ -2757,8 +2758,9 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
27572758
/* Not something you can raise. You get an exception
27582759
anyway, just not what you specified :-) */
27592760
PyErr_Format(PyExc_TypeError,
2760-
"exceptions must be strings, classes, or "
2761-
"instances, not %s", type->ob_type->tp_name);
2761+
"exceptions must be classes, instances, or "
2762+
"strings (deprecated), not %s",
2763+
type->ob_type->tp_name);
27622764
goto raise_error;
27632765
}
27642766
PyErr_Restore(type, value, tb);

0 commit comments

Comments
 (0)