Skip to content

Commit 82daa60

Browse files
authored
bpo-30167: Remove __cached__ from __main__ when removing __file__ (GH-7415)
1 parent 9fbcfc0 commit 82daa60

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``PyRun_SimpleFileExFlags`` removes ``__cached__`` from module in addition
2+
to ``__file__``.

Python/pythonrun.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,14 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
434434
Py_DECREF(v);
435435
ret = 0;
436436
done:
437-
if (set_file_name && PyDict_DelItemString(d, "__file__"))
438-
PyErr_Clear();
437+
if (set_file_name) {
438+
if (PyDict_DelItemString(d, "__file__")) {
439+
PyErr_Clear();
440+
}
441+
if (PyDict_DelItemString(d, "__cached__")) {
442+
PyErr_Clear();
443+
}
444+
}
439445
Py_XDECREF(m);
440446
return ret;
441447
}

0 commit comments

Comments
 (0)