summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorlarry <larry@hastings.org>2015-08-12 01:59:15 (GMT)
committerlarry <larry@hastings.org>2015-08-12 01:59:15 (GMT)
commit6707906ea5e0df1132d3cd0c77707ccc19948341 (patch)
treea2fa878b8d00a791ce17dd47296f177fc45cf825 /Python/ceval.c
parentcae101f5ecd8fee38a37ce8fa46c141cd8a522ef (diff)
parent3008bc0f4abb3f71433b1fcd97cc801da0a866cc (diff)
downloadcpython-6707906ea5e0df1132d3cd0c77707ccc19948341.zip
cpython-6707906ea5e0df1132d3cd0c77707ccc19948341.tar.gz
cpython-6707906ea5e0df1132d3cd0c77707ccc19948341.tar.bz2
Merged in brettcannon/cpython350/3.5 (pull request #2)
Issue #24492: make sure that ``from ... import ...` raises an ImportError if __name__ is not defined on a package.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index ac52ad9..8d2cdc2 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5085,19 +5085,24 @@ import_from(PyObject *v, PyObject *name)
sys.modules. */
PyErr_Clear();
pkgname = _PyObject_GetAttrId(v, &PyId___name__);
- if (pkgname == NULL)
- return NULL;
+ if (pkgname == NULL) {
+ goto error;
+ }
fullmodname = PyUnicode_FromFormat("%U.%U", pkgname, name);
Py_DECREF(pkgname);
- if (fullmodname == NULL)
+ if (fullmodname == NULL) {
return NULL;
+ }
x = PyDict_GetItem(PyImport_GetModuleDict(), fullmodname);
- if (x == NULL)
- PyErr_Format(PyExc_ImportError, "cannot import name %R", name);
- else
- Py_INCREF(x);
Py_DECREF(fullmodname);
+ if (x == NULL) {
+ goto error;
+ }
+ Py_INCREF(x);
return x;
+ error:
+ PyErr_Format(PyExc_ImportError, "cannot import name %R", name);
+ return NULL;
}
static int