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