mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-98040: Remove find_loader, find_module and other deprecated APIs (#98059)
* Remove deprecated classes from pkgutil * Remove some other PEP 302 obsolescence * Use find_spec instead of load_module * Remove more tests of PEP 302 obsolete APIs * Remove another bunch of tests using obsolete load_modules() * Remove deleted names from __all__ * Remove obsolete footnote * imp is removed * Remove `imp` from generated stdlib names * What's new and blurb * Update zipimport documentation for the removed methods * Fix some Windows tests * Remove any test (or part of a test) that references `find_module()`. * Use assertIsNone() / assertIsNotNone() consistently. * Update Doc/reference/import.rst * We don't need pkgutil._get_spec() any more either * test.test_importlib.fixtures.NullFinder * ...BadLoaderFinder.find_module * ...test_api.InvalidatingNullFinder.find_module * ...test.test_zipimport test of z.find_module * Suppress cross-references to find_loader and find_module * Suppress cross-references to Finder * Suppress cross-references to pkgutil.ImpImporter and pkgutil.ImpLoader --------- Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
parent
bcea36f8db
commit
326997829d
39 changed files with 137 additions and 1047 deletions
|
@ -147,20 +147,13 @@ class ABCTestHarness:
|
|||
|
||||
class MetaPathFinder:
|
||||
|
||||
def find_module(self, fullname, path):
|
||||
return super().find_module(fullname, path)
|
||||
pass
|
||||
|
||||
|
||||
class MetaPathFinderDefaultsTests(ABCTestHarness):
|
||||
|
||||
SPLIT = make_abc_subclasses(MetaPathFinder)
|
||||
|
||||
def test_find_module(self):
|
||||
# Default should return None.
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
found = self.ins.find_module('something', None)
|
||||
self.assertIsNone(found)
|
||||
|
||||
def test_invalidate_caches(self):
|
||||
# Calling the method is a no-op.
|
||||
self.ins.invalidate_caches()
|
||||
|
@ -173,22 +166,13 @@ class MetaPathFinderDefaultsTests(ABCTestHarness):
|
|||
|
||||
class PathEntryFinder:
|
||||
|
||||
def find_loader(self, fullname):
|
||||
return super().find_loader(fullname)
|
||||
pass
|
||||
|
||||
|
||||
class PathEntryFinderDefaultsTests(ABCTestHarness):
|
||||
|
||||
SPLIT = make_abc_subclasses(PathEntryFinder)
|
||||
|
||||
def test_find_loader(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
found = self.ins.find_loader('something')
|
||||
self.assertEqual(found, (None, []))
|
||||
|
||||
def find_module(self):
|
||||
self.assertEqual(None, self.ins.find_module('something'))
|
||||
|
||||
def test_invalidate_caches(self):
|
||||
# Should be a no-op.
|
||||
self.ins.invalidate_caches()
|
||||
|
@ -201,8 +185,7 @@ class PathEntryFinderDefaultsTests(ABCTestHarness):
|
|||
|
||||
class Loader:
|
||||
|
||||
def load_module(self, fullname):
|
||||
return super().load_module(fullname)
|
||||
pass
|
||||
|
||||
|
||||
class LoaderDefaultsTests(ABCTestHarness):
|
||||
|
@ -333,14 +316,6 @@ class MetaPathFinderFindModuleTests:
|
|||
|
||||
return MetaPathSpecFinder()
|
||||
|
||||
def test_find_module(self):
|
||||
finder = self.finder(None)
|
||||
path = ['a', 'b', 'c']
|
||||
name = 'blah'
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
found = finder.find_module(name, path)
|
||||
self.assertIsNone(found)
|
||||
|
||||
def test_find_spec_with_explicit_target(self):
|
||||
loader = object()
|
||||
spec = self.util.spec_from_loader('blah', loader)
|
||||
|
@ -370,53 +345,6 @@ class MetaPathFinderFindModuleTests:
|
|||
) = test_util.test_both(MetaPathFinderFindModuleTests, abc=abc, util=util)
|
||||
|
||||
|
||||
##### PathEntryFinder concrete methods #########################################
|
||||
class PathEntryFinderFindLoaderTests:
|
||||
|
||||
@classmethod
|
||||
def finder(cls, spec):
|
||||
class PathEntrySpecFinder(cls.abc.PathEntryFinder):
|
||||
|
||||
def find_spec(self, fullname, target=None):
|
||||
self.called_for = fullname
|
||||
return spec
|
||||
|
||||
return PathEntrySpecFinder()
|
||||
|
||||
def test_no_spec(self):
|
||||
finder = self.finder(None)
|
||||
name = 'blah'
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
found = finder.find_loader(name)
|
||||
self.assertIsNone(found[0])
|
||||
self.assertEqual([], found[1])
|
||||
self.assertEqual(name, finder.called_for)
|
||||
|
||||
def test_spec_with_loader(self):
|
||||
loader = object()
|
||||
spec = self.util.spec_from_loader('blah', loader)
|
||||
finder = self.finder(spec)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
found = finder.find_loader('blah')
|
||||
self.assertIs(found[0], spec.loader)
|
||||
|
||||
def test_spec_with_portions(self):
|
||||
spec = self.machinery.ModuleSpec('blah', None)
|
||||
paths = ['a', 'b', 'c']
|
||||
spec.submodule_search_locations = paths
|
||||
finder = self.finder(spec)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
found = finder.find_loader('blah')
|
||||
self.assertIsNone(found[0])
|
||||
self.assertEqual(paths, found[1])
|
||||
|
||||
|
||||
(Frozen_PEFFindLoaderTests,
|
||||
Source_PEFFindLoaderTests
|
||||
) = test_util.test_both(PathEntryFinderFindLoaderTests, abc=abc, util=util,
|
||||
machinery=machinery)
|
||||
|
||||
|
||||
##### Loader concrete methods ##################################################
|
||||
class LoaderLoadModuleTests:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue