Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 54743:40c8c35492f1 legacy-trunk
when no module is given in a 'from' relative import, make ImportFrom.module NULL
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 13 Jun 2009 20:23:33 +0000 |
| parents | 1d8f24bf4399 |
| children | 6f3054afa1a0 |
line wrap: on
line diff
--- a/Python/compile.c Sat Jun 13 17:08:53 2009 +0000 +++ b/Python/compile.c Sat Jun 13 20:23:33 2009 +0000 @@ -1976,6 +1976,13 @@ PyObject *names = PyTuple_New(n); PyObject *level; + static PyObject *empty_string; + + if (!empty_string) { + empty_string = PyString_FromString(""); + if (!empty_string) + return 0; + } if (!names) return 0; @@ -1998,23 +2005,24 @@ PyTuple_SET_ITEM(names, i, alias->name); } - if (s->lineno > c->c_future->ff_lineno) { - if (!strcmp(PyString_AS_STRING(s->v.ImportFrom.module), - "__future__")) { - Py_DECREF(level); - Py_DECREF(names); - return compiler_error(c, - "from __future__ imports must occur " + if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module && + !strcmp(PyString_AS_STRING(s->v.ImportFrom.module), "__future__")) { + Py_DECREF(level); + Py_DECREF(names); + return compiler_error(c, "from __future__ imports must occur " "at the beginning of the file"); - - } } ADDOP_O(c, LOAD_CONST, level, consts); Py_DECREF(level); ADDOP_O(c, LOAD_CONST, names, consts); Py_DECREF(names); - ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names); + if (s->v.ImportFrom.module) { + ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names); + } + else { + ADDOP_NAME(c, IMPORT_NAME, empty_string, names); + } for (i = 0; i < n; i++) { alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i); identifier store_name;
