diff options
author | E-Paine <63801254+E-Paine@users.noreply.github.com> | 2020-06-28 06:02:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-28 06:02:47 (GMT) |
commit | 8ab77c6f9fb6ef86af8f6b8722a2fcb37438edd0 (patch) | |
tree | bf25f277a5e9edb8eaa2bc9aa3d4a1be8d2a614d /Lib/idlelib/query.py | |
parent | 8df1016e2ef8c0a9f4d15bf7894c284295c99d9f (diff) | |
download | cpython-8ab77c6f9fb6ef86af8f6b8722a2fcb37438edd0.zip cpython-8ab77c6f9fb6ef86af8f6b8722a2fcb37438edd0.tar.gz cpython-8ab77c6f9fb6ef86af8f6b8722a2fcb37438edd0.tar.bz2 |
bpo-41144: Fix IDLE open module error (#21182)
Could not open os.path.
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/query.py')
-rw-r--r-- | Lib/idlelib/query.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/Lib/idlelib/query.py b/Lib/idlelib/query.py index 2a88530..015fc7a 100644 --- a/Lib/idlelib/query.py +++ b/Lib/idlelib/query.py @@ -19,7 +19,7 @@ Subclass HelpSource gets menu item and path for additions to Help menu. # HelpSource was extracted from configHelpSourceEdit.py (temporarily # config_help.py), with darwin code moved from ok to path_ok. -import importlib +import importlib.util, importlib.abc import os import shlex from sys import executable, platform # Platform is set for one test. @@ -57,7 +57,8 @@ class Query(Toplevel): self.withdraw() # Hide while configuring, especially geometry. self.title(title) self.transient(parent) - self.grab_set() + if not _utest: # Otherwise fail when directly run unittest. + self.grab_set() windowingsystem = self.tk.call('tk', 'windowingsystem') if windowingsystem == 'aqua': @@ -209,17 +210,23 @@ class ModuleName(Query): self.showerror(str(msg)) return None if spec is None: - self.showerror("module not found") + self.showerror("module not found.") return None if not isinstance(spec.loader, importlib.abc.SourceLoader): - self.showerror("not a source-based module") + self.showerror("not a source-based module.") return None try: file_path = spec.loader.get_filename(name) except AttributeError: - self.showerror("loader does not support get_filename", - parent=self) + self.showerror("loader does not support get_filename.") return None + except ImportError: + # Some special modules require this (e.g. os.path) + try: + file_path = spec.loader.get_filename() + except TypeError: + self.showerror("loader failed to get filename.") + return None return file_path @@ -375,7 +382,7 @@ class CustomRun(Query): return cli_args def entry_ok(self): - "Return apparently valid (cli_args, restart) or None" + "Return apparently valid (cli_args, restart) or None." cli_args = self.cli_args_ok() restart = self.restartvar.get() return None if cli_args is None else (cli_args, restart) |