]> granicus.if.org Git - python/commitdiff
bpo-30167: Remove __cached__ from __main__ when removing __file__ (GH-7415)
authorINADA Naoki <methane@users.noreply.github.com>
Thu, 29 Nov 2018 11:01:27 +0000 (20:01 +0900)
committerGitHub <noreply@github.com>
Thu, 29 Nov 2018 11:01:27 +0000 (20:01 +0900)
Misc/NEWS.d/next/Core and Builtins/2018-06-05-15-49-02.bpo-30167.e956hA.rst [new file with mode: 0644]
Python/pythonrun.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-06-05-15-49-02.bpo-30167.e956hA.rst b/Misc/NEWS.d/next/Core and Builtins/2018-06-05-15-49-02.bpo-30167.e956hA.rst
new file mode 100644 (file)
index 0000000..41bdec8
--- /dev/null
@@ -0,0 +1,2 @@
+``PyRun_SimpleFileExFlags`` removes ``__cached__`` from module in addition
+to ``__file__``.
index 2d5dc88c5c7674be1a75885c0a7dfcffe81f1ee6..9b6371d9c0da64d50650090b9a73c533b608da17 100644 (file)
@@ -434,8 +434,14 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
     Py_DECREF(v);
     ret = 0;
   done:
-    if (set_file_name && PyDict_DelItemString(d, "__file__"))
-        PyErr_Clear();
+    if (set_file_name) {
+        if (PyDict_DelItemString(d, "__file__")) {
+            PyErr_Clear();
+        }
+        if (PyDict_DelItemString(d, "__cached__")) {
+            PyErr_Clear();
+        }
+    }
     Py_XDECREF(m);
     return ret;
 }