Kaydet (Commit) 2e3155e2 authored tarafından Brett Cannon's avatar Brett Cannon

Merged revisions 74107 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r74107 | brett.cannon | 2009-07-19 20:19:18 -0700 (Sun, 19 Jul 2009) | 8 lines

  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 does in introduce an backwards-incompatiblity as the code in PyLoader
  already required the single method ResourceLoader defined as an abstract
  method.
........
üst 10e35b30
...@@ -76,7 +76,7 @@ InspectLoader.register(machinery.BuiltinImporter) ...@@ -76,7 +76,7 @@ InspectLoader.register(machinery.BuiltinImporter)
InspectLoader.register(machinery.FrozenImporter) 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 """Abstract base class to assist in loading source code by requiring only
back-end storage methods to be implemented. back-end storage methods to be implemented.
......
from importlib import abc from importlib import abc
from importlib import machinery from importlib import machinery
import inspect
import unittest import unittest
class SubclassTests(unittest.TestCase): class InheritanceTests:
"""Test that the various classes in importlib are subclasses of the """Test that the specified class is a subclass/superclass of the expected
expected ABCS.""" classes."""
def verify(self, ABC, *classes): subclasses = []
"""Verify the classes are subclasses of the ABC.""" superclasses = []
for cls in classes:
self.assert_(issubclass(cls, ABC))
def test_Finder(self): def __init__(self, *args, **kwargs):
self.verify(abc.Finder, machinery.BuiltinImporter, super().__init__(*args, **kwargs)
machinery.FrozenImporter, machinery.PathFinder) assert self.subclasses or self.superclasses, self.__class__
self.__test = getattr(abc, self.__class__.__name__)
def test_Loader(self): def test_subclasses(self):
self.verify(abc.Loader, machinery.BuiltinImporter, # Test that the expected subclasses inherit.
machinery.FrozenImporter) 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(): def test_main():
from test.support import run_unittest 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__': if __name__ == '__main__':
......
...@@ -37,6 +37,10 @@ C-API ...@@ -37,6 +37,10 @@ C-API
Library 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 - Issue #6431: Make Fraction type return NotImplemented when it doesn't
know how to handle a comparison without loss of precision. Also add know how to handle a comparison without loss of precision. Also add
correct handling of infinities and nans for comparisons with float. correct handling of infinities and nans for comparisons with float.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment