Skip to content

Commit 0f92c18

Browse files
committed
Use pkgutil.ImpLoader for the import loader
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent f192efa commit 0f92c18

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
if not py3:
5757
import imp
58+
import pkgutil
5859

5960

6061
logger = logging.getLogger(__name__)
@@ -231,24 +232,18 @@ def load_module(self, name):
231232

232233

233234
if not py3:
234-
class ImpImportLoader(object):
235+
# Remember that pkgutil.ImpLoader is an old style class.
236+
class ImpImportLoader(pkgutil.ImpLoader):
235237

236-
def __init__(self, watcher, file, pathname, description):
238+
def __init__(self, watcher, *args):
237239
self.watcher = watcher
238-
self.file = file
239-
self.pathname = pathname
240-
self.description = description
240+
pkgutil.ImpLoader.__init__(self, *args)
241241

242242
def load_module(self, name):
243-
try:
244-
module = imp.load_module(name, self.file, self.pathname,
245-
self.description)
246-
if hasattr(module, '__file__'):
247-
self.watcher.track_module(module.__file__)
248-
return module
249-
finally:
250-
if self.file is not None:
251-
self.file.close()
243+
module = pkgutil.ImpLoader.load_module(self, name)
244+
if hasattr(module, '__file__'):
245+
self.watcher.track_module(module.__file__)
246+
return module
252247

253248

254249
class ImportFinder(object):
@@ -268,7 +263,7 @@ def find_module(self, fullname, path=None):
268263
# sys.meta_path. Use imp to perform the actual importing.
269264
try:
270265
result = imp.find_module(fullname, path)
271-
return ImpImportLoader(self.watcher, *result)
266+
return ImpImportLoader(self.watcher, fullname, *result)
272267
except ImportError:
273268
return None
274269

0 commit comments

Comments
 (0)