Skip to content

Commit 392baea

Browse files
authored
Merge pull request numpy#27293 from DimitriPapadopoulos/B
MAINT: Keep applying ruff/flake8-bugbear rules (B)
2 parents 09c2186 + 640e55b commit 392baea

File tree

14 files changed

+23
-23
lines changed

14 files changed

+23
-23
lines changed

benchmarks/benchmarks/bench_ma.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def time_methods_getitem(self, margs, msize):
213213
mdat = self.nmxs
214214
elif msize == 'big':
215215
mdat = self.nmxl
216-
getattr(mdat, '__getitem__')(margs)
216+
mdat.__getitem__(margs)
217217

218218

219219
class MAMethodSetItem(Benchmark):
@@ -235,7 +235,7 @@ def time_methods_setitem(self, margs, mset, msize):
235235
mdat = self.nmxs
236236
elif msize == 'big':
237237
mdat = self.nmxl
238-
getattr(mdat, '__setitem__')(margs, mset)
238+
mdat.__setitem__(margs, mset)
239239

240240

241241
class Where(Benchmark):

benchmarks/benchmarks/bench_ufunc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def time_methods_getitem(self, margs, msize):
258258
mdat = self.xs
259259
elif msize == 'big':
260260
mdat = self.xl
261-
getattr(mdat, '__getitem__')(margs)
261+
mdat.__getitem__(margs)
262262

263263

264264
class NDArraySetItem(Benchmark):

doc/neps/tools/build_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def nep_metadata():
3838

3939
# The title should be the first line after a line containing only
4040
# * or = signs.
41-
for i, line in enumerate(lines[:-1]):
41+
for line in lines[:-1]:
4242
chars = set(line.rstrip())
4343
if len(chars) == 1 and ("=" in chars or "*" in chars):
4444
break

numpy/_core/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ def astype(x, dtype, /, *, copy=True, device=None):
27052705

27062706
def extend_all(module):
27072707
existing = set(__all__)
2708-
mall = getattr(module, '__all__')
2708+
mall = module.__all__
27092709
for a in mall:
27102710
if a not in existing:
27112711
__all__.append(a)

numpy/_core/tests/test_deprecations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class TestMachAr(_DeprecationTestCase):
488488
warning_cls = DeprecationWarning
489489

490490
def test_deprecated_module(self):
491-
self.assert_deprecated(lambda: getattr(np._core, "MachAr"))
491+
self.assert_deprecated(lambda: np._core.MachAr)
492492

493493

494494
class TestQuantileInterpolationDeprecation(_DeprecationTestCase):

numpy/_core/tests/test_simd.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_operators_logical(self):
160160
assert vor == data_or
161161

162162
data_xor = [a ^ b for a, b in zip(data_a, data_b)]
163-
vxor = getattr(self, "xor")(vdata_a, vdata_b)
163+
vxor = self.xor(vdata_a, vdata_b)
164164
assert vxor == data_xor
165165

166166
vnot = getattr(self, "not")(vdata_a)
@@ -171,15 +171,15 @@ def test_operators_logical(self):
171171
return
172172

173173
data_andc = [(a & ~b) & 0xFF for a, b in zip(data_a, data_b)]
174-
vandc = getattr(self, "andc")(vdata_a, vdata_b)
174+
vandc = self.andc(vdata_a, vdata_b)
175175
assert data_andc == vandc
176176

177177
data_orc = [(a | ~b) & 0xFF for a, b in zip(data_a, data_b)]
178-
vorc = getattr(self, "orc")(vdata_a, vdata_b)
178+
vorc = self.orc(vdata_a, vdata_b)
179179
assert data_orc == vorc
180180

181181
data_xnor = [~(a ^ b) & 0xFF for a, b in zip(data_a, data_b)]
182-
vxnor = getattr(self, "xnor")(vdata_a, vdata_b)
182+
vxnor = self.xnor(vdata_a, vdata_b)
183183
assert data_xnor == vxnor
184184

185185
def test_tobits(self):
@@ -1072,7 +1072,7 @@ def test_operators_logical(self):
10721072
if self.sfx not in ("u8"):
10731073
return
10741074
data_andc = [a & ~b for a, b in zip(data_cast_a, data_cast_b)]
1075-
vandc = cast(getattr(self, "andc")(vdata_a, vdata_b))
1075+
vandc = cast(self.andc(vdata_a, vdata_b))
10761076
assert vandc == data_andc
10771077

10781078
@pytest.mark.parametrize("intrin", ["any", "all"])

