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

This commit is contained in:
INADA Naoki 2018-11-29 20:01:27 +09:00 committed by GitHub
parent 9fbcfc08e5
commit 82daa60def
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1,2 @@
``PyRun_SimpleFileExFlags`` removes ``__cached__`` from module in addition
to ``__file__``.

View 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;
}