cpython: a0d8ae880ae6 (original) (raw)
--- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -1,5 +1,5 @@ -import imp import importlib +import importlib.abc import os import re import string @@ -35,34 +35,6 @@ def _sphinx_version(): release += '%s%s' % (level[0], serial) return release -def _find_module(fullname, path=None):
- file = None
- for tgt in fullname.split('.'):
if file is not None:[](#l1.19)
file.close() # close intermediate files[](#l1.20)
(file, filename, descr) = imp.find_module(tgt, path)[](#l1.21)
if descr[2] == imp.PY_SOURCE:[](#l1.22)
break # find but not load the source file[](#l1.23)
module = imp.load_module(tgt, file, filename, descr)[](#l1.24)
try:[](#l1.25)
path = module.__path__[](#l1.26)
except AttributeError:[](#l1.27)
raise ImportError('No source for module ' + module.__name__)[](#l1.28)
- if descr[2] != imp.PY_SOURCE:
# If all of the above fails and didn't raise an exception,fallback[](#l1.30)
# to a straight import which can find __init__.py in a package.[](#l1.31)
m = __import__(fullname)[](#l1.32)
try:[](#l1.33)
filename = m.__file__[](#l1.34)
except AttributeError:[](#l1.35)
pass[](#l1.36)
else:[](#l1.37)
file = None[](#l1.38)
descr = os.path.splitext(filename)[1], None, imp.PY_SOURCE[](#l1.39)
- return file, filename, descr
- class HelpDialog(object): @@ -687,20 +659,29 @@ class EditorWindow(object): return # XXX Ought to insert current file's directory in front of path try:
(f, file, (suffix, mode, type)) = _find_module(name)[](#l1.49)
except (NameError, ImportError) as msg:[](#l1.50)
loader = importlib.find_loader(name)[](#l1.51)
except (ValueError, ImportError) as msg:[](#l1.52) tkMessageBox.showerror("Import error", str(msg), parent=self.text)[](#l1.53) return[](#l1.54)
if type != imp.PY_SOURCE:[](#l1.55)
tkMessageBox.showerror("Unsupported type",[](#l1.56)
"%s is not a source module" % name, parent=self.text)[](#l1.57)
if loader is None:[](#l1.58)
tkMessageBox.showerror("Import error", "module not found",[](#l1.59)
parent=self.text)[](#l1.60)
return[](#l1.61)
if not isinstance(loader, importlib.abc.SourceLoader):[](#l1.62)
tkMessageBox.showerror("Import error", "not a source-based module",[](#l1.63)
parent=self.text)[](#l1.64) return[](#l1.65)
if f:[](#l1.66)
f.close()[](#l1.67)
try:[](#l1.68)
file_path = loader.get_filename(name)[](#l1.69)
except AttributeError:[](#l1.70)
tkMessageBox.showerror("Import error",[](#l1.71)
"loader does not support get_filename",[](#l1.72)
parent=self.text)[](#l1.73)
return[](#l1.74) if self.flist:[](#l1.75)
self.flist.open(file)[](#l1.76)
self.flist.open(file_path)[](#l1.77) else:[](#l1.78)
self.io.loadfile(file)[](#l1.79)
self.io.loadfile(file_path)[](#l1.80)
def open_class_browser(self, event=None): filename = self.io.filename
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -71,6 +71,8 @@ Library IDLE ---- +- Issue #18055: Move IDLE off of imp and on to importlib. +