[Python-Dev] problem with assignment shadows builtin warning
Jeremy Hylton
jeremy@zope.com
16 Jun 2003 15:33:33 -0400
I ran into a problem with the new deprecation warning today. When you
are doing package imports, Python uses setattr to populate the namespace
of the parent package. That is, if you import A.B.C, Python does the
equiavalent of setattr(A, "B", A.B) and setattr(A.B, "C", A.B.C).
The result is that I get a bunch of deprecation warnings if my modules
shadow builtin names. Module names that are also builtin names are
common in some work projects. (Ouput from our test runner is at the end
of the message.)
Do we want to discourage the use of module names that overlap with
builtin names? If so, we need a better error message, because if you go
to the line mentioned in the warning you won't see an obvious assignment
:-).
My initial reaction was that we should not have a deprecation warning
for this kind of shadowing, but I'm growing less comfortable about the
names. I'd definitely complain about a top-level "import list"; I don't
know why it is any better as a module within a package.
Jeremy
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zope/app/security/_protections.py:85: DeprecationWarning: assignment shadows builtin
from persistence.list import PersistentList
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zope/app/security/_protections.py:93: DeprecationWarning: assignment shadows builtin
from persistence.dict import PersistentDict
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zope/app/event/globalservice.py:22: DeprecationWarning: assignment shadows builtin
from zope.interface.type import TypeRegistry
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zope/app/ftp/__init__.py:22: DeprecationWarning: assignment shadows builtin
from zope.app.interfaces.file import IReadFile, IWriteFile
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zodb/storage/tests/test_demo.py:21: DeprecationWarning: assignment shadows builtin
from zodb.storage.file import FileStorage
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zope/app/event/subs.py:37: DeprecationWarning: assignment shadows builtin
from zope.app.services.type import PersistentTypeRegistry
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zope/app/browser/content/image.py:19: DeprecationWarning: assignment shadows builtin
from zope.app.browser.content.file import FileUpload
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zope/app/content/file.py:26: DeprecationWarning: assignment shadows builtin
from zope.app.interfaces.content.file import IFile, IReadFile,
IFileContent
/home/jeremy/src/Zope3/build/lib.linux-i686-2.3/zope/app/content/image.py:18: DeprecationWarning: assignment shadows builtin
from zope.app.content.file import File