[New-bugs-announce] [issue46746] IDLE: Consistently handle non .py source files

Terry J. Reedy report at bugs.python.org
Sun Feb 13 22:33:18 EST 2022

New submission from Terry J. Reedy <tjreedy at udel.edu>:

Python will attempt to execute any file it can decode to unicode text as a startup script.  It will only import .py files as a module.  #45447 turned on syntax coloring for .pyi stub files.  (.pyw files and files starting with "!#.*python" were already recognized as source (scripts).) It also added '.pyi' as a possible python extension in open and save dialogs.

For this issue, fix some other modules, as appropriate, for non-.py files.

Pathbrowser: Except for the files in sys.path, pathbrowser only shows .py files and directories including such.  It should be easy to also list .pyw and .pyi files and directories.  Perhaps a button could be added to list all files.

Open Module: Opens a module when given a valid import name.  So it cannot be used to open non-modules, which is to say, non .py files.  .pyi files are condensed modules, not startup files, but opening them would require considerable change since the import machinery is currently used.  We could add a message to the box saying, "To open a non-module (non .py) file, use File => Open."

Modulebrowser: This was originally called Classbrowser as it only browsed top-level classes and their methods.  It now browses all classes and def-ined functions and I renamed it to indicate the expanded scope. Since it only browses .py files, I did not know that I was theoretically narrowing the scope to exclude non-.py files.

Currently, when editing a non-.py file and trying to open a module browser, a window is opened and nothing happens.  This is the same as with a file with no classes or functions.  Either browse or display an error message.  The latter would include files with nothing to browse.

Anything else?

assignee: terry.reedy
components: IDLE
messages: 413210
nosy: terry.reedy
priority: normal
severity: normal
stage: test needed
status: open
title: IDLE: Consistently handle non .py source files
type: enhancement
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list