numpy/_core/tests/test_ufunc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
UNARY_OBJECT_UFUNCS = [uf for uf in UNARY_UFUNCS if "O->O" in uf.types]
2828

2929
# Remove functions that do not support `floats`
30-
UNARY_OBJECT_UFUNCS.remove(getattr(np, 'bitwise_count'))
30+
UNARY_OBJECT_UFUNCS.remove(np.bitwise_count)
3131

3232

3333
class TestUfuncKwargs:

numpy/_core/tests/test_umath_accuracy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
UNARY_OBJECT_UFUNCS = [uf for uf in UNARY_UFUNCS if "O->O" in uf.types]
1414

1515
# Remove functions that do not support `floats`
16-
UNARY_OBJECT_UFUNCS.remove(getattr(np, 'invert'))
17-
UNARY_OBJECT_UFUNCS.remove(getattr(np, 'bitwise_count'))
16+
UNARY_OBJECT_UFUNCS.remove(np.invert)
17+
UNARY_OBJECT_UFUNCS.remove(np.bitwise_count)
1818

1919
IS_AVX = __cpu_features__.get('AVX512F', False) or \
2020
(__cpu_features__.get('FMA3', False) and __cpu_features__.get('AVX2', False))

numpy/f2py/f2py2e.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def __call__(self, parser, namespace, values, option_string=None):
547547
include_paths_set.update(values.split(':'))
548548
else:
549549
include_paths_set.add(values)
550-
setattr(namespace, 'include_paths', list(include_paths_set))
550+
namespace.include_paths = list(include_paths_set)
551551

552552
def f2py_parser():
553553
parser = argparse.ArgumentParser(add_help=False)

numpy/f2py/tests/test_array_from_pyobj.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ def _init(self, name):
191191

192192
if self.NAME == 'CHARACTER':
193193
info = c_names_dict[self.NAME]
194-
self.type_num = getattr(wrap, 'NPY_STRING')
194+
self.type_num = wrap.NPY_STRING
195195
self.elsize = 1
196196
self.dtype = np.dtype('c')
197197
elif self.NAME.startswith('STRING'):
198198
info = c_names_dict[self.NAME[:6]]
199-
self.type_num = getattr(wrap, 'NPY_STRING')
199+
self.type_num = wrap.NPY_STRING
200200
self.elsize = int(self.NAME[6:] or 0)
201201
self.dtype = np.dtype(f'S{self.elsize}')
202202
else:

numpy/f2py/tests/test_callback.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def callback(code):
9494
else:
9595
return 1
9696

97-
f = getattr(self.module, "string_callback")
97+
f = self.module.string_callback
9898
r = f(callback)
9999
assert r == 0
100100

@@ -115,7 +115,7 @@ def callback(cu, lencu):
115115
return 3
116116
return 0
117117

118-
f = getattr(self.module, "string_callback_array")
118+
f = self.module.string_callback_array
119119
for cu in [cu1, cu2, cu3]:
120120
res = f(callback, cu, cu.size)
121121
assert res == 0

numpy/f2py/tests/test_docs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class TestDocAdvanced(util.F2PyTest):
3434
_path('ftype.f')]
3535

3636
def test_asterisk1(self):
37-
foo = getattr(self.module, 'foo1')
37+
foo = self.module.foo1
3838
assert_equal(foo(), b'123456789A12')
3939

4040
def test_asterisk2(self):
41-
foo = getattr(self.module, 'foo2')
41+
foo = self.module.foo2
4242
assert_equal(foo(2), b'12')
4343
assert_equal(foo(12), b'123456789A12')
4444
assert_equal(foo(20), b'123456789A123456789B')

numpy/random/tests/test_extending.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_cython(tmp_path):
8383
g = glob.glob(str(target_dir / "*" / "extending.pyx.c"))
8484
with open(g[0]) as fid:
8585
txt_to_find = 'NumPy API declarations from "numpy/__init__'
86-
for i, line in enumerate(fid):
86+
for line in fid:
8787
if txt_to_find in line:
8888
break
8989
else:

tools/c_coverage/c_coverage_report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def collect_stats(files, fd, pattern):
122122

123123
current_file = None
124124
current_function = None
125-
for i, line in enumerate(fd):
125+
for line in fd:
126126
if re.match("f[lie]=.+", line):
127127
path = line.split('=', 2)[1].strip()
128128
if os.path.exists(path) and re.search(pattern, path):

0 commit comments

Comments
 (0)