This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Make IDLE recognize .pyi stub files as source for open, save, and edit
Type: enhancement Stage: patch review
Components: IDLE Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: AlexWaygood, epaine, miss-islington, ronaldoussoren, steve.dower, terry.reedy
Priority: normal Keywords: patch

Created on 2021-10-12 15:24 by AlexWaygood, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 28950 merged AlexWaygood, 2021-10-14 16:10
PR 31303 merged terry.reedy, 2022-02-13 00:25
PR 31304 merged terry.reedy, 2022-02-13 00:47
PR 31305 merged terry.reedy, 2022-02-13 00:51
PR 31306 merged miss-islington, 2022-02-13 00:52
PR 31307 merged terry.reedy, 2022-02-13 00:59
PR 31308 merged miss-islington, 2022-02-13 02:10
PR 31309 merged miss-islington, 2022-02-13 02:11
PR 31310 merged miss-islington, 2022-02-13 02:11
Messages (28)
msg403738 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-10-12 15:24
IDLE currently does not do any syntax highlighting if you use it to open a .pyi stub file, even though everything in a .pyi file is a valid Python expression. It would be great if syntax highlighting for .pyi files could be supported.
msg403741 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-10-12 15:51
It should be fairly easy to recognize x.pyi as a python file.  Just have to find the place.  Something like
  def f(i:int) -> int: ...
would have 'def' and 'int' highlighted.
msg403755 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-10-12 19:36
It looks like support for .py files is hardcoded into IDLE's source code in the following places:


* browser.ModuleBrowserTreeItem.OnDoubleClick
* browser.ModuleBrowserTreeItem.IsExpandable
* browser.ModuleBrowserTreeItem.listchildren
* editor.ispythonsource  << This is the one that controls syntax highlighting
* iomenu.IOBinding.filetypes


If I were to file a PR adding support for .pyi files, would you prefer that I hardcoded ".pyi" in, or would it be better to add a SUPPORTED_FILES constant somewhere?
msg403772 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-10-13 00:49
Thank you for doing the research.

I have been thinking about adding a file containing idlelib 'leaf' objects, those with no idlelib dependencies, which are needed in more than one file. would be to reduce the complexity of the idlelib dependency graph, which has enough cyclic dependencies to make startup tricky.  Time to do it.  idlelib/common.py?, leaves.py?, or ???  Draft:
---
"""Idlelib objects with no external idlelib dependencies and 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 (ditto).
"""

# python_extensions is used in editor, browser, and iomenu.
# .pyw is for Windows; .pyi is for stub files.
python_extensions = ('.py', '.pyw', '.pyi')  
extension_string = "*" + " *".join(python_extensions)
---

editor.EditorWindow.ispythonsource could be moved into the new file if a 'firstline=None' argument were added.

OnDoubleClick should use IsExpandable.  IsExpandable should use the logic in ispythonsource so Linux no-extension python source can be browsed as well as edited.

After manual testing, add a new test_common.py file in idlelib.idle_test. After imports, it could start with one test:

class ExtensionTest(TestCase):
    def test_stub(self):
        self.assertIn('.pyi', common.python_extensions)
        self.assertIn('.pyi', common.extension_string)

For IDLE, I can and will backport.
msg403884 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-10-14 03:27
I am going to call the file util.py and will work on a PR.
msg403889 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-10-14 07:36
Oh — I've already nearly finished a PR. Do you mind if I submit mine? Happy to make any changes you like, obviously.
msg403915 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-10-14 16:25
Have posted my PR. I've tested it manually and run the IDLE test suite on it with the `-u all` setting; it seems fine. The new tests I've written are a bit thin on the ground right now, though. I may need some guidance/help if more extensive tests are needed -- I'm a little new to unittest.

