@@ -1976,6 +1976,13 @@ compiler_from_import(struct compiler *c, stmt_ty s)
19761976
19771977 PyObject * names = PyTuple_New (n );
19781978 PyObject * level ;
1979+ static PyObject * empty_string ;
1980+
1981+ if (!empty_string ) {
1982+ empty_string = PyString_FromString ("" );
1983+ if (!empty_string )
1984+ return 0 ;
1985+ }
19791986
19801987 if (!names )
19811988 return 0 ;
@@ -1998,23 +2005,24 @@ compiler_from_import(struct compiler *c, stmt_ty s)
19982005 PyTuple_SET_ITEM (names , i , alias -> name );
19992006 }
20002007
2001- if (s -> lineno > c -> c_future -> ff_lineno ) {
2002- if (!strcmp (PyString_AS_STRING (s -> v .ImportFrom .module ),
2003- "__future__" )) {
2004- Py_DECREF (level );
2005- Py_DECREF (names );
2006- return compiler_error (c ,
2007- "from __future__ imports must occur "
2008+ if (s -> lineno > c -> c_future -> ff_lineno && s -> v .ImportFrom .module &&
2009+ !strcmp (PyString_AS_STRING (s -> v .ImportFrom .module ), "__future__" )) {
2010+ Py_DECREF (level );
2011+ Py_DECREF (names );
2012+ return compiler_error (c , "from __future__ imports must occur "
20082013 "at the beginning of the file" );
2009-
2010- }
20112014 }
20122015
20132016 ADDOP_O (c , LOAD_CONST , level , consts );
20142017 Py_DECREF (level );
20152018 ADDOP_O (c , LOAD_CONST , names , consts );
20162019 Py_DECREF (names );
2017- ADDOP_NAME (c , IMPORT_NAME , s -> v .ImportFrom .module , names );
2020+ if (s -> v .ImportFrom .module ) {
2021+ ADDOP_NAME (c , IMPORT_NAME , s -> v .ImportFrom .module , names );
2022+ }
2023+ else {
2024+ ADDOP_NAME (c , IMPORT_NAME , empty_string , names );
2025+ }
20182026 for (i = 0 ; i < n ; i ++ ) {
20192027 alias_ty alias = (alias_ty )asdl_seq_GET (s -> v .ImportFrom .names , i );
20202028 identifier store_name ;
0 commit comments