Terry J. Reedy added the comment:

start with no indent: orange
add any indent: turns purple
delete indent: back to orange
same in edit window
change does not happen with other keywords (or 3.x)

The underlying cause is that 'print' is both in keyword.kwlist and in module 
__builtin__ (for use when the print_function future import suppresses 
recognition of print as keyword). Hence it is in both the partial regexes that 
get concatenated together at the top of ColorDelegator.py and used with .match 
on lines 201 and 232.

The proximal cause is that .match in recolorize_main, 201, 232 gives different 
answers without or with a leading space.

import keyword
import __builtin__
import re

def any(name, alternates):
    "Return a named group pattern matching list of alternates."
    return "(?P<%s>" % name + "|".join(alternates) + ")"

kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
builtinlist = [str(name) for name in dir(__builtin__)]
builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"

prog = re.compile(kw + "|" + builtin , re.S)
print(prog.match('print').groupdict().items())
print(prog.match(' print').groupdict().items())
>>> 
[('BUILTIN', None), ('KEYWORD', 'print')]
[('BUILTIN', 'print'), ('KEYWORD', None)]

The prefix [^.'\"\\#] added to builtin but not kw matches a space. Removing 
'print' from builtinlist prevents it from matching as a builtin. I think this 
is the right thing to do since Idle cannot know how 'print' will be 
interpreted, so should use the keyword default. 

  builtinlist.remove('print')

I am not going to write a test for this.

----------
assignee:  -> terry.reedy
keywords: +patch
nosy: +terry.reedy
stage:  -> needs patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to