From 5cffd8065a1fb7f0a97472632099f589a6dae869 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 9 Feb 2013 11:34:36 +0100 Subject: [PATCH] improve error message on failing exec() --- Cython/Utility/Builtins.c | 5 +++-- tests/run/exectest.pyx | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cython/Utility/Builtins.c b/Cython/Utility/Builtins.c index 0ead20e..7863a18 100644 --- a/Cython/Utility/Builtins.c +++ b/Cython/Utility/Builtins.c @@ -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 diff --git a/tests/run/exectest.pyx b/tests/run/exectest.pyx index 0311047..5a5cebe 100644 --- a/tests/run/exectest.pyx +++ b/tests/run/exectest.pyx @@ -113,3 +113,11 @@ def test_encoding_unicode(d1, d2): def test_compile(d): c = compile(u"b = a+c", u"", 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 {} -- 2.7.4