[Python-Dev] Re: PEP 328 - Relative Imports

Nicolas Fleury nidoizo at yahoo.com
Sat Sep 11 00:51:26 CEST 2004


Barry Warsaw wrote:
> from __global__ import logging
> 
> That would always import the global logging package.  __global__ is the
> optional "fake" global package and would only be used when you want to
> explicitly skip any local imports.
> 
> IIRC though, Guido never liked this proposal much.  I repost it here on
> the off chance that he's way too busy to read every message in this
> thread <wink>.

I agree with Guido.  FWIW, I think imports should be absolute by default 
and that the statu quo is a mistake.  The __global__ solution makes 
absolute imports too verbose, when they are usually in majority.  I also 
don't see any advantage (but clear disadvantages) to mix relative and 
absolute imports with the same syntax, so PEP328 is the way to go. 
Third party packages have 3 releases to adapt, so I don't see the problem.

You have to understand that with the __global__ solution, I would make 
all my imports use that syntax, and that's really verbose.  Where I 
work, we are many working in a root package and right now it's a mess 
because any new module can hide global modules to modules in same 
directory, so modules names must be chosen accordingly (we even run a 
test at night to make sure no import is relative).  And yes, I would 
want to be able to name modules in a package with names like "math", 
"os", "pickle", "test", "unittest", etc. and not wait Python 3 for that 
capability.  I also expect more standard modules to be in packages in 
future.

Regards,
Nicolas



More information about the Python-Dev mailing list