Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e3155e

Browse files
committed
Merged revisions 74107 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 10e35b3 commit 2e3155e

3 files changed

Lines changed: 66 additions & 15 deletions

File tree

Lib/importlib/abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def get_source(self, fullname:str) -> str:
7676
InspectLoader.register(machinery.FrozenImporter)
7777

7878

79-
class PyLoader(_bootstrap.PyLoader, InspectLoader):
79+
class PyLoader(_bootstrap.PyLoader, ResourceLoader, InspectLoader):
8080

8181
"""Abstract base class to assist in loading source code by requiring only
8282
back-end storage methods to be implemented.

Lib/importlib/test/test_abc.py

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,77 @@
11
from importlib import abc
22
from importlib import machinery
3+
import inspect
34
import unittest
45

56

6-
class SubclassTests(unittest.TestCase):
7+
class InheritanceTests:
78

8-
"""Test that the various classes in importlib are subclasses of the
9-
expected ABCS."""
9+
"""Test that the specified class is a subclass/superclass of the expected
10+
classes."""
1011

11-
def verify(self, ABC, *classes):
12-
"""Verify the classes are subclasses of the ABC."""
13-
for cls in classes:
14-
self.assert_(issubclass(cls, ABC))
12+
subclasses = []
13+
superclasses = []
1514

16-
def test_Finder(self):
17-
self.verify(abc.Finder, machinery.BuiltinImporter,
18-
machinery.FrozenImporter, machinery.PathFinder)
15+
def __init__(self, *args, **kwargs):
16+
super().__init__(*args, **kwargs)
17+
assert self.subclasses or self.superclasses, self.__class__
18+
self.__test = getattr(abc, self.__class__.__name__)
1919

20-
def test_Loader(self):
21-
self.verify(abc.Loader, machinery.BuiltinImporter,
22-
machinery.FrozenImporter)
20+
def test_subclasses(self):
21+
# Test that the expected subclasses inherit.
22+
for subclass in self.subclasses:
23+
self.assertTrue(issubclass(subclass, self.__test),
24+
"{0} is not a subclass of {1}".format(subclass, self.__test))
25+
26+
def test_superclasses(self):
27+
# Test that the class inherits from the expected superclasses.
28+
for superclass in self.superclasses:
29+
self.assertTrue(issubclass(self.__test, superclass),
30+
"{0} is not a superclass of {1}".format(superclass, self.__test))
31+
32+
33+
class Finder(InheritanceTests, unittest.TestCase):
34+
35+
subclasses = [machinery.BuiltinImporter, machinery.FrozenImporter,
36+
machinery.PathFinder]
37+
38+
39+
class Loader(InheritanceTests, unittest.TestCase):
40+
41+
subclasses = [abc.PyLoader]
42+
43+
44+
class ResourceLoader(InheritanceTests, unittest.TestCase):
45+
46+
superclasses = [abc.Loader]
47+
48+
49+
class InspectLoader(InheritanceTests, unittest.TestCase):
50+
51+
superclasses = [abc.Loader]
52+
subclasses = [abc.PyLoader, machinery.BuiltinImporter,
53+
machinery.FrozenImporter]
54+
55+
56+
class PyLoader(InheritanceTests, unittest.TestCase):
57+
58+
superclasses = [abc.Loader, abc.ResourceLoader, abc.InspectLoader]
59+
60+
61+
class PyPycLoader(InheritanceTests, unittest.TestCase):
62+
63+
superclasses = [abc.PyLoader]
2364

2465

2566
def test_main():
2667
from test.support import run_unittest
27-
run_unittest(SubclassTests)
68+
classes = []
69+
for class_ in globals().values():
70+
if (inspect.isclass(class_) and
71+
issubclass(class_, unittest.TestCase) and
72+
issubclass(class_, InheritanceTests)):
73+
classes.append(class_)
74+
run_unittest(*classes)
2875

2976

3077
if __name__ == '__main__':

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ C-API
3737
Library
3838
-------
3939

40+
- importlib.abc.PyLoader did not inherit from importlib.abc.ResourceLoader like
41+
the documentation said it did even though the code in PyLoader relied on the
42+
abstract method required by ResourceLoader.
43+
4044
- Issue #6431: Make Fraction type return NotImplemented when it doesn't
4145
know how to handle a comparison without loss of precision. Also add
4246
correct handling of infinities and nans for comparisons with float.

0 commit comments

Comments
 (0)