bpo-32046: Update 2to3 when converts operator.isCallable(obj). (#4417) · python/cpython@a489599

Original file line numberDiff line numberDiff line change

@@ -1,6 +1,6 @@

11

"""Fixer for operator functions.

22
3-

operator.isCallable(obj) -> hasattr(obj, '__call__')

3+

operator.isCallable(obj) -> callable(obj)

44

operator.sequenceIncludes(obj) -> operator.contains(obj)

55

operator.isSequenceType(obj) -> isinstance(obj, collections.abc.Sequence)

66

operator.isMappingType(obj) -> isinstance(obj, collections.abc.Mapping)

@@ -49,11 +49,10 @@ def transform(self, node, results):

4949

def _sequenceIncludes(self, node, results):

5050

return self._handle_rename(node, results, "contains")

5151
52-

@invocation("hasattr(%s, '__call__')")

52+

@invocation("callable(%s)")

5353

def _isCallable(self, node, results):

5454

obj = results["obj"]

55-

args = [obj.clone(), String(", "), String("'__call__'")]

56-

return Call(Name("hasattr"), args, prefix=node.prefix)

55+

return Call(Name("callable"), [obj.clone()], prefix=node.prefix)

5756
5857

@invocation("operator.mul(%s)")

5958

def _repeat(self, node, results):