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

Dima Dorfman dima at trit.org
Sat Aug 14 12:31:50 CEST 2004


Guido van Rossum <guido at python.org> wrote:
> Michael Chermside wrote:
> > 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
> > parentheses are used. [...]
> 
> +1

Certainly easy to do (in fact, changing the grammar was almost
sufficient). I've uploaded a new patch to SF, with the comment saying,
in part,

  - Support trailing comma in from list (suggested by Michael
    Chermside on python-dev). This form is now acceptable:

      from os import (path,)

    but this is not:

      from os import path,

    I originally wanted to support the latter for consistency, but I
    don't think it's necessary (who would want to do that but not use
    parens?) and it's potentially confusing in a case like this:

      from sys import stdin,
      stdout

    which looks like it was intended to be one statement, but the
    second line is actually separate. The way the grammar is written,
    the case with a trailing comma but no parentheses parses okay, but
    it is intentionally rejected by the compiler.

If we want to support that case for some reason, it's simple enough to
remove the rejection test from the compiler.

Dima.


More information about the Python-Dev mailing list