Commit d268a44f authored by Stefan Behnel's avatar Stefan Behnel

provide better error message for unknown globals (copied from CPython)

--HG--
rename : tests/broken/ref2global.pyx => tests/run/ref2global.pyx
parent 9233ad7c
......@@ -595,7 +595,12 @@ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
result = __Pyx_PyObject_GetAttrStr($builtins_cname, name);
}
if (!result) {
PyErr_SetObject(PyExc_NameError, name);
PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
"global name '%U' is not defined", name);
#else
"global name '%s' is not defined", PyString_AS_STRING(name));
#endif
}
}
return result;
......
# mode: run
# tag: global, nameerror
try:
from heapq import * # just to confuse the compiler
except ImportError:
pass
def f(a):
"""
>>> f(1)
Traceback (most recent call last):
NameError: global name 'definitely_unknown_name' is not defined
"""
a = f
a = definitely_unknown_name
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