Skip to content

Commit 786a4e1

Browse files
bpo-36266: Add module name in ImportError when DLL not found on Windows (GH-15180)
(cherry picked from commit 24fe460) Co-authored-by: shireenrao <[email protected]>
1 parent 7309cca commit 786a4e1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add the module name in the formatted error message when DLL load fail happens during module import in ``_PyImport_FindSharedFuncptrWindows()``. Patch by Srinivas Nyayapati.

Python/dynload_win.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
258258
This should not happen if called correctly. */
259259
if (theLength == 0) {
260260
message = PyUnicode_FromFormat(
261-
"DLL load failed with error code %u",
262-
errorCode);
261+
"DLL load failed with error code %u while importing %s",
262+
errorCode, shortname);
263263
} else {
264264
/* For some reason a \r\n
265265
is appended to the text */
@@ -269,8 +269,8 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
269269
theLength -= 2;
270270
theInfo[theLength] = '\0';
271271
}
272-
message = PyUnicode_FromString(
273-
"DLL load failed: ");
272+
message = PyUnicode_FromFormat(
273+
"DLL load failed while importing %s: ", shortname);
274274

275275
PyUnicode_AppendAndDel(&message,
276276
PyUnicode_FromWideChar(

0 commit comments

Comments
 (0)