[Python-checkins] r75088 - in sandbox/trunk/2to3/lib2to3: fixes/fix_callable.py tests/test_fixers.py
benjamin.peterson
python-checkins at python.org
Sun Sep 27 18:25:22 CEST 2009
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):
More information about the Python-checkins
mailing list