Skip to content

Commit 1557a30

Browse files
MAINT: apply ruff/flake8-simplify rule SIM110
SIM110 Use `return all(...)` instead of `for` loop SIM110 Use `return any(...)` instead of `for` loop
1 parent 4c3592d commit 1557a30

File tree

6 files changed

+9
-36
lines changed

6 files changed

+9
-36
lines changed

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/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.

numpy/lib/_iotools.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ def has_nested_fields(ndtype):
7777
False
7878
7979
"""
80-
for name in ndtype.names or ():
81-
if ndtype[name].names is not None:
82-
return True
83-
return False
80+
return any(ndtype[name].names is not None for name in ndtype.names or ())
8481

8582

8683
def flatten_dtype(ndtype, flatten_base=False):

0 commit comments

Comments
 (0)