summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/fixes/fix_unicode.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/fixes/fix_unicode.py')
-rw-r--r--Lib/lib2to3/fixes/fix_unicode.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/Lib/lib2to3/fixes/fix_unicode.py b/Lib/lib2to3/fixes/fix_unicode.py
index 7f5cc80..393396e 100644
--- a/Lib/lib2to3/fixes/fix_unicode.py
+++ b/Lib/lib2to3/fixes/fix_unicode.py
@@ -6,23 +6,20 @@ import re
from ..pgen2 import token
from .. import fixer_base
+_mapping = {"unichr" : "chr", "unicode" : "str"}
+_literal_re = re.compile(r"[uU][rR]?[\'\"]")
+
class FixUnicode(fixer_base.BaseFix):
- PATTERN = "STRING | NAME<'unicode' | 'unichr'>"
+ PATTERN = "STRING | 'unicode' | 'unichr'"
def transform(self, node, results):
if node.type == token.NAME:
- if node.value == "unicode":
- new = node.clone()
- new.value = "str"
- return new
- if node.value == "unichr":
- new = node.clone()
- new.value = "chr"
- return new
- # XXX Warn when __unicode__ found?
+ new = node.clone()
+ new.value = _mapping[node.value]
+ return new
elif node.type == token.STRING:
- if re.match(r"[uU][rR]?[\'\"]", node.value):
+ if _literal_re.match(node.value):
new = node.clone()
new.value = new.value[1:]
return new