[Python-checkins] r83789 - sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py
benjamin.peterson
python-checkins at python.org
Sun Aug 8 00:45:14 CEST 2010
Author: benjamin.peterson
Date: Sun Aug 8 00:45:14 2010
New Revision: 83789
Log:
cleanup and use unicode consistently
Modified:
sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py Sun Aug 8 00:45:14 2010
@@ -10,8 +10,9 @@
"""
# Local imports
-from .. import fixer_base
-from ..fixer_util import Call, Name, String, touch_import
+from lib2to3 import fixer_base
+from lib2to3.fixer_util import Call, Name, String, touch_import
+
class FixOperator(fixer_base.BaseFix):
@@ -29,8 +30,9 @@
""" % dict(methods=methods, obj=obj)
def transform(self, node, results):
- if self._check_method(node, results):
- return self._get_method(results)(node, results)
+ method = self._check_method(node, results)
+ if method is not None:
+ return method(node, results)
def _sequenceIncludes(self, node, results):
"""operator.contains(%s)"""
@@ -52,15 +54,15 @@
def _isSequenceType(self, node, results):
"""isinstance(%s, collections.Sequence)"""
- return self._handle_type2abc(node, results, "collections", "Sequence")
+ return self._handle_type2abc(node, results, u"collections", u"Sequence")
def _isMappingType(self, node, results):
"""isinstance(%s, collections.Mapping)"""
- return self._handle_type2abc(node, results, "collections", "Mapping")
+ return self._handle_type2abc(node, results, u"collections", u"Mapping")
def _isNumberType(self, node, results):
"""isinstance(%s, numbers.Number)"""
- return self._handle_type2abc(node, results, "numbers", "Number")
+ return self._handle_type2abc(node, results, u"numbers", u"Number")
def _handle_rename(self, node, results, name):
method = results["method"][0]
@@ -69,19 +71,17 @@
def _handle_type2abc(self, node, results, module, abc):
touch_import(None, module, node)
- obj = results['obj']
- args = [obj.clone(), String(', ' + ".".join([module, abc]))]
- return Call(Name('isinstance'), args, prefix=node.get_prefix())
-
- def _get_method(self, results):
- return getattr(self, "_" + results["method"][0].value)
+ obj = results["obj"]
+ args = [obj.clone(), String(u", " + u".".join([module, abc]))]
+ return Call(Name(u"isinstance"), args, prefix=node.prefix)
def _check_method(self, node, results):
- method = self._get_method(results)
+ method = getattr(self, "_" + results["method"][0].value.encode("ascii"))
if callable(method):
if "module" in results:
- return True
+ return method
else:
- invocation_str = method.__doc__ % str(results["obj"])
- self.warning(node, "You should use '%s' here." % invocation_str)
- return False
+ sub = (unicode(results["obj"]),)
+ invocation_str = unicode(method.__doc__) % sub
+ self.warning(node, u"You should use '%s' here." % invocation_str)
+ return None
More information about the Python-checkins
mailing list