Issue #13959: Have
importlib.abc.FileLoader.load_module()/get_filename() and
importlib.machinery.ExtensionFileLoader.load_module() have their
single argument be optional as the loader's constructor has all the
ncessary information.
This allows for the deprecation of
imp.load_source()/load_compile()/load_package().
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 5b285fc..3f419b7 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -1,11 +1,12 @@
import imp
+import importlib
import os
import os.path
import shutil
import sys
-import unittest
from test import support
-import importlib
+import unittest
+import warnings
class LockTests(unittest.TestCase):
@@ -154,18 +155,24 @@
mod = imp.load_module(temp_mod_name, file, filename, info)
self.assertEqual(mod.a, 1)
- mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore')
+ mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
self.assertEqual(mod.a, 1)
- mod = imp.load_compiled(
- temp_mod_name, imp.cache_from_source(temp_mod_name + '.py'))
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore')
+ mod = imp.load_compiled(
+ temp_mod_name, imp.cache_from_source(temp_mod_name + '.py'))
self.assertEqual(mod.a, 1)
if not os.path.exists(test_package_name):
os.mkdir(test_package_name)
with open(init_file_name, 'w') as file:
file.write('b = 2\n')
- package = imp.load_package(test_package_name, test_package_name)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore')
+ package = imp.load_package(test_package_name, test_package_name)
self.assertEqual(package.b, 2)
finally:
del sys.path[0]
diff --git a/Lib/test/test_tools.py b/Lib/test/test_tools.py
index bc2672d..cbe6d80 100644
--- a/Lib/test/test_tools.py
+++ b/Lib/test/test_tools.py
@@ -6,7 +6,7 @@
import os
import sys
-import imp
+import importlib.machinery
import unittest
from unittest import mock
import sysconfig
@@ -80,7 +80,8 @@
@classmethod
def setUpClass(self):
path = os.path.join(scriptsdir, 'pdeps.py')
- self.pdeps = imp.load_source('pdeps', path)
+ loader = importlib.machinery.SourceFileLoader('pdeps', path)
+ self.pdeps = loader.load_module()
@classmethod
def tearDownClass(self):
@@ -104,7 +105,8 @@
def setUp(self):
path = os.path.join(scriptsdir, 'gprof2html.py')
- self.gprof = imp.load_source('gprof2html', path)
+ loader = importlib.machinery.SourceFileLoader('gprof2html', path)
+ self.gprof = loader.load_module()
oldargv = sys.argv
def fixup():
sys.argv = oldargv