Mercurial > cpython-lru_cache-weakref
diff Python/future.c @ 19407:81c7565a56ac legacy-trunk
Fix SF bug [ #450245 ] Error in parsing future stmts
Check return value from future_parse() in for loop for file_input to
accomodate multiple future statements on separate lines.
Add several comments explaining how the code works.
Remove out-dated XXX comment.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Mon, 20 Aug 2001 20:32:33 +0000 |
| parents | 97a3d3d7029f |
| children | ba0236f84318 |
line wrap: on
line diff
--- a/Python/future.c Mon Aug 20 20:29:07 2001 +0000 +++ b/Python/future.c Mon Aug 20 20:32:33 2001 +0000 @@ -8,6 +8,9 @@ #define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined" #define FUTURE_IMPORT_STAR "future statement does not support import *" +/* FUTURE_POSSIBLE() is provided to accomodate doc strings, which is + the only statement that can occur before a future statement. +*/ #define FUTURE_POSSIBLE(FF) ((FF)->ff_last_lineno == -1) static int @@ -57,7 +60,6 @@ "from __future__ imports must occur at the " "beginning of the file"); PyErr_SyntaxLocation(filename, n->n_lineno); - /* XXX set filename and lineno */ } /* Relevant portions of the grammar: @@ -75,7 +77,12 @@ dotted_name: NAME ('.' NAME)* */ -/* future_parse() return values: +/* future_parse() finds future statements at the beginnning of a + module. The function calls itself recursively, rather than + factoring out logic for different kinds of statements into + different routines. + + Return values: -1 indicates an error occurred, e.g. unknown feature name 0 indicates no feature was found 1 indicates a feature was found @@ -97,11 +104,19 @@ return 0; case file_input: + /* Check each statement in the file, starting with the + first, and continuing until the first statement + that isn't a future statement. + */ for (i = 0; i < NCH(n); i++) { node *ch = CHILD(n, i); if (TYPE(ch) == stmt) { r = future_parse(ff, ch, filename); - if (!FUTURE_POSSIBLE(ff)) + /* Need to check both conditions below + to accomodate doc strings, which + causes r < 0. + */ + if (r < 1 && !FUTURE_POSSIBLE(ff)) return r; } }
