Commit 513ffe81 authored by Raymond Hettinger's avatar Raymond Hettinger

* Fix missing return after error message is set.

* Add a test case that would have caught it.
parent 2f55eb4c
......@@ -281,6 +281,7 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(eval('dir()', g, m), list('xyz'))
self.assertEqual(eval('globals()', g, m), g)
self.assertEqual(eval('locals()', g, m), m)
self.assertRaises(TypeError, eval, 'a', m)
# Verify that dict subclasses work as well
class D(dict):
......
......@@ -459,12 +459,13 @@ builtin_eval(PyObject *self, PyObject *args)
return NULL;
if (locals != Py_None && !PyMapping_Check(locals)) {
PyErr_SetString(PyExc_TypeError, "locals must be a mapping");
return NULL;
return NULL;
}
if (globals != Py_None && !PyDict_Check(globals)) {
PyErr_SetString(PyExc_TypeError, PyMapping_Check(globals) ?
"globals must be a real dict; try eval(expr, {}, mapping)"
: "globals must be a dict");
return NULL;
}
if (globals == Py_None) {
globals = PyEval_GetGlobals();
......
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