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

Aahz aahz at pythoncraft.com
Mon Aug 9 19:34:15 CEST 2004


On Mon, Aug 09, 2004, Guido van Rossum wrote:
>Dima Dorfman:
>>
>> 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!

Yup!

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

Enh; as you say, implementation is often needed to clarify, and I don't
think anyone would dispute that this is a small portion of the PEP.

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

I'd suggest that only ``from foo import (...)`` be permitted (where "..."
does not include ``*``).  But I don't care much, and I'll update the PEP
as soon as it's clear which precise versions are allowed.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"To me vi is Zen.  To use vi is to practice zen.  Every command is a
koan.  Profound to the user, unintelligible to the uninitiated.  You
discover truth everytime you use it."  --reddy at lion.austin.ibm.com


More information about the Python-Dev mailing list