Skip to content

Commit 5e59676

Browse files
Issue #18037: Do not escape '\u' and '\U' in raw strings.
1 parent bcce125 commit 5e59676

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Lib/lib2to3/fixes/fix_unicode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def transform(self, node, results):
2828
return new
2929
elif node.type == token.STRING:
3030
val = node.value
31-
if (not self.unicode_literals and val[0] in 'rR\'"' and
32-
'\\' in val):
31+
if not self.unicode_literals and val[0] in '\'"' and '\\' in val:
3332
val = r'\\'.join([
3433
v.replace('\\u', r'\\u').replace('\\U', r'\\U')
3534
for v in val.split(r'\\')

Lib/lib2to3/tests/test_fixers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,7 @@ def test_native_literal_escape_u(self):
28302830
self.check(b, a)
28312831

28322832
b = r"""r'\\\u20ac\U0001d121\\u20ac'"""
2833-
a = r"""r'\\\\u20ac\\U0001d121\\u20ac'"""
2833+
a = r"""r'\\\u20ac\U0001d121\\u20ac'"""
28342834
self.check(b, a)
28352835

28362836
def test_bytes_literal_escape_u(self):

0 commit comments

Comments
 (0)