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

Skip to content

Commit 4135e78

Browse files
committed
Use IOError and ImportError when import fails.
1 parent 201be05 commit 4135e78

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Python/import.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,14 @@ get_module(m, name, m_ret)
149149

150150
fp = open_module(name, ".py", namebuf);
151151
if (fp == NULL) {
152-
if (m == NULL)
153-
err_setstr(NameError, name);
154-
else
155-
err_setstr(IOError, "no module source file");
152+
if (m == NULL) {
153+
sprintf(namebuf, "no module named %.200s", name);
154+
err_setstr(ImportError, namebuf);
155+
}
156+
else {
157+
sprintf(namebuf, "no source for module %.200s", name);
158+
err_setstr(ImportError, namebuf);
159+
}
156160
return NULL;
157161
}
158162
/* Get mtime -- always useful */

0 commit comments

Comments
 (0)