[Python-checkins] bpo-30167: Remove __cached__ from __main__ when removing __file__ (GH-7415)

INADA Naoki webhook-mailer at python.org
Thu Nov 29 06:01:33 EST 2018


https://github.com/python/cpython/commit/82daa60defbd6497efdaa6c1132ecc8563122ed5
commit: 82daa60defbd6497efdaa6c1132ecc8563122ed5
branch: master
author: INADA Naoki <methane at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-11-29T20:01:27+09:00
summary:

bpo-30167: Remove __cached__ from __main__ when removing __file__ (GH-7415)

files:
A Misc/NEWS.d/next/Core and Builtins/2018-06-05-15-49-02.bpo-30167.e956hA.rst
M 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
index 000000000000..41bdec899b75
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-06-05-15-49-02.bpo-30167.e956hA.rst	
@@ -0,0 +1,2 @@
+``PyRun_SimpleFileExFlags`` removes ``__cached__`` from module in addition
+to ``__file__``.
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 2d5dc88c5c76..9b6371d9c0da 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -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;
 }



More information about the Python-checkins mailing list