Skip to content

Commit

Permalink
STY: Apply ruff/flake8-bugbear rule B004
Browse files Browse the repository at this point in the history
B004 Using `hasattr(x, "__call__")` to test if x is callable is unreliable.
     Use `callable(x)` for consistent results.
  • Loading branch information
DimitriPapadopoulos committed Sep 22, 2024
1 parent 4d1352a commit 24fcea3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions nipype/interfaces/utility/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(

super().__init__(**inputs)
if function:
if hasattr(function, "__call__"):
if callable(function):
try:
self.inputs.function_str = getsource(function)
except OSError:
Expand Down Expand Up @@ -103,7 +103,7 @@ def __init__(

def _set_function_string(self, obj, name, old, new):
if name == "function_str":
if hasattr(new, "__call__"):
if callable(new):
function_source = getsource(new)
fninfo = new.__code__
elif isinstance(new, (str, bytes)):
Expand Down
2 changes: 1 addition & 1 deletion nipype/pipeline/plugins/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, plugin_args=None):
if (
plugin_args
and "callable" in plugin_args
and hasattr(plugin_args["callable"], "__call__")
and callable(plugin_args["callable"])
):
self._callable = plugin_args["callable"]
else:
Expand Down

0 comments on commit 24fcea3

Please sign in to comment.