diff options
Diffstat (limited to 'Lib/idlelib/browser.py')
-rw-r--r-- | Lib/idlelib/browser.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/Lib/idlelib/browser.py b/Lib/idlelib/browser.py index 4da2d40..4fe64dc 100644 --- a/Lib/idlelib/browser.py +++ b/Lib/idlelib/browser.py @@ -6,7 +6,6 @@ XXX TO DO: (or recheck on window popup) - add popup menu with more options (e.g. doc strings, base classes, imports) - add base classes to class browser tree -- finish removing limitation to x.py files (ModuleBrowserTreeItem) """ import os @@ -16,12 +15,22 @@ import sys from idlelib.config import idleConf from idlelib import pyshell from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas +from idlelib.util import py_extensions from idlelib.window import ListedToplevel file_open = None # Method...Item and Class...Item use this. # Normally pyshell.flist.open, but there is no pyshell.flist for htest. +# The browser depends on pyclbr and importlib which do not support .pyi files. +browseable_extension_blocklist = ('.pyi',) + + +def is_browseable_extension(path): + _, ext = os.path.splitext(path) + ext = os.path.normcase(ext) + return ext in py_extensions and ext not in browseable_extension_blocklist + def transform_children(child_dict, modname=None): """Transform a child dictionary to an ordered sequence of objects. @@ -76,8 +85,8 @@ class ModuleBrowser: Instance variables: name: Module name. - file: Full path and module with .py extension. Used in - creating ModuleBrowserTreeItem as the rootnode for + file: Full path and module with supported extension. + Used in creating ModuleBrowserTreeItem as the rootnode for the tree and subsequently in the children. """ self.master = master @@ -161,22 +170,22 @@ class ModuleBrowserTreeItem(TreeItem): def OnDoubleClick(self): "Open a module in an editor window when double clicked." - if os.path.normcase(self.file[-3:]) != ".py": + if not is_browseable_extension(self.file): return if not os.path.exists(self.file): return file_open(self.file) def IsExpandable(self): - "Return True if Python (.py) file." - return os.path.normcase(self.file[-3:]) == ".py" + "Return True if Python file." + return is_browseable_extension(self.file) def listchildren(self): "Return sequenced classes and functions in the module." - dir, base = os.path.split(self.file) - name, ext = os.path.splitext(base) - if os.path.normcase(ext) != ".py": + if not is_browseable_extension(self.file): return [] + dir, base = os.path.split(self.file) + name, _ = os.path.splitext(base) try: tree = pyclbr.readmodule_ex(name, [dir] + sys.path) except ImportError: |