[Python-checkins] r75213 - in sandbox/trunk/2to3/lib2to3: fixes/fix_callable.py tests/test_fixers.py

benjamin.peterson python-checkins at python.org
Sat Oct 3 17:09:46 CEST 2009


Author: benjamin.peterson
Date: Sat Oct  3 17:09:46 2009
New Revision: 75213

Log:
revert 75212; it's not correct

People can use isinstance(x, collections.Callable) if they expect objects with
__call__ in their instance dictionaries.


Modified:
   sandbox/trunk/2to3/lib2to3/fixes/fix_callable.py
   sandbox/trunk/2to3/lib2to3/tests/test_fixers.py

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_callable.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_callable.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_callable.py	Sat Oct  3 17:09:46 2009
@@ -3,7 +3,7 @@
 
 """Fixer for callable().
 
-This converts callable(obj) into hasattr(type(obj), '__call__')."""
+This converts callable(obj) into hasattr(obj, '__call__')."""
 
 # Local imports
 from .. import pytree
@@ -27,8 +27,5 @@
     def transform(self, node, results):
         func = results["func"]
 
-        new_func = func.clone()
-        new_func.prefix = u""
-        type_call = Call(Name(u"type"), [new_func], prefix=func.prefix)
-        args = [type_call, String(u', '), String(u"'__call__'")]
+        args = [func.clone(), String(u', '), String(u"'__call__'")]
         return Call(Name(u"hasattr"), args, prefix=node.prefix)

Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	Sat Oct  3 17:09:46 2009
@@ -2710,16 +2710,16 @@
 
     def test_prefix_preservation(self):
         b = """callable(    x)"""
-        a = """hasattr(    type(x), '__call__')"""
+        a = """hasattr(    x, '__call__')"""
         self.check(b, a)
 
         b = """if     callable(x): pass"""
-        a = """if     hasattr(type(x), '__call__'): pass"""
+        a = """if     hasattr(x, '__call__'): pass"""
         self.check(b, a)
 
     def test_callable_call(self):
         b = """callable(x)"""
-        a = """hasattr(type(x), '__call__')"""
+        a = """hasattr(x, '__call__')"""
         self.check(b, a)
 
     def test_callable_should_not_change(self):


More information about the Python-checkins mailing list