Forget' a module was ever imported. This removes the module from sys.modules and deletes any PEP 3147/488 or legacy .pyc files.
(modname)
| 37 | |
| 38 | |
| 39 | def forget(modname): |
| 40 | """'Forget' a module was ever imported. |
| 41 | |
| 42 | This removes the module from sys.modules and deletes any PEP 3147/488 or |
| 43 | legacy .pyc files. |
| 44 | """ |
| 45 | unload(modname) |
| 46 | for dirname in sys.path: |
| 47 | source = os.path.join(dirname, modname + '.py') |
| 48 | # It doesn't matter if they exist or not, unlink all possible |
| 49 | # combinations of PEP 3147/488 and legacy pyc files. |
| 50 | unlink(source + 'c') |
| 51 | for opt in ('', 1, 2): |
| 52 | unlink(importlib.util.cache_from_source(source, optimization=opt)) |
| 53 | |
| 54 | |
| 55 | def make_legacy_pyc(source): |