bpo-41144: Fix IDLE open module error (#21182)
Could not open os.path. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
8df1016e2e
commit
8ab77c6f9f
|
@ -3,6 +3,8 @@ Released on 2020-10-05?
|
||||||
======================================
|
======================================
|
||||||
|
|
||||||
|
|
||||||
|
bpo-41144: Make Open Module open a special module such as os.path.
|
||||||
|
|
||||||
bpo-40723: Make test_idle pass when run after import.
|
bpo-40723: Make test_idle pass when run after import.
|
||||||
Patch by Florian Dahlitz.
|
Patch by Florian Dahlitz.
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,9 @@ class ModuleNameTest(unittest.TestCase):
|
||||||
dialog = self.Dummy_ModuleName('idlelib')
|
dialog = self.Dummy_ModuleName('idlelib')
|
||||||
self.assertTrue(dialog.entry_ok().endswith('__init__.py'))
|
self.assertTrue(dialog.entry_ok().endswith('__init__.py'))
|
||||||
self.assertEqual(dialog.entry_error['text'], '')
|
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):
|
class GotoTest(unittest.TestCase):
|
||||||
|
|
|
@ -19,7 +19,7 @@ Subclass HelpSource gets menu item and path for additions to Help menu.
|
||||||
# HelpSource was extracted from configHelpSourceEdit.py (temporarily
|
# HelpSource was extracted from configHelpSourceEdit.py (temporarily
|
||||||
# config_help.py), with darwin code moved from ok to path_ok.
|
# config_help.py), with darwin code moved from ok to path_ok.
|
||||||
|
|
||||||
import importlib
|
import importlib.util, importlib.abc
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
from sys import executable, platform # Platform is set for one test.
|
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.withdraw() # Hide while configuring, especially geometry.
|
||||||
self.title(title)
|
self.title(title)
|
||||||
self.transient(parent)
|
self.transient(parent)
|
||||||
self.grab_set()
|
if not _utest: # Otherwise fail when directly run unittest.
|
||||||
|
self.grab_set()
|
||||||
|
|
||||||
windowingsystem = self.tk.call('tk', 'windowingsystem')
|
windowingsystem = self.tk.call('tk', 'windowingsystem')
|
||||||
if windowingsystem == 'aqua':
|
if windowingsystem == 'aqua':
|
||||||
|
@ -209,17 +210,23 @@ class ModuleName(Query):
|
||||||
self.showerror(str(msg))
|
self.showerror(str(msg))
|
||||||
return None
|
return None
|
||||||
if spec is None:
|
if spec is None:
|
||||||
self.showerror("module not found")
|
self.showerror("module not found.")
|
||||||
return None
|
return None
|
||||||
if not isinstance(spec.loader, importlib.abc.SourceLoader):
|
if not isinstance(spec.loader, importlib.abc.SourceLoader):
|
||||||
self.showerror("not a source-based module")
|
self.showerror("not a source-based module.")
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
file_path = spec.loader.get_filename(name)
|
file_path = spec.loader.get_filename(name)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.showerror("loader does not support get_filename",
|
self.showerror("loader does not support get_filename.")
|
||||||
parent=self)
|
|
||||||
return None
|
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
|
return file_path
|
||||||
|
|
||||||
|
|
||||||
|
@ -375,7 +382,7 @@ class CustomRun(Query):
|
||||||
return cli_args
|
return cli_args
|
||||||
|
|
||||||
def entry_ok(self):
|
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()
|
cli_args = self.cli_args_ok()
|
||||||
restart = self.restartvar.get()
|
restart = self.restartvar.get()
|
||||||
return None if cli_args is None else (cli_args, restart)
|
return None if cli_args is None else (cli_args, restart)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Make Open Module open a special module such as os.path.
|
Loading…
Reference in New Issue