Skip to content

Commit 335e14d

Browse files
Issue python#19713: Move away from using find_module/load_module.
1 parent d749c7a commit 335e14d

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

Lib/test/test_tools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import os
88
import sys
9+
import importlib._bootstrap
910
import importlib.machinery
1011
import unittest
1112
from unittest import mock
@@ -405,8 +406,8 @@ class PdepsTests(unittest.TestCase):
405406
@classmethod
406407
def setUpClass(self):
407408
path = os.path.join(scriptsdir, 'pdeps.py')
408-
loader = importlib.machinery.SourceFileLoader('pdeps', path)
409-
self.pdeps = loader.load_module()
409+
spec = importlib.util.spec_from_file_location('pdeps', path)
410+
self.pdeps = importlib._bootstrap._SpecMethods(spec).load()
410411

411412
@classmethod
412413
def tearDownClass(self):
@@ -430,8 +431,8 @@ class Gprof2htmlTests(unittest.TestCase):
430431

431432
def setUp(self):
432433
path = os.path.join(scriptsdir, 'gprof2html.py')
433-
loader = importlib.machinery.SourceFileLoader('gprof2html', path)
434-
self.gprof = loader.load_module()
434+
spec = importlib.util.spec_from_file_location('gprof2html', path)
435+
self.gprof = importlib._bootstrap._SpecMethods(spec).load()
435436
oldargv = sys.argv
436437
def fixup():
437438
sys.argv = oldargv

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ Library
255255
- Issue #6477: Added support for pickling the types of built-in singletons
256256
(i.e., Ellipsis, NotImplemented, None).
257257

258+
- Issue #19713: Move away from using find_module/load_module.
259+
258260
- Issue #19851: Fixed a regression in reloading sub-modules.
259261

260262
- ssl.create_default_context() sets OP_NO_COMPRESSION to prevent CRIME.

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import sys, os, importlib.machinery, re, optparse
55
from glob import glob
6+
import importlib._bootstrap
7+
import importlib.util
68
import sysconfig
79

810
from distutils import log
@@ -327,8 +329,10 @@ def build_extension(self, ext):
327329
return
328330

329331
loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename)
332+
spec = importlib.util.spec_from_file_location(ext.name, ext_filename,
333+
loader=loader)
330334
try:
331-
loader.load_module()
335+
importlib._bootstrap._SpecMethods(spec).load()
332336
except ImportError as why:
333337
self.failed.append(ext.name)
334338
self.announce('*** WARNING: renaming "%s" since importing it'

0 commit comments

Comments
 (0)