]> granicus.if.org Git - python/commitdiff
Fix SF bug [ #450245 ] Error in parsing future stmts
authorJeremy Hylton <jeremy@alum.mit.edu>
Mon, 20 Aug 2001 20:32:33 +0000 (20:32 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Mon, 20 Aug 2001 20:32:33 +0000 (20:32 +0000)
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.

Python/future.c

index 6b1c0c55b892cba9ddd751ab260786f045caccdd..563bbdff154d65ddd6608c7be1ee17ec804a3c20 100644 (file)
@@ -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 @@ future_error(node *n, char *filename)
                        "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_as_name: dotted_name [NAME NAME]
 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 @@ future_parse(PyFutureFeatures *ff, node *n, char *filename)
                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;
                        }
                }