Also add .pyi to the python extensions in the "File-open" and "File-save" dialogues.
Add util.py to contain objects that are used in multiple idlelib modules
and have no dependencies on any of them.
Co-authored-by: E-Paine <63801254+E-Paine@users.noreply.github.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
(Contributed by Mark Dickinson in :issue:`44547`.)
+IDLE and idlelib
+----------------
+
+* IDLE now applies syntax highlighting to `.pyi` files. (Contributed by Alex
+ Waygood and Terry Jan Reedy in :issue:`45447`.)
+
inspect
-------
* Add :func:`inspect.getmembers_static`: return all members without
=========================
+bpo-28950: Apply IDLE syntax highlighting to `.pyi` files. Add util.py
+for common components. Patch by Alex Waygood and Terry Jan Reedy.
+
bpo-46630: Make query dialogs on Windows start with a cursor in the
entry box.
textview.py # Define read-only text widget (nim).
tree.py # Define tree widget, used in browsers (nim).
undo.py # Manage undo stack.
+util.py # Define objects imported elsewhere with no dependencies (nim)
windows.py # Manage window list and define listed top level.
zoomheight.py # Zoom window to full height of screen.
from idlelib import replace
from idlelib import search
from idlelib.tree import wheel_event
+from idlelib.util import py_extensions
from idlelib import window
# The default tab setting for a Text widget, in average-width characters.
if not filename or os.path.isdir(filename):
return True
base, ext = os.path.splitext(os.path.basename(filename))
- if os.path.normcase(ext) in (".py", ".pyw"):
+ if os.path.normcase(ext) in py_extensions:
return True
line = self.text.get('1.0', '1.0 lineend')
return line.startswith('#!') and 'python' in line
--- /dev/null
+#!usr/bin/env python
+
+def example_function(some_argument):
+ pass
--- /dev/null
+class Example:
+ def method(self, argument1: str, argument2: list[int]) -> None: ...
"Test , coverage 17%."
-from idlelib import iomenu
+from idlelib import iomenu, util
import unittest
from test.support import requires
from tkinter import Tk
eq(fix(), 'a'+io.eol_convention)
+def _extension_in_filetypes(extension):
+ return any(
+ f'*{extension}' in filetype_tuple[1]
+ for filetype_tuple in iomenu.IOBinding.filetypes
+ )
+
+
+class FiletypesTest(unittest.TestCase):
+ def test_python_source_files(self):
+ for extension in util.py_extensions:
+ with self.subTest(extension=extension):
+ self.assertTrue(
+ _extension_in_filetypes(extension)
+ )
+
+ def test_text_files(self):
+ self.assertTrue(_extension_in_filetypes('.txt'))
+
+ def test_all_files(self):
+ self.assertTrue(_extension_in_filetypes(''))
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)
--- /dev/null
+"""Test util, coverage 100%"""
+
+import unittest
+from idlelib import util
+
+
+class UtilTest(unittest.TestCase):
+ def test_extensions(self):
+ for extension in {'.pyi', '.py', '.pyw'}:
+ self.assertIn(extension, util.py_extensions)
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
import idlelib
from idlelib.config import idleConf
+from idlelib.util import py_extensions
+
+py_extensions = ' '.join("*"+ext for ext in py_extensions)
encoding = 'utf-8'
if sys.platform == 'win32':
savedialog = None
filetypes = (
- ("Python files", "*.py *.pyw", "TEXT"),
+ ("Python files", py_extensions, "TEXT"),
("Text files", "*.txt", "TEXT"),
("All files", "*"),
)
--- /dev/null
+"""
+Idlelib objects with no external idlelib dependencies
+which are needed in more than one idlelib module.
+
+They are included here because
+ a) they don't particularly belong elsewhere; or
+ b) because inclusion here simplifies the idlelib dependency graph.
+
+TODO:
+ * Python versions (editor and help_about),
+ * tk version and patchlevel (pyshell, help_about, maxos?, editor?),
+ * std streams (pyshell, run),
+ * warning stuff (pyshell, run).
+"""
+from os import path
+
+# .pyw is for Windows; .pyi is for stub files.
+py_extensions = ('.py', '.pyw', '.pyi') # Order needed for open/save dialogs.
+
+if __name__ == '__main__':
+ from unittest import main
+ main('idlelib.idle_test.test_util', verbosity=2)
--- /dev/null
+Apply IDLE syntax highlighting to `.pyi` files. Patch by Alex Waygood
+and Terry Jan Reedy.