diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-07-20 03:19:18 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-07-20 03:19:18 (GMT) |
commit | 64ef00fa605463e1da84e43ea8a5d722843174b6 (patch) | |
tree | 219e0049b500df1051e208ff1ec6c8a19a1d08d4 | |
parent | 4dc3193973101ce278aee58a9ee36cec2451caf4 (diff) | |
download | cpython-64ef00fa605463e1da84e43ea8a5d722843174b6.zip cpython-64ef00fa605463e1da84e43ea8a5d722843174b6.tar.gz cpython-64ef00fa605463e1da84e43ea8a5d722843174b6.tar.bz2 |
Importlib's documentation said that importlib.abc.PyLoader inherited from
importlib.abc.ResourceLoader, when in fact it did not. Fixed the ABC to inherit
as documented.
This doesn't introduce an backwards-incompatiblity as the code in PyLoader
already required the single method ResourceLoader defined as an abstract
method.
-rw-r--r-- | Lib/importlib/abc.py | 2 | ||||
-rw-r--r-- | Lib/importlib/test/test_abc.py | 75 | ||||
-rw-r--r-- | Misc/NEWS | 4 |
3 files changed, 66 insertions, 15 deletions
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index b2bdb02..7b89d0b 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -76,7 +76,7 @@ InspectLoader.register(machinery.BuiltinImporter) InspectLoader.register(machinery.FrozenImporter) -class PyLoader(_bootstrap.PyLoader, InspectLoader): +class PyLoader(_bootstrap.PyLoader, ResourceLoader, InspectLoader): """Abstract base class to assist in loading source code by requiring only back-end storage methods to be implemented. diff --git a/Lib/importlib/test/test_abc.py b/Lib/importlib/test/test_abc.py index c5a5908..6e09534 100644 --- a/Lib/importlib/test/test_abc.py +++ b/Lib/importlib/test/test_abc.py @@ -1,30 +1,77 @@ from importlib import abc from importlib import machinery +import inspect import unittest -class SubclassTests(unittest.TestCase): +class InheritanceTests: - """Test that the various classes in importlib are subclasses of the - expected ABCS.""" + """Test that the specified class is a subclass/superclass of the expected + classes.""" - def verify(self, ABC, *classes): - """Verify the classes are subclasses of the ABC.""" - for cls in classes: - self.assertTrue(issubclass(cls, ABC)) + subclasses = [] + superclasses = [] - def test_Finder(self): - self.verify(abc.Finder, machinery.BuiltinImporter, - machinery.FrozenImporter, machinery.PathFinder) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + assert self.subclasses or self.superclasses, self.__class__ + self.__test = getattr(abc, self.__class__.__name__) - def test_Loader(self): - self.verify(abc.Loader, machinery.BuiltinImporter, - machinery.FrozenImporter) + def test_subclasses(self): + # Test that the expected subclasses inherit. + for subclass in self.subclasses: + self.assertTrue(issubclass(subclass, self.__test), + "{0} is not a subclass of {1}".format(subclass, self.__test)) + + def test_superclasses(self): + # Test that the class inherits from the expected superclasses. + for superclass in self.superclasses: + self.assertTrue(issubclass(self.__test, superclass), + "{0} is not a superclass of {1}".format(superclass, self.__test)) + + +class Finder(InheritanceTests, unittest.TestCase): + + subclasses = [machinery.BuiltinImporter, machinery.FrozenImporter, + machinery.PathFinder] + + +class Loader(InheritanceTests, unittest.TestCase): + + subclasses = [abc.PyLoader] + + +class ResourceLoader(InheritanceTests, unittest.TestCase): + + superclasses = [abc.Loader] + + +class InspectLoader(InheritanceTests, unittest.TestCase): + + superclasses = [abc.Loader] + subclasses = [abc.PyLoader, machinery.BuiltinImporter, + machinery.FrozenImporter] + + +class PyLoader(InheritanceTests, unittest.TestCase): + + superclasses = [abc.Loader, abc.ResourceLoader, abc.InspectLoader] + + +class PyPycLoader(InheritanceTests, unittest.TestCase): + + superclasses = [abc.PyLoader] def test_main(): from test.support import run_unittest - run_unittest(SubclassTests) + classes = [] + for class_ in globals().values(): + if (inspect.isclass(class_) and + issubclass(class_, unittest.TestCase) and + issubclass(class_, InheritanceTests)): + classes.append(class_) + run_unittest(*classes) if __name__ == '__main__': @@ -43,6 +43,10 @@ C-API Library ------- +- importlib.abc.PyLoader did not inherit from importlib.abc.ResourceLoader like + the documentation said it did even though the code in PyLoader relied on the + abstract method required by ResourceLoader. + - Issue #6431: Make Fraction type return NotImplemented when it doesn't know how to handle a comparison without loss of precision. Also add correct handling of infinities and nans for comparisons with float. |