![](https://secure.gravatar.com/avatar/8ac615df352a970211b0e3d94a307c6d.jpg?s=120&d=mm&r=g)
Author: benjamin.peterson Date: Sun Sep 27 18:25:21 2009 New Revision: 75088 Log: look on the type only for __call__ 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 Sun Sep 27 18:25:21 2009 @@ -3,7 +3,7 @@ """Fixer for callable(). -This converts callable(obj) into hasattr(obj, '__call__').""" +This converts callable(obj) into hasattr(type(obj), '__call__').""" # Local imports from .. import pytree @@ -27,5 +27,8 @@ def transform(self, node, results): func = results["func"] - args = [func.clone(), String(u', '), String(u"'__call__'")] + 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__'")] 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 Sun Sep 27 18:25:21 2009 @@ -2710,16 +2710,16 @@ def test_prefix_preservation(self): b = """callable( x)""" - a = """hasattr( x, '__call__')""" + a = """hasattr( type(x), '__call__')""" self.check(b, a) b = """if callable(x): pass""" - a = """if hasattr(x, '__call__'): pass""" + a = """if hasattr(type(x), '__call__'): pass""" self.check(b, a) def test_callable_call(self): b = """callable(x)""" - a = """hasattr(x, '__call__')""" + a = """hasattr(type(x), '__call__')""" self.check(b, a) def test_callable_should_not_change(self):
participants (1)
-
benjamin.peterson