Repository: asottile/pyupgrade

Issue:
raw-string rewrite with escaped newlines incorrect
```console
$ cat t.py
x = """\
foo\s
"""
print(x)
$ python t.py 
foo\s

$ pyupgrade t.py
Rewriting t.py
$ cat t.py
x = r"""\
foo\s
"""
print(x)
$ python t.py
\
foo\s

```

Discussion:

Patch:
diff --git a/pyupgrade.py b/pyupgrade.py
index cdf8c14..f41fa13 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -429,7 +429,7 @@ ESCAPE_STARTS = frozenset((
     'N', 'u', 'U',
 ))
 ESCAPE_STARTS_BYTES = ESCAPE_STARTS - frozenset(('N', 'u', 'U'))
-ESCAPE_RE = re.compile(r'\\.')
+ESCAPE_RE = re.compile(r'\\.', re.DOTALL)
 
 
 def _fix_escape_sequences(contents_text):


Test patch:
diff --git a/tests/pyupgrade_test.py b/tests/pyupgrade_test.py
index 183903f..685571c 100644
--- a/tests/pyupgrade_test.py
+++ b/tests/pyupgrade_test.py
@@ -370,6 +370,10 @@ def test_fix_escape_sequences_noop(s):
         (r'"\8"', r'r"\8"'), (r'"\9"', r'r"\9"'),
         # explicit byte strings should not honor string-specific escapes
         ('b"\\u2603"', 'br"\\u2603"'),
+        # do not make a raw string for escaped newlines
+        ('"""\\\n\\q"""', '"""\\\n\\\\q"""'),
+        ('"""\\\r\n\\q"""', '"""\\\r\n\\\\q"""'),
+        ('"""\\\r\\q"""', '"""\\\r\\\\q"""'),
     ),
 )
 def test_fix_escape_sequences(s, expected):