PEP 328 update

Carl Banks imbosol at aerojockey.invalid
Mon May 3 21:57:50 EDT 2004


John Roth wrote:
> 
> 
> 
> "Aahz" <aahz at pythoncraft.com> wrote in message
> news:c76k9g$rf0$1 at panix1.panix.com...
>> In article <109d87iiu30ct7a at news.supernews.com>,
>> John Roth <newsgroups at jhrothjr.com> wrote:
>> >
>> >I also don't particularly see the reason for banning the relative form
>> >from raw import statements.
>>
>> Did you see the rationale toward the end?
> 
> Yes. From my point of view, the . is an operator or a
> decorator. It is not a part of the name; if it was, the
> system would be unable to find the module on disk,
> because that name does not have the dot.
> 
> The rationale makes no sense whatsoever.


Look at it this way:

If you do "import abc.def.ghi", then the module ghi gets imported
(along with packages abc and def); however, only the only symbol that
gets bound is "abc".

If you try to do "import .ghi", well, it's obvious that you're
imporing a sister module, but it's not clear what symbol should be
bound.  (Do you bind "ghi" or "abc"?)

According to the Python Zen: "In the face of ambiguity, refuse the
temptation to guess."  Ergo, don't allow it.

But frankly, even if it were obvious, neither option makes sense.  If
"import .ghi" means to bind the symbol "abc", then the code that uses
it has to know that "ghi" is found in package "abc.def".  That pretty
much defeats the purpose of relative imports.  It also makes the code
incredibly unclear to the reader.

If "import .ghi" means to bind the symbol "ghi", well, there's already
a way to do it, namely "from . import ghi".  And there should only be
one way to do it.


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon



More information about the Python-list mailing list