Repository navigation
Make IDLE recognize .pyi stub files as source for open, save, and edit #89610
Copy link
Copy link
Closed
Labels
3.11only security fixesonly security fixestopic-IDLEtype-featureA feature request or enhancementA feature request or enhancement
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/terryjreedy'
closed_at = None
created_at = <Date 2021-10-12.15:24:36.540>
labels = ['expert-IDLE', 'type-feature', '3.11']
title = 'Make IDLE recognize .pyi stub files as source for open, save, and edit'
updated_at = <Date 2022-02-14.03:35:10.254>
user = 'https://github.com/AlexWaygood'bugs.python.org fields:
activity = <Date 2022-02-14.03:35:10.254>
actor = 'terry.reedy'
assignee = 'terry.reedy'
closed = False
closed_date = None
closer = None
components = ['IDLE']
creation = <Date 2021-10-12.15:24:36.540>
creator = 'AlexWaygood'
dependencies = []
files = []
hgrepos = []
issue_num = 45447
keywords = ['patch']
message_count = 28.0
messages = ['403738', '403741', '403755', '403772', '403884', '403889', '403915', '403998', '404021', '404023', '404030', '404100', '404102', '404110', '410637', '410669', '412561', '412617', '413147', '413149', '413150', '413156', '413157', '413158', '413168', '413169', '413170', '413211']
nosy_count = 6.0
nosy_names = ['terry.reedy', 'ronaldoussoren', 'steve.dower', 'miss-islington', 'epaine', 'AlexWaygood']
pr_nums = ['28950', '31303', '31304', '31305', '31306', '31307', '31308', '31309', '31310']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue45447'
versions = ['Python 3.11']Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixestopic-IDLEtype-featureA feature request or enhancementA feature request or enhancement
Projects
- StatusShow more project fieldsDone
Activity
AlexWaygood commentedon Oct 12, 2021
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.
[-]Support syntax highlighting for .pyi stub files[/-][+]IDLE: Support syntax highlighting for .pyi stub files[/+][-]Support syntax highlighting for .pyi stub files[/-][+]IDLE: Support syntax highlighting for .pyi stub files[/+]terryjreedy commentedon Oct 12, 2021
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.
AlexWaygood commentedon Oct 12, 2021
It looks like support for .py files is hardcoded into IDLE's source code in the following places:
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?
terryjreedy commentedon Oct 13, 2021
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).
"""
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:
For IDLE, I can and will backport.
terryjreedy commentedon Oct 14, 2021
I am going to call the file util.py and will work on a PR.
AlexWaygood commentedon Oct 14, 2021
Oh — I've already nearly finished a PR. Do you mind if I submit mine? Happy to make any changes you like, obviously.
34 remaining items
ronaldoussoren commentedon Jul 28, 2022
See also my comment about adding
pyito the list ofCFBundleTypeExtensionsin IDLE's Info.plist. That will allow opening stub files by double clicking on them in the Finder, and is not necessary for the File/open menu.Otherwise syntax coloring for stub files appears to work fine in the current Python 3.11 beta.
pythongh-89610: Add .pyi as a recognised extension for IDLE on macOS
erlend-aasland commentedon Jul 28, 2022
👉🏻 #95393
pythongh-89610: Don't hardcode supported extensions in IDLE browser
erlend-aasland commentedon Jul 28, 2022
👉🏻 #95397
Seems irrelevant for this issue to me; I might be wrong, I only took a quick glance at the code.
terryjreedy commentedon Jul 28, 2022
I listed iomenu filetypes before we added the util.py_extensions tuple, which is used in several places. Before, the same information was duplicated in multiple places. That item is now obsolete.
pythongh-89610: Add .pyi as a recognised extension for IDLE on macOS (p…
pythongh-89610: Add .pyi as a recognised extension for IDLE on macOS (p…
gh-89610: Add .pyi as a recognised extension for IDLE on macOS (#95393)
gh-89610: Add .pyi as a recognised extension for IDLE on macOS (GH-95393
gh-89610: Add .pyi as a recognised extension for IDLE on macOS (GH-95393
terryjreedy commentedon Jul 29, 2022
I open task issue #95410 with two of the items completed by this issue. I opened a browser issue #95411 and moved the browser PR there.