MCPcopy Index your code
hub / github.com/python/cpython / forget

Function forget

Lib/test/support/import_helper.py:40–56  ·  view source on GitHub ↗

Forget' a module was ever imported. This removes the module from sys.modules and deletes any PEP 3147/488 or legacy .pyc files.

(modname)

Source from the content-addressed store, hash-verified

38
39
40def 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
59def make_legacy_pyc(source, allow_compile=False):

Callers 6

_check_moduleMethod · 0.90
_check_packageMethod · 0.90
test_run_nameMethod · 0.90
test_with_extensionMethod · 0.90
_cleanMethod · 0.90
test_missing_sourceMethod · 0.90

Calls 3

unloadFunction · 0.85
unlinkFunction · 0.85
joinMethod · 0.45

Tested by 5

_check_moduleMethod · 0.72
_check_packageMethod · 0.72
test_run_nameMethod · 0.72
test_with_extensionMethod · 0.72
test_missing_sourceMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…