[Python-Dev] Re: [Patches] [Patch #101234] Allow all assignment expressions after 'import something as'

Thomas Wouters thomas@xs4all.net
Mon, 21 Aug 2000 14:03:06 +0200


On Sun, Aug 20, 2000 at 11:37:46PM -0500, Guido van Rossum wrote:

> > > Summary: Allow all assignment expressions after 'import something as'
> -1.  Hypergeneralization.

I don't think it's hypergeneralization. In fact, people might expect it[*],
if we claim that the 'import-as' syntax is a shortcut for the current
practice of

   import somemod
   sspam = somemod.somesubmod.spam

(or similar constructs.) However, I realize you're under a lot of pressure
to Pronounce a number of things now that you're back, and we can always
change this later (if you change your mind.) I dare to predict, though, that
we'll see questions about why this isn't generalized, on c.l.py.

(*] I know 'people might expect it' and 'hypergeneralization' aren't
mutually exclusive, but you know what I mean.)

> By the way, notice that
>   import foo.bar
> places 'foo' in the current namespace, after ensuring that 'foo.bar'
> is defined.

Oh, I noticed ;) We had a small thread about that, this weekend. The subject
was something like ''import as'' or so.

> What should
>   import foo.bar as spam
> assign to spam?  I hope foo.bar, not foo.

The original patch assigned foo to spam, not foo.bar. Why ? Well, all the
patch did was use a different name for the STORE operation that follows an
IMPORT_NAME. To elaborate, 'import foo.bar' does this:

    IMPORT_NAME "foo.bar"
    <resulting object, 'foo', is pushed on the stack>
    STORE_NAME "foo"

and all the patch did was replace the "foo" in STORE_NAME with the name
given in the "as" clause.

> I note that the CVS version doesn't support this latter syntax at all;
> it should be fixed, even though the same effect can be has with
>   from foo import bar as spam

Well, "general consensus" (where the general was a three-headed beast, see
the thread I mentioned) prompted me to make it illegal for now. At least
noone is going to rely on it just yet ;) Making it work as you suggest
requires a separate approach, though. I'll think about how to do it best.

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!