PEP 328 update

John Roth newsgroups at jhrothjr.com
Tue May 4 07:54:14 EDT 2004


"Carl Banks" <imbosol at aerojockey.invalid> wrote in message
news:yMClc.12854$Gq1.5974 at fe2.columbus.rr.com...
> 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"?)

Why isn't it clear? The way it currently works, if you use
import foo, the name being bound is foo. I see no reason to
change that. If you want something other than the first name in
the string to be bound, then you use the from syntax.

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

What's to guess? You're just complicating things for no good
reason that I can discern.

> 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.

Which is why I am astonished that anyone would consider that
seriously for more than about 10 nanoseconds.

> 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.

There is a concept called "conceptual integrity." Paying close
attention to it is widely regarded as one way of making things
comprehensible by eliminating special cases. This is a special
case that I can see no compelling reason for. The only reasons
given so far don't seem credible.

John Roth
>
>
> -- 
> 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