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: IDLE: Wrong highlighting when \n follows def/class
Type: behavior Stage: needs patch
Components: IDLE Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Alex-Python-Programmer, terry.reedy
Priority: normal Keywords:

Created on 2020-04-25 03:29 by Alex-Python-Programmer, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg367249 - (view) Author: Alex (Alex-Python-Programmer) Date: 2020-04-25 03:29
In this code:

def a():
    #
def
def b():

When I delete the # at line 3, the keyword 'def' become blue.
msg367251 - (view) Author: Alex (Alex-Python-Programmer) Date: 2020-04-25 03:32
The sharp is at line 2, not line 3. I made a mistake.
msg367337 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-04-27 00:57
For me, on Mac, only  the 3rd 'def', on line 4, changes to blue, the default highlight for defined names (those immediately following 'def' or 'class').  This is because deleting the '#' causes recoloring from there onward, and IDLE's handling of newlines after 'def' or 'class' is buggy. I presume that you see the same.

I most concerned with correctly highlighting correct code.  It may be ambiguous what to do with incorrect code.  If one types 'def name' or 'class name' to start a line, name is colored blue as a definition name.  If name happens to be misspelled to match a keyword, should it be colored as a keyword?  Maybe, but in this context, it will not function as such.  Perhaps it should be immediately colored as a syntax error (default red), instead of waiting for an explicit syntax check.  But this an innovation for IDLE and should be a different issue from this one.

If there is a newline between def/class and the name, python sees it as a space if escaped with '\' but a syntax error if not.  IDLE effectively does the opposite.  The idprog in idlelib.colorizer uses \s, which matches a bare newline, among other things, but not 'backslash newline'.    I intend to replace '\s' with alternatives legal in this context.

def\
name ...  # Name should be blue, at least after multiline recolor.

def
name ...  # 'def\n' is error; name should not be blue ever.
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84564
2020-04-27 00:57:33terry.reedysettitle: IDLE: Undesired highlight -> IDLE: Wrong highlighting when \n follows def/class
stage: needs patch
messages: + msg367337
versions: + Python 3.7, Python 3.9
2020-04-25 03:32:57Alex-Python-Programmersetmessages: + msg367251
2020-04-25 03:29:57Alex-Python-Programmercreate