Movatterモバイル変換
[0]ホーム
[Python-Dev] problem with assignment shadows builtin warning
Neil Schemenauernas@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 usingPyObject_SetAttrString on the module. It's a little ugly because the itlooks like that import code isn't limited to operating on modules. Iguess 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 importcode. Neil
[8]ページ先頭