]> granicus.if.org Git - python/commitdiff
__file__ used to be always set to the .pyc (or .pyo) file, even if
authorGuido van Rossum <guido@python.org>
Tue, 25 Aug 1998 18:44:34 +0000 (18:44 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 25 Aug 1998 18:44:34 +0000 (18:44 +0000)
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.

Python/import.c

index 33d266a36c502e09aeb4526efd6e9d464d749bac..7099d1b92b4a195d111c304342a3355c413342fb 100644 (file)
@@ -706,6 +706,7 @@ load_source_module(name, pathname, fp)
                if (Py_VerboseFlag)
                        fprintf(stderr, "import %s # precompiled from %s\n",
                                name, cpathname);
+               pathname = cpathname;
        }
        else {
                co = parse_source_module(pathname, fp);
@@ -716,7 +717,7 @@ load_source_module(name, pathname, fp)
                                name, pathname);
                write_compiled_module(co, cpathname, mtime);
        }
-       m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, cpathname);
+       m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);
        Py_DECREF(co);
 
        return m;