Skip to content

Commit 16cf84b

Browse files
bpo-33204: IDLE: consistently color invalid string prefixes (pythonGH-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 da58533) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent d918bbd commit 16cf84b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Lib/idlelib/colorizer.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def make_pat():
2121
# 1st 'file' colorized normal, 2nd as builtin, 3rd as string
2222
builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
2323
comment = any("COMMENT", [r"#[^\n]*"])
24-
stringprefix = r"(?i:\br|u|f|fr|rf|b|br|rb)?"
24+
stringprefix = r"(?i:r|u|f|fr|rf|b|br|rb)?"
2525
sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
2626
dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
2727
sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
@@ -265,11 +265,14 @@ def _color_delegator(parent): # htest #
265265
source = ("# Following has syntax errors\n"
266266
"if True: then int 1\nelif False: print 0\nelse: float(None)\n"
267267
"if iF + If + IF: 'keywork matching must respect case'\n"
268-
"# All valid prefixes for unicode and byte strings should be colored\n"
268+
"# All valid prefixes for unicode and byte strings should be colored.\n"
269269
"'x', '''x''', \"x\", \"\"\"x\"\"\"\n"
270-
"r'x', u'x', R'x', U'x', f'x', F'x', ur'is invalid'\n"
270+
"r'x', u'x', R'x', U'x', f'x', F'x'\n"
271271
"fr'x', Fr'x', fR'x', FR'x', rf'x', rF'x', Rf'x', RF'x'\n"
272-
"b'x',B'x', br'x',Br'x',bR'x',BR'x', rb'x'.rB'x',Rb'x',RB'x'\n")
272+
"b'x',B'x', br'x',Br'x',bR'x',BR'x', rb'x'.rB'x',Rb'x',RB'x'\n"
273+
"# Invalid combinations of legal characters should be half colored.\n"
274+
"ur'x', ru'x', uf'x', fu'x', UR'x', ufr'x', rfu'x', xf'x', fx'x'"
275+
)
273276
text = Text(top, background="white")
274277
text.pack(expand=1, fill="both")
275278
text.insert("insert", source)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
IDLE: consistently color invalid string prefixes. A 'u' string prefix cannot
2+
be paired with either 'r' or 'f'. Consistently color as much of the prefix,
3+
starting at the right, as is valid.

0 commit comments

Comments
 (0)