classification
Title: IDLE: Option to warn user on "Run Module" if file is not Python source
Type: enhancement Stage:
Components: IDLE Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: epaine, markroseman, terry.reedy, wyz23x2
Priority: normal Keywords:

Created on 2020-07-29 06:54 by wyz23x2, last changed 2020-10-23 15:59 by markroseman.

Messages (5)
msg374561 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-29 06:54
It would be great if IDLE shows a note when a non-Python file is attempted to run.
msg374562 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-29 06:57
It should be able to turn on/off this feature.
msg374568 - (view) Author: E. Paine (epaine) * Date: 2020-07-29 10:59
I think this sounds like a very good idea. I would recommend using the `ispythonsource` method (in the editor class) as it already has all the logic you need while also checking for a start line like "#!/usr/bin/env python" (rather than relying solely on the extension).
msg374571 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-29 13:31
I disagree.  IDLE already shows a note -- in the editor window -- with the first noted divergence from python code marked.  We are trying to keep IDLE relatively simple and not clutter it with trivial options.

ispythonsource is just a guess.  The decision is whether turn on the colorizer and do python indents.  For a new file, assume that it will be python code.  Returning True for a directory is an error that is never hit as directories are not opened.  Python files do not have to have a .py extensions, and files that have a .py extension do not have to be python files.  But IDLE encourages use of the convention.

I would consider adding a note to the SyntaxError box when the error is on the first line.  Something like "Is this really a Python code file?"

  The only actual running of non-Python files I have seen reported, and I believe at least twice, is very beginner beginners running the saved Shell log, which begins "Python 3.x...", with the 3 highlighted.  If this were recognized, the message might be "If this is a log of an interactive session, you cannot run it."

But I am not sure if this would really solve the problem of extreme ignorance.  And anything added would have to have a test, and would be a possible maintenance burden.
msg379448 - (view) Author: Mark Roseman (markroseman) * Date: 2020-10-23 15:59
I like Terry's idea of providing a better error message than just "invalid syntax" when we run something that likely isn't a Python file. There doesn't seem to be any great danger in trying to run any file that would justify a warning beforehand.
History
Date User Action Args
2020-10-23 15:59:54markrosemansetnosy: + markroseman
messages: + msg379448
2020-07-29 13:31:12terry.reedysetmessages: + msg374571
2020-07-29 10:59:13epainesetnosy: + epaine

messages: + msg374568
title: IDLE: Option to warn user on "Run Module" if file is not .py/.pyw -> IDLE: Option to warn user on "Run Module" if file is not Python source
2020-07-29 06:57:22wyz23x2settitle: IDLE: Warn user on "Run Module" if file is not .py/.pyw -> IDLE: Option to warn user on "Run Module" if file is not .py/.pyw
2020-07-29 06:57:08wyz23x2setmessages: + msg374562
2020-07-29 06:54:57wyz23x2create