--- a/eric6/Utilities/ModuleParser.py Fri Feb 07 18:49:32 2020 +0100 +++ b/eric6/Utilities/ModuleParser.py Sat Feb 08 16:47:20 2020 +0100 @@ -19,7 +19,7 @@ import sys import os -import imp +import importlib import re import Utilities @@ -31,15 +31,17 @@ TABWIDTH = 4 +SEARCH_ERROR = 0 +PY_SOURCE = 1 PTL_SOURCE = 128 RB_SOURCE = 129 -SUPPORTED_TYPES = [imp.PY_SOURCE, PTL_SOURCE, RB_SOURCE] +SUPPORTED_TYPES = [PY_SOURCE, PTL_SOURCE, RB_SOURCE] TYPE_MAPPING = { - "Python": imp.PY_SOURCE, - "Python2": imp.PY_SOURCE, - "Python3": imp.PY_SOURCE, - "MicroPython": imp.PY_SOURCE, + "Python": PY_SOURCE, + "Python2": PY_SOURCE, + "Python3": PY_SOURCE, + "MicroPython": PY_SOURCE, "Ruby": RB_SOURCE, } @@ -423,7 +425,7 @@ self.from_imports = {} self.package = '.'.join(name.split('.')[:-1]) self.type = moduleType - if moduleType in [imp.PY_SOURCE, PTL_SOURCE]: + if moduleType in [PY_SOURCE, PTL_SOURCE]: self._getnext = _py_getnext elif moduleType == RB_SOURCE: self._getnext = _rb_getnext @@ -499,7 +501,7 @@ @param src the source text to be scanned (string) """ - if self.type in [imp.PY_SOURCE, PTL_SOURCE]: + if self.type in [PY_SOURCE, PTL_SOURCE]: self.__py_scan(src) elif self.type == RB_SOURCE: self.__rb_scan(src) @@ -1277,7 +1279,7 @@ @return type of the modules's source (string) """ - if self.type in [imp.PY_SOURCE, PTL_SOURCE]: + if self.type in [PY_SOURCE, PTL_SOURCE]: py3ExtList = Preferences.getDebugger("Python3Extensions").split() if self.file.endswith(tuple(py3ExtList)): moduleType = "Python3" @@ -1650,14 +1652,21 @@ ('.rb', 'r', RB_SOURCE)) else: return (open(pathname), pathname, - (ext, 'r', imp.PY_SOURCE)) + (ext, 'r', PY_SOURCE)) raise ImportError # standard Python module file if name.lower().endswith('.py'): name = name[:-3] - return imp.find_module(name, path) + spec = importlib.machinery.PathFinder.find_spec(name, path) + if spec is None: + raise ImportError + if isinstance(spec.loader, importlib.machinery.SourceFileLoader): + ext = os.path.splitext(spec.origin)[-1] + return (open(spec.origin), spec.origin, (ext, 'r', PY_SOURCE)) + + raise ImportError def resetParsedModules():