Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
Better fixer for unicode invokes that disables accidental attribute r…
Browse files Browse the repository at this point in the history
…ewrites. This fixes #1
  • Loading branch information
mitsuhiko committed Mar 14, 2012
1 parent c1ff4ca commit 7b7ef03
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions libmodernize/fixes/fix_unicode.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@


class FixUnicode(fixer_base.BaseFix): class FixUnicode(fixer_base.BaseFix):
BM_compatible = True BM_compatible = True
PATTERN = "STRING | 'unicode'" PATTERN = """
STRING |
power< name='unicode'
trailer< '(' [any] ')' >
any *
>
"""


def transform(self, node, results): def transform(self, node, results):
if node.type == token.NAME: if 'name' in results:
touch_import(None, u'six', node) touch_import(None, u'six', node)
new = node.clone() name = results['name']
new.value = u'six.text_type' name.replace(Name(u'six.text_type', prefix=name.prefix))
return new
elif node.type == token.STRING and _literal_re.match(node.value): elif node.type == token.STRING and _literal_re.match(node.value):
touch_import(None, u'six', node) touch_import(None, u'six', node)
new = node.clone() new = node.clone()
Expand Down

0 comments on commit 7b7ef03

Please sign in to comment.