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

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1 1 """Fixer for operator functions.
2 2
3 -operator.isCallable(obj) -> hasattr(obj, '__call__')
3 +operator.isCallable(obj) -> callable(obj)
4 4 operator.sequenceIncludes(obj) -> operator.contains(obj)
5 5 operator.isSequenceType(obj) -> isinstance(obj, collections.abc.Sequence)
6 6 operator.isMappingType(obj) -> isinstance(obj, collections.abc.Mapping)
@@ -49,11 +49,10 @@ def transform(self, node, results):
49 49 def _sequenceIncludes(self, node, results):
50 50 return self._handle_rename(node, results, "contains")
51 51
52 -@invocation("hasattr(%s, '__call__')")
52 +@invocation("callable(%s)")
53 53 def _isCallable(self, node, results):
54 54 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)
57 56
58 57 @invocation("operator.mul(%s)")
59 58 def _repeat(self, node, results):