================================== =============================================
From To
================================== =============================================
- ``operator.isCallable(obj)`` ``hasattr(obj, '__call__')``
+ ``operator.isCallable(obj)`` ``callable(obj)``
``operator.sequenceIncludes(obj)`` ``operator.contains(obj)``
``operator.isSequenceType(obj)`` ``isinstance(obj, collections.abc.Sequence)``
``operator.isMappingType(obj)`` ``isinstance(obj, collections.abc.Mapping)``
"""Fixer for operator functions.
-operator.isCallable(obj) -> hasattr(obj, '__call__')
+operator.isCallable(obj) -> callable(obj)
operator.sequenceIncludes(obj) -> operator.contains(obj)
operator.isSequenceType(obj) -> isinstance(obj, collections.abc.Sequence)
operator.isMappingType(obj) -> isinstance(obj, collections.abc.Mapping)
def _sequenceIncludes(self, node, results):
return self._handle_rename(node, results, "contains")
- @invocation("hasattr(%s, '__call__')")
+ @invocation("callable(%s)")
def _isCallable(self, node, results):
obj = results["obj"]
- args = [obj.clone(), String(", "), String("'__call__'")]
- return Call(Name("hasattr"), args, prefix=node.prefix)
+ return Call(Name("callable"), [obj.clone()], prefix=node.prefix)
@invocation("operator.mul(%s)")
def _repeat(self, node, results):
def test_operator_isCallable(self):
b = "operator.isCallable(x)"
- a = "hasattr(x, '__call__')"
+ a = "callable(x)"
self.check(b, a)
def test_operator_sequenceIncludes(self):
def test_bare_isCallable(self):
s = "isCallable(x)"
- t = "You should use 'hasattr(x, '__call__')' here."
+ t = "You should use 'callable(x)' here."
self.warns_unchanged(s, t)
def test_bare_sequenceIncludes(self):