[Python-checkins] bpo-41144: Fix IDLE open module error (GH-21182)

Miss Islington (bot) webhook-mailer at python.org
Sun Jun 28 02:20:20 EDT 2020


https://github.com/python/cpython/commit/86ef6fe2b64360a1a55a913a09b12f0a80e8c06d
commit: 86ef6fe2b64360a1a55a913a09b12f0a80e8c06d
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-06-27T23:20:13-07:00
summary:

bpo-41144: Fix IDLE open module error (GH-21182)


Could not open os.path.

Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>
(cherry picked from commit 8ab77c6f9fb6ef86af8f6b8722a2fcb37438edd0)

Co-authored-by: E-Paine <63801254+E-Paine at users.noreply.github.com>

files:
A Misc/NEWS.d/next/IDLE/2020-06-27-17-02-00.bpo-41144.JoFGIX.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/idle_test/test_query.py
M Lib/idlelib/query.py

diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index edd00d4cdac1e..584fd4631fbc2 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,8 @@ Released on 2020-07-03?
 ======================================
 
 
+bpo-41144: Make Open Module open a special module such as os.path.
+
 bpo-40723: Make test_idle pass when run after import.
 Patch by Florian Dahlitz.
 
diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py
index 6d026cb532068..e968862688b95 100644
--- a/Lib/idlelib/idle_test/test_query.py
+++ b/Lib/idlelib/idle_test/test_query.py
@@ -136,6 +136,9 @@ def test_good_module_name(self):
         dialog = self.Dummy_ModuleName('idlelib')
         self.assertTrue(dialog.entry_ok().endswith('__init__.py'))
         self.assertEqual(dialog.entry_error['text'], '')
+        dialog = self.Dummy_ModuleName('os.path')
+        self.assertTrue(dialog.entry_ok().endswith('path.py'))
+        self.assertEqual(dialog.entry_error['text'], '')
 
 
 class GotoTest(unittest.TestCase):
diff --git a/Lib/idlelib/query.py b/Lib/idlelib/query.py
index 2a88530b4d082..015fc7ade459d 100644
--- a/Lib/idlelib/query.py
+++ b/Lib/idlelib/query.py
@@ -19,7 +19,7 @@
 # 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 @@ def __init__(self, parent, title, message, *, text0='', used_names={},
         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 @@ def entry_ok(self):
             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 @@ def cli_args_ok(self):
         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)
diff --git a/Misc/NEWS.d/next/IDLE/2020-06-27-17-02-00.bpo-41144.JoFGIX.rst b/Misc/NEWS.d/next/IDLE/2020-06-27-17-02-00.bpo-41144.JoFGIX.rst
new file mode 100644
index 0000000000000..ed558d3e7ded1
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2020-06-27-17-02-00.bpo-41144.JoFGIX.rst
@@ -0,0 +1 @@
+Make Open Module open a special module such as os.path.



More information about the Python-checkins mailing list