Commit 5cffd806 authored by Stefan Behnel's avatar Stefan Behnel

improve error message on failing exec()

parent 6af1821f
......@@ -140,8 +140,9 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals)
#else
} else if (!PyString_Check(o)) {
#endif
PyErr_SetString(PyExc_TypeError,
"exec: arg 1 must be string, bytes or code object");
PyErr_Format(PyExc_TypeError,
"exec: arg 1 must be string, bytes or code object, got %.200s",
Py_TYPE(o)->tp_name);
goto bad;
}
#if PY_MAJOR_VERSION >= 3
......
......@@ -113,3 +113,11 @@ def test_encoding_unicode(d1, d2):
def test_compile(d):
c = compile(u"b = a+c", u"<string>", u"exec")
exec c in d
def exec_invalid_type(x):
"""
>>> exec_invalid_type(42)
Traceback (most recent call last):
TypeError: exec: arg 1 must be string, bytes or code object, got int
"""
exec x in {}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment