[Python-Dev] Re: Christmas Wishlist

Guido van Rossum guido at python.org
Mon Dec 15 13:36:44 EST 2003


> > Well, but since you want all imports to be global, it'd be insane to
> > introduce *new* syntax for global imports, wouldn't it?
> 
> If we banned relative (a.k.a. local) imports, yes definitely.
> 
> from __future__ global_imports

I think this ought to be a *global* flag rather than a per-module
flag.  E.g. after setting

    sys.allow_relative_import = False

all imports anywhere would be interpreted as absolute imports.

This would mean you couldn't have some code that still uses relative
imports, but the problem with the __future__ statement is that it
seems so pointless: packages that only use absolute imports don't need
it, and packages that use relative imports break if it is used.

About the only time where the __future__ statement would make a
difference is when a package defines a local module whose name is the
same as that of a global module, *and* the package also wants to
import the global module.  I would personally solve that by renaming
the local module though...

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



More information about the Python-Dev mailing list