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

Skip to content

Commit afd3dae

Browse files
committed
__file__ used to be always set to the .pyc (or .pyo) file, even if
that file in fact did not exist or at least was not used. Change this so that __file__ is *only* set to the .pyc/.pyo file when it actually read the code object from it; otherwise __file__ is set to the .py file.
1 parent 90f827c commit afd3dae

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

Python/import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ load_source_module(name, pathname, fp)
706706
if (Py_VerboseFlag)
707707
fprintf(stderr, "import %s # precompiled from %s\n",
708708
name, cpathname);
709+
pathname = cpathname;
709710
}
710711
else {
711712
co = parse_source_module(pathname, fp);
@@ -716,7 +717,7 @@ load_source_module(name, pathname, fp)
716717
name, pathname);
717718
write_compiled_module(co, cpathname, mtime);
718719
}
719-
m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, cpathname);
720+
m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);
720721
Py_DECREF(co);
721722

722723
return m;

0 commit comments

Comments
 (0)