mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Fix __import__("") to raise ValueError rather than return None.
This commit is contained in:
parent
06853fc150
commit
8ddab27182
2 changed files with 11 additions and 1 deletions
|
@ -1934,6 +1934,14 @@ import_module_level(char *name, PyObject *globals, PyObject *locals,
|
|||
}
|
||||
tail = next;
|
||||
}
|
||||
if (tail == Py_None) {
|
||||
/* If tail is Py_None, both get_parent and load_next found
|
||||
an empty module name: someone called __import__("") or
|
||||
doctored faulty bytecode */
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Empty module name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fromlist != NULL) {
|
||||
if (fromlist == Py_None || !PyObject_IsTrue(fromlist))
|
||||
|
@ -2094,7 +2102,8 @@ load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
|
|||
PyObject *result;
|
||||
|
||||
if (strlen(name) == 0) {
|
||||
/* empty module name only happens in 'from . import' */
|
||||
/* completely empty module name should only happen in
|
||||
'from . import' (or '__import__("")')*/
|
||||
Py_INCREF(mod);
|
||||
*p_name = NULL;
|
||||
return mod;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue