cpython: 0a75ce232f56 (original) (raw)

--- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -102,12 +102,11 @@ Functions .. function:: invalidate_caches()

@@ -129,22 +128,17 @@ are also provided to help in implementin implementations should derive from (or register with) the more specific :class:MetaPathFinder or :class:PathEntryFinder ABCs.

-

.. class:: MetaPathFinder

@@ -156,20 +150,45 @@ are also provided to help in implementin will be the value of :attr:__path__ from the parent package. If a loader cannot be found, None is returned.

+ .. class:: PathEntryFinder

+

+

.. class:: Loader @@ -638,6 +657,11 @@ find and load modules. module. If no finder is ever found then None is both stored in the cache and returned.

+ .. class:: FileFinder(path, *loader_details)

--- a/Lib/importlib/init.py +++ b/Lib/importlib/init.py @@ -38,9 +38,9 @@ from ._bootstrap import import def invalidate_caches():

--- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1186,6 +1186,14 @@ class PathFinder: """Meta path finder for sys.path and package path attributes.""" @classmethod

+

@@ -1235,14 +1243,14 @@ class PathFinder: portions = [] if loader is not None: # We found a loader: return it immediately.

@classmethod def find_module(cls, fullname, path=None):

--- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -25,26 +25,22 @@ def _register(abstract_cls, *classes): class Finder(metaclass=abc.ABCMeta):

-

- class MetaPathFinder(Finder): @@ -52,12 +48,18 @@ class MetaPathFinder(Finder): @abc.abstractmethod def find_module(self, fullname, path):

+ _register(MetaPathFinder, machinery.BuiltinImporter, machinery.FrozenImporter, machinery.PathFinder, machinery.WindowsRegistryFinder) @@ -68,13 +70,25 @@ class PathEntryFinder(Finder): @abc.abstractmethod def find_loader(self, fullname):

+

+ _register(PathEntryFinder, machinery.FileFinder)

--- a/Lib/test/test_importlib/test_abc.py +++ b/Lib/test/test_importlib/test_abc.py @@ -36,11 +36,13 @@ class MetaPathFinder(InheritanceTests, u subclasses = [machinery.BuiltinImporter, machinery.FrozenImporter, machinery.PathFinder, machinery.WindowsRegistryFinder] + class PathEntryFinder(InheritanceTests, unittest.TestCase): superclasses = [abc.Finder] subclasses = [machinery.FileFinder] + class Loader(InheritanceTests, unittest.TestCase): subclasses = [abc.PyLoader]

--- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -148,11 +148,15 @@ class InvalidateCacheTests(unittest.Test self.called = True key = 'gobledeegook'

def test_method_lacking(self): # There should be no issues if the method is not defined.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -80,6 +80,9 @@ Core and Builtins Library ------- +- Issue #15502: Have importlib.invalidate_caches() work on sys.meta_path

--- a/Python/importlib.h +++ b/Python/importlib.h @@ -2942,19 +2942,49 @@ unsigned char _Py_M__importlib[] = { 100,101,114,142,4,0,0,115,6,0,0,0,16,1,12,3, 18,4,117,15,0,0,0,78,97,109,101,115,112,97,99,101, 76,111,97,100,101,114,99,1,0,0,0,0,0,0,0,1,

};