10000 gh-95411: IDLE - Enable using the module browser with .pyw files by erlend-aasland · Pull Request #95397 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-95411: IDLE - Enable using the module browser with .pyw files #95397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review: drop support for .pyi in browser
  • Loading branch information
erlend-aasland committed Jul 29, 2022
commit de3ba24e36c9fbb5cbafb8f07f7edb635a7985c3
8 changes: 4 additions & 4 deletions Lib/idlelib/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from idlelib.config import idleConf
from idlelib import 8000 pyshell
from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
from idlelib.util import is_supported_extension
from idlelib.util import is_browseable_extension
from idlelib.window import ListedToplevel


Expand Down Expand Up @@ -161,19 +161,19 @@ def GetSubList(self):

def OnDoubleClick(self):
"Open a module in an editor window when double clicked."
if not is_supported_extension(self.file):
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 file."
return is_supported_extension(self.file)
return is_browseable_extension(self.file)

def listchildren(self):
"Return sequenced classes and functions in the module."
if not is_supported_extension(self.file):
if not is_browseable_extension(self.file):
return []
dir, base = os.path.split(self.file)
name, _ = os.path.splitext(base)
Expand Down
16 changes: 12 additions & 4 deletions Lib/idlelib/idle_test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@


class UtilTest(unittest.TestCase):
path = '/some/path/myfile'

def test_is_supported_extension(self):
path = '/some/path/myfile'
for ext in util.py_extensions:
with self.subTest(ext=ext):
filename = f'{path}{ext}'
filename = f'{self.path}{ext}'
self.assertTrue(util.is_supported_extension(filename))

def test_is_not_supported_extension(self):
path = '/some/path/myfile'
for ext in '.txt', '.p', '.pyww', '.pyii', '.pyy', '':
with self.subTest(ext=ext):
filename = f"{path}{ext}"
filename = f"{self.path}{ext}"
self.assertFalse(util.is_supported_extension(filename))

def test_is_browseable_extension(self):
for ext in util.py_extensions:
with self.subTest(ext=ext):
filename = f'{self.path}{ext}'
actual = util.is_browseable_extension(filename)
expected = ext not in util.browseable_extension_blocklist
self.assertEqual(actual, expected)


if __name__ == '__main__':
unittest.main(verbosity=2)
19 changes: 15 additions & 4 deletions Lib/idlelib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,23 @@
# .pyw is for Windows; .pyi is for stub files.
py_extensions = ('.py', '.pyw', '.pyi') # Order needed for open/save dialogs.

# The browser depends on pyclbr and importlib which do not support .pyi files.
browseable_extension_blocklist = ('.pyi',)

def is_supported_extension(path):

def _get_ext(path):
_, ext = os.path.splitext(path)
if not ext:
return False
return os.path.normcase(ext) in py_extensions
return os.path.normcase(ext)


def is_supported_extension(path):
ext = _get_ext(path)
return ext in py_extensions


def is_browseable_extension(path):
ext = _get_ext(path)
return ext in py_extensions and ext not in browseable_extension_blocklist


if __name__ == '__main__':
Expand Down
0