Skip to content

Commit

Permalink
style: Use any or all instead of for loop (SIM110) (#4404)
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix committed Sep 29, 2024
1 parent 16c87b1 commit e82663c
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 35 deletions.
5 changes: 1 addition & 4 deletions gui/wxpython/psmap/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ def __getitem__(self, id):

def __contains__(self, id):
"""Test if instruction is included"""
for each in self.instruction:
if each.id == id:
return True
return False
return any(each.id == id for each in self.instruction)

def __delitem__(self, id):
"""Delete instruction"""
Expand Down
5 changes: 1 addition & 4 deletions man/build_class_graphical.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@


def file_matches(filename, patterns):
for pattern in patterns:
if fnmatch.fnmatch(filename, pattern):
return True
return False
return any(fnmatch.fnmatch(filename, pattern) for pattern in patterns)


def starts_with_module(string, module) -> bool:
Expand Down
5 changes: 1 addition & 4 deletions man/build_manual_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ def img_in_html(filename, imagename) -> bool:


def file_matches(filename, patterns):
for pattern in patterns:
if fnmatch.fnmatch(filename, pattern):
return True
return False
return any(fnmatch.fnmatch(filename, pattern) for pattern in patterns)


def get_files(directory, patterns, exclude_patterns):
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ ignore = [
"SIM102", # collapsible-if
"SIM105", # suppressible-exception
"SIM108", # if-else-block-instead-of-if-exp
"SIM109", # compare-with-tuple
"SIM110", # reimplemented-builtin
"SIM113", # enumerate-for-loop
"SIM116", # if-else-block-instead-of-dict-lookup
"SIM118", # in-dict-keys
Expand Down
5 changes: 1 addition & 4 deletions python/grass/pygrass/gis/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,7 @@ def __eq__(self, reg):
"zone",
"proj",
]
for attr in attrs:
if getattr(self, attr) != getattr(reg, attr):
return False
return True
return all(getattr(self, attr) == getattr(reg, attr) for attr in attrs)

def __ne__(self, other):
return not self == other
Expand Down
5 changes: 1 addition & 4 deletions python/grass/pygrass/raster/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ def __del__(self):
"""Rast_free_history"""

def __eq__(self, hist):
for attr in self.attrs:
if getattr(self, attr) != getattr(hist, attr):
return False
return True
return all(getattr(self, attr) == getattr(hist, attr) for attr in self.attrs)

def __len__(self):
return self.length()
Expand Down
5 changes: 1 addition & 4 deletions python/grass/pygrass/vector/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,7 @@ def __eq__(self, link):
False
"""
attrs = ["layer", "name", "table_name", "key", "driver"]
for attr in attrs:
if getattr(self, attr) != getattr(link, attr):
return False
return True
return all(getattr(self, attr) == getattr(link, attr) for attr in attrs)

def __ne__(self, other):
return not self == other
Expand Down
6 changes: 1 addition & 5 deletions python/grass/script/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,7 @@ def get_options(self):

def has_required(self):
"""Check if command has at least one required parameter"""
for p in self.params:
if p.get("required", False):
return True

return False
return any(p.get("required", False) for p in self.params)

def set_param(self, aParam, aValue, element="value"):
"""Set param value/values."""
Expand Down
5 changes: 1 addition & 4 deletions scripts/g.search.modules/g.search.modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,7 @@ def _exact_search(keyword, module_keywords):
:param module_keywords: comma separated list of keywords
"""
module_keywords = module_keywords.split(",")
for current in module_keywords:
if keyword == current:
return True
return False
return keyword in module_keywords


def _manpage_search(pattern, name):
Expand Down

0 comments on commit e82663c

Please sign in to comment.