[Python-Dev] Re: Allow all assignment expressions after 'import something as' (original) (raw)

Ka-Ping Yee ping@lfw.org
Tue, 22 Aug 2000 13:02:31 -0700 (PDT)


On Mon, 21 Aug 2000, Guido van Rossum wrote:

> > > > Summary: Allow all assignment expressions after 'import > > > > something as' [...] I kind of doubt it, because it doesn't look useful.

Looks potentially useful to me. If nothing else, it's certainly easier to explain than any other behaviour i could think of, since assignment is already well-understood.

I do want "import foo.bar as spam" back, assigning foo.bar to spam.

No no no no. Or at least let's step back and look at the whole situation first.

"import foo.bar as spam" makes me uncomfortable because:

(a) It's not clear whether spam should get foo or foo.bar, as
    evidenced by the discussion between Gordon and Thomas.

(b) There's a straightforward and unambiguous way to express
    this already: "from foo import bar as spam".

(c) It's not clear whether this should work only for modules
    named bar, or any symbol named bar.

Before packages, the only two forms of the import statement were:

import <module>
from <module> import <symbol>

After packages, the permitted forms are now:

import <module>
import <package>
import <pkgpath>.<module>
import <pkgpath>.<package>
from <module> import <symbol>
from <package> import <module>
from <pkgpath>.<module> import <symbol>
from <pkgpath>.<package> import <module>

where a is a dot-separated list of package names.

With "as" clauses, we could permit:

import <module> as <localmodule>
import <package> as <localpackage>

?? import . as ?? import . as ?? import . as ?? import .. as from import as from import as from . import as from . import as

It's not clear that we should allow "as" on the forms marked with ??, since the other six clearly identify the thing being renamed and they do not.

Also note that all the other forms using "as" assign exactly one thing: the name after the "as". Would the forms marked with ?? assign just the name after the "as" (consistent with the other "as" forms), or also the top-level package name as well (consistent with the current behaviour of "import .")?

That is, would

import foo.bar as spam

define just spam or both foo and spam?

All these questions make me uncertain...

-- ?!ng