Index: lib2to3/tests/test_fixers.py =================================================================== --- lib2to3/tests/test_fixers.py (revision 77044) +++ lib2to3/tests/test_fixers.py (working copy) @@ -2725,16 +2725,16 @@ def test_prefix_preservation(self): b = """callable( x)""" - a = """hasattr( x, '__call__')""" + a = """from collections import Callable\nisinstance( x, Callable)""" self.check(b, a) b = """if callable(x): pass""" - a = """if hasattr(x, '__call__'): pass""" + a = """from collections import Callable\nif isinstance(x, Callable): pass""" self.check(b, a) def test_callable_call(self): b = """callable(x)""" - a = """hasattr(x, '__call__')""" + a = """from collections import Callable\nisinstance(x, Callable)""" self.check(b, a) def test_callable_should_not_change(self): Index: lib2to3/fixes/fix_callable.py =================================================================== --- lib2to3/fixes/fix_callable.py (revision 77044) +++ lib2to3/fixes/fix_callable.py (working copy) @@ -3,12 +3,12 @@ """Fixer for callable(). -This converts callable(obj) into hasattr(obj, '__call__').""" +This converts callable(obj) into isinstance(obj, collections.Callable).""" # Local imports from .. import pytree from .. import fixer_base -from ..fixer_util import Call, Name, String +from ..fixer_util import Call, Name, String, Attr, touch_import class FixCallable(fixer_base.BaseFix): @@ -25,7 +25,9 @@ """ def transform(self, node, results): - func = results["func"] + func = results['func'] - args = [func.clone(), String(u', '), String(u"'__call__'")] - return Call(Name(u"hasattr"), args, prefix=node.prefix) + touch_import(u'collections', u'Callable', node) + + args = [func.clone(), String(u', '), Name(u'Callable')] + return Call(Name(u'isinstance'), args, prefix=node.prefix)