[Python-checkins] bpo-33204: IDLE: consistently color invalid string prefixes (GH-6344)

Miss Islington (bot) webhook-mailer at python.org
Mon Apr 2 02:33:28 EDT 2018


https://github.com/python/cpython/commit/16cf84b4fbe78f9d876e0335f33459f1b92b7bf0
commit: 16cf84b4fbe78f9d876e0335f33459f1b92b7bf0
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-04-01T23:33:25-07:00
summary:

bpo-33204: IDLE: consistently color invalid string prefixes (GH-6344)


A 'u' string prefix cannot be paired with either 'r' or 'f'.  Consistently
color as much of the prefix, starting at the right, as is valid.
(cherry picked from commit da58533ac67b01ce8f6466e6f03ff6b8b3bb04d5)

Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>

files:
A Misc/NEWS.d/next/IDLE/2018-04-02-00-28-13.bpo-33204.NBsuIv.rst
M Lib/idlelib/colorizer.py

diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py
index ff4084528804..f835e5874b7e 100644
--- a/Lib/idlelib/colorizer.py
+++ b/Lib/idlelib/colorizer.py
@@ -21,7 +21,7 @@ def make_pat():
     # 1st 'file' colorized normal, 2nd as builtin, 3rd as string
     builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
     comment = any("COMMENT", [r"#[^\n]*"])
-    stringprefix = r"(?i:\br|u|f|fr|rf|b|br|rb)?"
+    stringprefix = r"(?i:r|u|f|fr|rf|b|br|rb)?"
     sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
     dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
     sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
@@ -265,11 +265,14 @@ def _color_delegator(parent):  # htest #
     source = ("# Following has syntax errors\n"
         "if True: then int 1\nelif False: print 0\nelse: float(None)\n"
         "if iF + If + IF: 'keywork matching must respect case'\n"
-        "# All valid prefixes for unicode and byte strings should be colored\n"
+        "# All valid prefixes for unicode and byte strings should be colored.\n"
         "'x', '''x''', \"x\", \"\"\"x\"\"\"\n"
-        "r'x', u'x', R'x', U'x', f'x', F'x', ur'is invalid'\n"
+        "r'x', u'x', R'x', U'x', f'x', F'x'\n"
         "fr'x', Fr'x', fR'x', FR'x', rf'x', rF'x', Rf'x', RF'x'\n"
-        "b'x',B'x', br'x',Br'x',bR'x',BR'x', rb'x'.rB'x',Rb'x',RB'x'\n")
+        "b'x',B'x', br'x',Br'x',bR'x',BR'x', rb'x'.rB'x',Rb'x',RB'x'\n"
+        "# Invalid combinations of legal characters should be half colored.\n"
+        "ur'x', ru'x', uf'x', fu'x', UR'x', ufr'x', rfu'x', xf'x', fx'x'"
+        )
     text = Text(top, background="white")
     text.pack(expand=1, fill="both")
     text.insert("insert", source)
diff --git a/Misc/NEWS.d/next/IDLE/2018-04-02-00-28-13.bpo-33204.NBsuIv.rst b/Misc/NEWS.d/next/IDLE/2018-04-02-00-28-13.bpo-33204.NBsuIv.rst
new file mode 100644
index 000000000000..d5d769846eb1
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2018-04-02-00-28-13.bpo-33204.NBsuIv.rst
@@ -0,0 +1,3 @@
+IDLE: consistently color invalid string prefixes. A 'u' string prefix cannot
+be paired with either 'r' or 'f'.  Consistently color as much of the prefix,
+starting at the right, as is valid.



More information about the Python-checkins mailing list