Repository: asottile/pyupgrade

Issue:
Possible bug `"/\N{SNOWMAN}".encode("utf-8")` -> `br"/\N{SNOWMAN}"`
Taken from running pyupgrade on Werkzeug's test suite. I think this is the wrong behavior as `"/\N{SNOWMAN}".encode("utf-8")` != `br"/\N{SNOWMAN}"` and therefore this tools should not convert the former to the latter.

Discussion:

Patch:
diff --git a/pyupgrade.py b/pyupgrade.py
index 25d7e99..1d0636f 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -656,6 +656,7 @@ def _fix_encode_to_binary(tokens, i):  # type: (List[Token], int) -> None
                 not _is_ascii(rest) or
                 '\\u' in escapes or
                 '\\U' in escapes or
+                '\\N' in escapes or
                 ('\\x' in escapes and not latin1_ok) or
                 'f' in prefix.lower()
         ):


Test patch:
diff --git a/tests/binary_literals_test.py b/tests/binary_literals_test.py
index 885d122..1c543fd 100644
--- a/tests/binary_literals_test.py
+++ b/tests/binary_literals_test.py
@@ -13,6 +13,7 @@ from pyupgrade import _fix_tokens
         '"☃".encode("UTF-8")',
         '"\\u2603".encode("UTF-8")',
         '"\\U0001f643".encode("UTF-8")',
+        '"\\N{SNOWMAN}".encode("UTF-8")',
         '"\\xa0".encode("UTF-8")',
         # not byte literal compatible
         '"y".encode("utf16")',