Permalink
Browse files

Better fixer for unicode invokes that disables accidental attribute r…

…ewrites. This fixes #1
  • Loading branch information...
1 parent c1ff4ca commit 7b7ef0304a40ecfe21cd70feaa971210f560ad17 @mitsuhiko committed Mar 14, 2012
Showing with 10 additions and 5 deletions.
  1. +10 −5 libmodernize/fixes/fix_unicode.py
@@ -8,14 +8,19 @@
class FixUnicode(fixer_base.BaseFix):
BM_compatible = True
- PATTERN = "STRING | 'unicode'"
+ PATTERN = """
+ STRING |
+ power< name='unicode'
+ trailer< '(' [any] ')' >
+ any *
+ >
+ """
def transform(self, node, results):
- if node.type == token.NAME:
+ if 'name' in results:
touch_import(None, u'six', node)
- new = node.clone()
- new.value = u'six.text_type'
- return new
+ name = results['name']
+ name.replace(Name(u'six.text_type', prefix=name.prefix))
elif node.type == token.STRING and _literal_re.match(node.value):
touch_import(None, u'six', node)
new = node.clone()

0 comments on commit 7b7ef03

Please sign in to comment.