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

Skip to content

Commit e81e9b1

Browse files
committed
Patch #794826: Add __file__ in dynamically loaded modules for multiple
interpreters. Fixes #698282. Will backport to 2.3.
1 parent ef36537 commit e81e9b1

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Python/importdl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp)
5454
_Py_PackageContext = oldcontext;
5555
if (PyErr_Occurred())
5656
return NULL;
57-
if (_PyImport_FixupExtension(name, pathname) == NULL)
58-
return NULL;
5957

6058
m = PyDict_GetItemString(PyImport_GetModuleDict(), name);
6159
if (m == NULL) {
@@ -66,6 +64,9 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp)
6664
/* Remember the filename as the __file__ attribute */
6765
if (PyModule_AddStringConstant(m, "__file__", pathname) < 0)
6866
PyErr_Clear(); /* Not important enough to report */
67+
68+
if (_PyImport_FixupExtension(name, pathname) == NULL)
69+
return NULL;
6970
if (Py_VerboseFlag)
7071
PySys_WriteStderr(
7172
"import %s # dynamically loaded from %s\n",

0 commit comments

Comments
 (0)