[Python-Dev] problem with assignment shadows builtin warning
Neil Schemenauer
nas@python.ca
Mon, 16 Jun 2003 13:14:12 -0700
Jeremy Hylton wrote:
> I guess someone needs to patch the import code to manipulate the
> parent namespaces in a way that won't generate an exception.
The simplest fix is to operate on the dict directly rather than using
PyObject_SetAttrString on the module. It's a little ugly because the it
looks like that import code isn't limited to operating on modules. I
guess the patch would have to be something like
if (PyModule_Check(mod)) {
PyObject *dict = PyModule_GetDict(mod);
if (!dict) {
Py_XDECREF(m);
m = NULL;
}
else if (PyDict_SetItemString(dict, subname, res) < 0) {
Py_XDECREF(m);
m = NULL;
}
}
else {
PyObject_SetAttrString(mod, subname, res) < 0) {
Py_XDECREF(m);
m = NULL;
}
}
Ugly. Luckily that's the only PyObject_SetAttrString() in the import
code.
Neil