Skip to content

Commit d7ce405

Browse files
Apply ruff/flake8-bugbear rule B004
B004 Using `hasattr(x, "__call__")` to test if x is callable is unreliable. Use `callable(x)` for consistent results.
1 parent abeca76 commit d7ce405

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

numpy/lib/_iotools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def upgrade_mapper(cls, func, default=None):
561561
>>> StringConverter.upgrade_mapper(dateparser, default=defaultdate)
562562
"""
563563
# Func is a single functions
564-
if hasattr(func, '__call__'):
564+
if callable(func):
565565
cls._mapper.insert(-1, (cls._getsubdtype(default), func, default))
566566
return
567567
elif hasattr(func, '__iter__'):
@@ -608,7 +608,7 @@ def __init__(self, dtype_or_func=None, default=None, missing_values=None,
608608
dtype = np.dtype(dtype_or_func)
609609
except TypeError:
610610
# dtype_or_func must be a function, then
611-
if not hasattr(dtype_or_func, '__call__'):
611+
if not callable(dtype_or_func):
612612
errmsg = ("The input argument `dtype` is neither a"
613613
" function nor a dtype (got '%s' instead)")
614614
raise TypeError(errmsg % type(dtype_or_func))

0 commit comments

Comments
 (0)