[Python-Dev] problem with assignment shadows builtin warning

Guido van Rossum guido@python.org
Mon, 16 Jun 2003 16:17:01 -0400


> 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.

But it sounds like a good idea to check this in.  Please add a comment
like

/* Don't want to use PyObject_SetAttrString() because of warnings about
   overriding builtins when the submodule name happens to shadow a
   built-in */

--Guido van Rossum (home page: http://www.python.org/~guido/)