Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c0afe5

Browse files
committed
Fix a curious bug: statements like "import sys.time" would succeed,
because the path through the code would notice that sys.__path__ did not exist and it would fall back to the default path (builtins + sys.path) instead of failing). No longer.
1 parent edde150 commit 9c0afe5

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

Python/import.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,9 +1664,16 @@ import_submodule(mod, subname, fullname)
16641664
struct filedescr *fdp;
16651665
FILE *fp = NULL;
16661666

1667-
path = PyObject_GetAttrString(mod, "__path__");
1668-
if (path == NULL)
1669-
PyErr_Clear();
1667+
if (mod == Py_None)
1668+
path = NULL;
1669+
else {
1670+
path = PyObject_GetAttrString(mod, "__path__");
1671+
if (path == NULL) {
1672+
PyErr_Clear();
1673+
Py_INCREF(Py_None);
1674+
return Py_None;
1675+
}
1676+
}
16701677

16711678
buf[0] = '\0';
16721679
fdp = find_module(subname, path,

0 commit comments

Comments
 (0)