Skip to content

Commit 4be1b63

Browse files
authored
Merge pull request numpy#26879 from DimitriPapadopoulos/SIM
MAINT: start applying ruff/flake8-simplify rules (SIM)
2 parents 5052807 + 8111485 commit 4be1b63

File tree

16 files changed

+50
-93
lines changed

16 files changed

+50
-93
lines changed

numpy/_core/_dtype.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ def _is_packed(dtype):
277277
if align:
278278
total_offset = _aligned_offset(total_offset, max_alignment)
279279

280-
if total_offset != dtype.itemsize:
281-
return False
282-
return True
280+
return total_offset == dtype.itemsize
283281

284282

285283
def _struct_list_str(dtype):

numpy/_core/code_generators/generate_umath.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,9 @@ def make_arrays(funcdict):
13761376
funclist = []
13771377
datalist = []
13781378
siglist = []
1379-
k = 0
13801379
sub = 0
13811380

1382-
for t in uf.type_descriptions:
1381+
for k, t in enumerate(uf.type_descriptions):
13831382
cfunc_alias = t.cfunc_alias if t.cfunc_alias else name
13841383
cfunc_fname = None
13851384
if t.func_data is FullTypeDescr:
@@ -1439,8 +1438,6 @@ def make_arrays(funcdict):
14391438
for x in t.in_ + t.out:
14401439
siglist.append('NPY_%s' % (english_upper(chartoname[x]),))
14411440

1442-
k += 1
1443-
14441441
if funclist or siglist or datalist:
14451442
funcnames = ', '.join(funclist)
14461443
signames = ', '.join(siglist)

numpy/_core/numerictypes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,10 @@ def issctype(rep):
223223
return False
224224
try:
225225
res = obj2sctype(rep)
226-
if res and res != object_:
227-
return True
228-
return False
229226
except Exception:
230227
return False
231-
228+
else:
229+
return res and res != object_
232230

233231
@set_module('numpy')
234232
def obj2sctype(rep, default=None):

numpy/_core/tests/test_cpu_features.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ def cpu_have(self, feature_name):
8585
map_names = self.features_map.get(feature_name, feature_name)
8686
if isinstance(map_names, str):
8787
return map_names in self.features_flags
88-
for f in map_names:
89-
if f in self.features_flags:
90-
return True
91-
return False
88+
return any(f in self.features_flags for f in map_names)
9289

9390
def load_flags_cpuinfo(self, magic_key):
9491
self.features_flags = self.get_cpuinfo_item(magic_key)

numpy/distutils/extension.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,9 @@ def __init__(
9393
return
9494

9595
def has_cxx_sources(self):
96-
for source in self.sources:
97-
if cxx_ext_re(str(source)):
98-
return True
99-
return False
96+
return any(cxx_ext_re(str(source)) for source in self.sources)
10097

10198
def has_f2py_sources(self):
102-
for source in self.sources:
103-
if fortran_pyf_ext_re(source):
104-
return True
105-
return False
99+
return any(fortran_pyf_ext_re(source) for source in self.sources)
106100

107101
# class Extension

numpy/distutils/misc_util.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,7 @@ def is_string(s):
489489

490490
def all_strings(lst):
491491
"""Return True if all items in lst are string objects. """
492-
for item in lst:
493-
if not is_string(item):
494-
return False
495-
return True
492+
return all(is_string(item) for item in lst)
496493

497494
def is_sequence(seq):
498495
if is_string(seq):
@@ -527,17 +524,11 @@ def get_language(sources):
527524

528525
def has_f_sources(sources):
529526
"""Return True if sources contains Fortran files """
530-
for source in sources:
531-
if fortran_ext_match(source):
532-
return True
533-
return False
527+
return any(fortran_ext_match(source) for source in sources)
534528

535529
def has_cxx_sources(sources):
536530
"""Return True if sources contains C++ files """
537-
for source in sources:
538-
if cxx_ext_match(source):
539-
return True
540-
return False
531+
return any(cxx_ext_match(source) for source in sources)
541532

542533
def filter_sources(sources):
543534
"""Return four lists of filenames containing

numpy/f2py/tests/test_array_from_pyobj.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ def __repr__(self):
9090
return "Intent(%r)" % (self.intent_list)
9191

9292
def is_intent(self, *names):
93-
for name in names:
94-
if name not in self.intent_list:
95-
return False
96-
return True
93+
return all(name in self.intent_list for name in names)
9794

9895
def is_intent_exact(self, *names):
9996
return len(self.intent_list) == len(names) and self.is_intent(*names)

numpy/f2py/tests/util.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ def check_language(lang, code_snippet=None):
220220
cwd=tmpdir,
221221
capture_output=True,
222222
)
223-
if runmeson.returncode == 0:
224-
return True
225-
else:
226-
return False
223+
return runmeson.returncode == 0
227224
finally:
228225
shutil.rmtree(tmpdir)
229226
return False

numpy/lib/_arraypad_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ def pad(array, pad_width, mode='constant', **kwargs):
860860

861861
elif mode in {"reflect", "symmetric"}:
862862
method = kwargs.get("reflect_type", "even")
863-
include_edge = True if mode == "symmetric" else False
863+
include_edge = mode == "symmetric"
864864
for axis, (left_index, right_index) in zip(axes, pad_width):
865865
if array.shape[axis] == 1 and (left_index > 0 or right_index > 0):
866866
# Extending singleton dimension for 'reflect' is legacy

numpy/lib/_datasource.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,7 @@ def _iswritemode(self, mode):
271271

272272
# Currently only used to test the bz2 files.
273273
_writemodes = ("w", "+")
274-
for c in mode:
275-
if c in _writemodes:
276-
return True
277-
return False
274+
return any(c in _writemodes for c in mode)
278275

279276
def _splitzipext(self, filename):
280277
"""Split zip extension from filename and return filename.

0 commit comments

Comments
 (0)