[Python-Dev] Multi-line import implementation (was: 2.4a2,
and @decorators)
Michael Chermside
mcherm at mcherm.com
Wed Aug 11 15:57:41 CEST 2004
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?
Others have already mentioned that "from sys import xxx, xxx, xxx"
is the case that badly needs line wrapping. I would, however, like
to suggest that (if it's easy to do) you allow a trailing comma when
parenthesees are used. Of course this looks silly:
from mymodule import (xxx, xxx,
xxx, xxx,)
But in the most extreme case, like this:
from myBigModule import (
xxxxxxxx, xxxxxxxx, xxxxxxxx,
xxxxxxxx, xxxxxxxx, xxxxxxxx,
xxxxxxxx, xxxxxxxx, xxxxxxxx,
xxxxxxxx, xxxxxxxx, xxxxxxxx,
xxxxxxxx, xxxxxxxx, xxxxxxxx,
)
it's awefully nice on cut-and-paste to allow the trailing comma. But
the most important reason for doing so is that Python already allows
(and disregards) an extra trailing comma in similar lists:
>>> [1,2,3,]
[1, 2, 3]
>>> {1:1,2:2,3:3,}
{1: 1, 2: 2, 3: 3}
>>> def func(a,b,c,):
... print a, b, c
...
>>> func(1,2,3)
1 2 3
>>> (1,2,3,)
(1, 2, 3)
-- Michael Chermside
PS: The length-one-tuple is a special case (and a bit of a wart)
in that it MANDATES the use of the trailing comma. But that's
got nothing to do with the basic principle.
More information about the Python-Dev
mailing list