One other thing I'm not sure on: the docstring at the top of `browser.py` includes the line "- finish removing limitation to x.py files (ModuleBrowserTreeItem)" in the TODO items. Can this be removed now?
msg403998 - (view) Author: E. Paine (epaine) * Date: 2021-10-15 09:58
Would it make sense, since this issue pretty much makes IDLE officially support .pyi files, to add the "Edit with IDLE" menu when right-clicking on a .pyi file in Windows explorer?
msg404021 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-10-15 14:15
Yes.  After this issue is done, we should open a new issue and nosy Steve Dower, who is in charge of that for Windows, and Ned Deily, in case anything should be done on mac.
msg404023 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2021-10-15 14:23
The most straightforward change for macOS is to add “pyi” to the list of extensions in “Mac/IDLE/IDLE.app/Contents/Info.plist”.  That way IDLE will be seen as a valid editor for .pyi files.
msg404030 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-10-15 15:29
Steve, how do we make it so that "Edit with IDLE" appears when right-clicking on a .pyi file in Windows explorer?  As easy as on mac (see Ronald's answer above)?
msg404100 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-10-16 16:34
Bit more complicated. It'll need changes to Tools/msi/launcher/launcher_reg.wxs, Tools/msi/tcltk/tcltk_reg.wxs, and PC/layout/support/appxmanifest.py, but I don't think it's that obvious where (we don't want these files to open with py.exe by default, so they'll need a whole new definition).
msg404102 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-10-16 16:54
Shall I add the change to the mac file to my PR, or would it be better to leave it for a separate PR? (I'm not confident enough to make the changes to the Windows files.)
msg404110 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-10-16 19:11
We can add the mac change once it is manually tested on some system.  I may try on my macbook.  Windows will be another PR or even issue.
msg410637 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2022-01-15 10:14
@terry, have you had a chance to glance at my PR at all? I'd really appreciate your review! :)
msg410669 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-01-16 03:41
A minimal version of util.py just for this issue is fine.  What is blocking the issue deciding exactly what the minimum should be.  Are both the extension list and function needed?

Alex says somewhere in PR comments that ispythonsource passes directories.  That seems wrong.  Perhaps moving and revising it and making no-extension files browsable and removing the x.py(?) limitation should be a separate issue.  IDLE users on *nix don't mind using extensions.  I have not seen a complaint, though perhaps people who do mind silently use something else.  I need to check again how the editor function is used and decide if we can leave it alone for now.  So don't remove anything just now.

I need to experiment with Ron's suggestion on my Mac.

The Windows context menu is definitely a separate issue.

Please add idle_test/example.pyi with the line in msg403741 for manual testing now and possibly future automatic testing.
msg412561 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-05 05:14
For the open dialog, we only need the expanded extension list.  People with no-extension python code file must select 'all files'.  Once the file is open, we need the issource function to decide whether to turn on the colorizer.  I intend to review the patch itself tomorrow.
msg412617 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-06 06:39
I broaden the issue title scope and will correspondingly restrict the PR scope.  'Recognition' applies to open and save dialogs, syntax marking, and module browsing.  (The latter needs fixing for .pyw also.)

Improving the handling of no extension source with initial #! line will be a different issue.
msg413147 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-13 00:04
New changeset 50cf4991c49e19f917305dd7b9c71085c11edddb by Alex Waygood in branch 'main':
bpo-45447: Add syntax highlighting for `.pyi` files in IDLE (GH-28950)
https://github.com/python/cpython/commit/50cf4991c49e19f917305dd7b9c71085c11edddb
msg413149 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-13 00:52
New changeset 9fabcfbe68ff81ef5f17f86a93daf9cce9d83876 by Terry Jan Reedy in branch '3.10':
bpo-45447: Add syntax highlighting for `.pyi` files in IDLE (GH-28950)
https://github.com/python/cpython/commit/9fabcfbe68ff81ef5f17f86a93daf9cce9d83876
msg413150 - (view) Author: miss-islington (miss-islington) Date: 2022-02-13 01:19
New changeset 1d4d44c385414042cbdd2a1e9504cd8e9d69c0ae by Miss Islington (bot) in branch '3.9':
bpo-45447: Add syntax highlighting for `.pyi` files in IDLE (GH-28950)
https://github.com/python/cpython/commit/1d4d44c385414042cbdd2a1e9504cd8e9d69c0ae
msg413156 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-13 02:10
New changeset 2d98433549be358d1c192e30e51b8d345d618cc7 by Terry Jan Reedy in branch 'main':
bpo-45447: Add entry to What's new 3.10 (GH-31304)
https://github.com/python/cpython/commit/2d98433549be358d1c192e30e51b8d345d618cc7
msg413157 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-13 02:11
New changeset cef91ca80c41749824eca1d4b2c99731e3d5f64c by Terry Jan Reedy in branch 'main':
bpo-45447: Add entry to What's new 3.9 (GH-31305)
https://github.com/python/cpython/commit/cef91ca80c41749824eca1d4b2c99731e3d5f64c
msg413158 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-13 02:12
New changeset 6331c08d1c3248ff47a7b8e0045c9023c9af672c by Terry Jan Reedy in branch 'main':
bpo-45447: Fix entry in What's New 3.11 (GH-31307)
https://github.com/python/cpython/commit/6331c08d1c3248ff47a7b8e0045c9023c9af672c
msg413168 - (view) Author: miss-islington (miss-islington) Date: 2022-02-13 06:30
New changeset 5698e0be8e77bd4d7a1fda88005662f0b239dec8 by Miss Islington (bot) in branch '3.10':
bpo-45447: Add entry to What's new 3.9 (GH-31305)
https://github.com/python/cpython/commit/5698e0be8e77bd4d7a1fda88005662f0b239dec8
msg413169 - (view) Author: miss-islington (miss-islington) Date: 2022-02-13 06:30
New changeset ebe73e6095fc019fd1e31c9f41bc67d56ee003b6 by Miss Islington (bot) in branch '3.9':
bpo-45447: Add entry to What's new 3.9 (GH-31305)
https://github.com/python/cpython/commit/ebe73e6095fc019fd1e31c9f41bc67d56ee003b6
msg413170 - (view) Author: miss-islington (miss-islington) Date: 2022-02-13 06:31
New changeset 44666c3285a52c2a4632f89aeeddd7ca7d02c8df by Miss Islington (bot) in branch '3.10':
bpo-45447: Add entry to What's new 3.10 (GH-31304)
https://github.com/python/cpython/commit/44666c3285a52c2a4632f89aeeddd7ca7d02c8df
msg413211 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-14 03:35
Issue 46746 is the followup for browsers (currently restricted to .py files) and anything else.
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89610
2022-02-14 03:35:10terry.reedysetmessages: + msg413211
title: Make IDLE recognize .pyi stub files (and .pyw) as python source -> Make IDLE recognize .pyi stub files as source for open, save, and edit
2022-02-13 06:31:10miss-islingtonsetmessages: + msg413170
2022-02-13 06:30:39miss-islingtonsetmessages: + msg413169
2022-02-13 06:30:34miss-islingtonsetmessages: + msg413168
2022-02-13 02:12:25terry.reedysetmessages: + msg413158
2022-02-13 02:11:33miss-islingtonsetpull_requests: + pull_request29471
2022-02-13 02:11:29miss-islingtonsetpull_requests: + pull_request29470
2022-02-13 02:11:24terry.reedysetmessages: + msg413157
2022-02-13 02:10:49terry.reedysetmessages: + msg413156
2022-02-13 02:10:41miss-islingtonsetpull_requests: + pull_request29469
2022-02-13 01:19:32miss-islingtonsetmessages: + msg413150
2022-02-13 00:59:34terry.reedysetpull_requests: + pull_request29468
2022-02-13 00:52:47miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request29467
2022-02-13 00:52:45terry.reedysetmessages: + msg413149
2022-02-13 00:51:52terry.reedysetpull_requests: + pull_request29466
2022-02-13 00:47:26terry.reedysetpull_requests: + pull_request29465
2022-02-13 00:25:08terry.reedysetpull_requests: + pull_request29464
2022-02-13 00:04:56terry.reedysetmessages: + msg413147
2022-02-06 06:39:12terry.reedysetmessages: + msg412617
title: IDLE: Support syntax highlighting for .pyi stub files -> Make IDLE recognize .pyi stub files (and .pyw) as python source
2022-02-05 05:14:55terry.reedysetmessages: + msg412561
2022-01-16 03:41:00terry.reedysetmessages: + msg410669
2022-01-15 10:14:23AlexWaygoodsetmessages: + msg410637
2021-10-16 19:11:57terry.reedysetmessages: + msg404110
2021-10-16 16:54:34AlexWaygoodsetmessages: + msg404102
2021-10-16 16:34:21steve.dowersetmessages: + msg404100
2021-10-15 15:29:47terry.reedysetnosy: + steve.dower
messages: + msg404030
2021-10-15 14:23:10ronaldoussorensetnosy: + ronaldoussoren
messages: + msg404023
2021-10-15 14:15:21terry.reedysetmessages: + msg404021
2021-10-15 09:58:47epainesetmessages: + msg403998
2021-10-14 16:25:24AlexWaygoodsetmessages: + msg403915
2021-10-14 16:10:50AlexWaygoodsetkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request27239
2021-10-14 11:12:26epainesetnosy: + epaine
2021-10-14 07:36:51AlexWaygoodsetmessages: + msg403889
2021-10-14 03:27:13terry.reedysetmessages: + msg403884
2021-10-13 00:49:08terry.reedysetmessages: + msg403772
stage: test needed
2021-10-12 19:36:00AlexWaygoodsetmessages: + msg403755
2021-10-12 15:51:22terry.reedysetmessages: + msg403741
2021-10-12 15:24:54AlexWaygoodsettitle: Support syntax highlighting for .pyi stub files -> IDLE: Support syntax highlighting for .pyi stub files
2021-10-12 15:24:36AlexWaygoodcreate