@@ -58,11 +58,14 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
5858static int
5959future_parse (PyFutureFeatures * ff , mod_ty mod , const char * filename )
6060{
61- int i , found_docstring = 0 , done = 0 , prev_line = 0 ;
61+ int i , done = 0 , prev_line = 0 ;
6262
6363 if (!(mod -> kind == Module_kind || mod -> kind == Interactive_kind ))
6464 return 1 ;
6565
66+ if (asdl_seq_LEN (mod -> v .Module .body ) == 0 )
67+ return 1 ;
68+
6669 /* A subsequent pass will detect future imports that don't
6770 appear at the beginning of the file. There's one case,
6871 however, that is easier to handle here: A series of imports
@@ -71,8 +74,13 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename)
7174 but is preceded by a regular import.
7275 */
7376
77+ i = 0 ;
78+ stmt_ty first = (stmt_ty )asdl_seq_GET (mod -> v .Module .body , i );
79+ if (first -> kind == Expr_kind && first -> v .Expr .value -> kind == Str_kind )
80+ i ++ ;
7481
75- for (i = 0 ; i < asdl_seq_LEN (mod -> v .Module .body ); i ++ ) {
82+
83+ for (; i < asdl_seq_LEN (mod -> v .Module .body ); i ++ ) {
7684 stmt_ty s = (stmt_ty )asdl_seq_GET (mod -> v .Module .body , i );
7785
7886 if (done && s -> lineno > prev_line )
@@ -99,18 +107,13 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename)
99107 return 0 ;
100108 ff -> ff_lineno = s -> lineno ;
101109 }
102- else
110+ else {
103111 done = 1 ;
112+ }
104113 }
105- else if (s -> kind == Expr_kind && !found_docstring ) {
106- expr_ty e = s -> v .Expr .value ;
107- if (e -> kind != Str_kind )
108- done = 1 ;
109- else
110- found_docstring = 1 ;
111- }
112- else
114+ else {
113115 done = 1 ;
116+ }
114117 }
115118 return 1 ;
116119}
0 commit comments