Skip to content

Commit fe52670

Browse files
authored
Merge pull request numpy#26902 from DimitriPapadopoulos/B
Apply some ruff/flake8-bugbear rules (B004 and B005)
2 parents 7bff275 + a360364 commit fe52670

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

numpy/f2py/crackfortran.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,7 @@ def get_parameters(vars, global_params={}):
25392539
outmess(f'get_parameters[TODO]: '
25402540
f'implement evaluation of complex expression {v}\n')
25412541

2542-
dimspec = ([s.lstrip('dimension').strip()
2542+
dimspec = ([s.removeprefix('dimension').strip()
25432543
for s in vars[n]['attrspec']
25442544
if s.startswith('dimension')] or [None])[0]
25452545

numpy/lib/_datasource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def _sanitize_relative_path(self, path):
420420
last = path
421421
# Note: os.path.join treats '/' as os.sep on Windows
422422
path = path.lstrip(os.sep).lstrip('/')
423-
path = path.lstrip(os.pardir).lstrip('..')
423+
path = path.lstrip(os.pardir).removeprefix('..')
424424
drive, path = os.path.splitdrive(path) # for Windows
425425
return path
426426

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))

numpy/lib/tests/test_loadtxt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ def test_str_dtype_unit_discovery_with_converter():
10041004
expected = np.array(
10051005
["spam-a-lot"] * 60000 + ["tis_but_a_scratch"], dtype="U17"
10061006
)
1007-
conv = lambda s: s.strip("XXX")
1007+
conv = lambda s: s.removeprefix("XXX")
10081008

10091009
# file-like path
10101010
txt = StringIO("\n".join(data))

0 commit comments

Comments
 (0)