[Python-Dev] DeprecationWarning: assignment shadows builtin

Neil Schemenauer nas-python@python.ca
Wed, 16 Jul 2003 12:52:56 -0700


Ralf W. Grosse-Kunstleve wrote:
> >>> import std_vector
> __main__:1: DeprecationWarning: assignment shadows builtin
> >>> dir(std_vector)
> ['__doc__', '__file__', '__name__', 'array_cast', 'boost_array_sum',
> 'cos', 'double', 'float', 'in_place_multiply', 'int', 'long', 'size_t']
> 
> std_vector is a Boost.Python extension module

I suspect the warning is shown due to the way Boost builds the namespace
of the extension module.  Shadowing of builtin names is checked by the
setattr method of the module type.  Boost is probably using
module_setattr to populate the global dictionary.  There's nothing wrong
with doing that except that it triggers a spurious warning.

> Does the DeprecationWarning mean that I cannot provide this intuitive
> interface anymore?

That was not the intention.  Having module globals that shadow builtins
is okay.  The warning is supposed to be triggered if the scope of a name
is changed from builtin to global at runtime.  Eg:

    import string
    string.str = 'ha ha'

That's a strange thing to do and I suspect there is little code out
there that does it.  Unfortunately the code that tries to detect it is
imperfect.

> It seems to me that the names of builtin types are essentially made
> equivalent to reserved keywords.

No, see above.

  Neil