[Python-Dev] one more restriction for from __future__ import ...

Guido van Rossum guido@digicool.com
Tue, 27 Feb 2001 19:29:44 -0500


>   >> It would be a bear to implement error handling for cases like
>   >> this:
>   >>
>   >> from __future__ import a; import b; from __future__ import c
> 
>   GvR> Really?!?  Why?  Isn't it straightforward to check that
>   GvR> everything you encounter in a left-to-right leaf scan of the
>   GvR> parse tree is either a future statement or a docstring until
>   GvR> you encounter a non-future?
> 
> It's not hard to find legal future statements.  It's hard to find
> illegal ones.  The pass to find future statements exits as soon as it
> finds something that isn't a doc string or a future.  The symbol table
> pass detects illegal future statements by comparing the current line
> number against the line number of the last legal futre statement.

Aha.  That's what I missed -- comparison by line number.  One thing
you could do would simply be check the entire current
simple_statement, which would catch the above example; the
possibilities are limited at that level (no blocks can start on the
same line after an import).

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