[Python-Dev] Multi-line import implementation (was: 2.4a2, and @decorators)

Guido van Rossum guido at python.org
Mon Aug 9 17:25:21 CEST 2004


> > The 2.4 release schedule PEP now lists this as lacking someone
> > to drive it. I won't/can't spend time on it. So, if one of the people
> > who wants it could step forward, that'd be excellent. Even if it's
> > just to do the multi-line import syntax of
> > 
> >   from foo import ( bar, baz, bar2,
> >                     baz2, bar3, baz3 )
> 
> I took a stab at implementing this (the easy part of PEP 328--parens
> around import lists).

Great!

> Are the exact semantics of what's allowed documented somewhere?

Not unless it's in the PEP -- it usually takes a stab at implementing
something to find what's left unspecified!

> PEP 328 mostly talks about relative and absolute
> imports, and it doesn't specify the exact semantics of where
> parentheses should be allowed. My patch (attached) accepts
> 
>   import (os, sys)
>   from sys import (stdin, stdout, stderr)
>   import (os)
>   from sys import (*)
> 
> but rejects
> 
>   from (sys) import stdin
>   import (os), (sys)
>   import (os,)
> 
> Should any of those be allowed? Anything that I missed?

This suggests (given the recent criticism of how we've been following
the PEP process) that the PEP needs to be updated first.

My own gut feeling is that it's not important to allow parentheses on
"bare" (from-less) imports, since you can easily repeat the 'import'
keyword on a new line; but that it is important on the from...import
form, and then only after the "import" keyword.  So that would accept
your 2nd and 4th example but reject the 1st and 3rd.

I guess one can argue about (*); I don't care about it and suggest
that it be dropped.

> The patch is incomplete in other ways; the docs haven't been updated
> and neither have the parser module and compile package. If it's
> decided that it would be okay to include this separately from
> relative/absolute import support (they're different features,
> really), I'll complete the patch.

Please do, and please use the SF patch manager to upload the patch.

--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list