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.

Author terry.reedy
Recipients rhettinger, terry.reedy
Date 2014-03-29.07:31:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1396078297.68.0.0837840124813.issue21029@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-03-29 07:31:37terry.reedysetrecipients: + terry.reedy, rhettinger
2014-03-29 07:31:37terry.reedysetmessageid: <1396078297.68.0.0837840124813.issue21029@psf.upfronthosting.co.za>
2014-03-29 07:31:37terry.reedylinkissue21029 messages
2014-03-29 07:31:36terry.reedycreate