From e82663c25232be28cc768789ed7a1a586f20354c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sun, 29 Sep 2024 05:44:15 -0400 Subject: [PATCH] style: Use `any` or `all` instead of `for` loop (SIM110) (#4404) --- gui/wxpython/psmap/instructions.py | 5 +---- man/build_class_graphical.py | 5 +---- man/build_manual_gallery.py | 5 +---- pyproject.toml | 2 -- python/grass/pygrass/gis/region.py | 5 +---- python/grass/pygrass/raster/history.py | 5 +---- python/grass/pygrass/vector/table.py | 5 +---- python/grass/script/task.py | 6 +----- scripts/g.search.modules/g.search.modules.py | 5 +---- 9 files changed, 8 insertions(+), 35 deletions(-) diff --git a/gui/wxpython/psmap/instructions.py b/gui/wxpython/psmap/instructions.py index 8a535b96704..693e8024b57 100644 --- a/gui/wxpython/psmap/instructions.py +++ b/gui/wxpython/psmap/instructions.py @@ -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""" diff --git a/man/build_class_graphical.py b/man/build_class_graphical.py index 35b2a731cfe..554c950d3a8 100644 --- a/man/build_class_graphical.py +++ b/man/build_class_graphical.py @@ -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: diff --git a/man/build_manual_gallery.py b/man/build_manual_gallery.py index 3d381e27877..51a6fbcd312 100755 --- a/man/build_manual_gallery.py +++ b/man/build_manual_gallery.py @@ -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): diff --git a/pyproject.toml b/pyproject.toml index 3a6d449ec1d..9e430071afc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/python/grass/pygrass/gis/region.py b/python/grass/pygrass/gis/region.py index 98c75a15631..892a3664b49 100644 --- a/python/grass/pygrass/gis/region.py +++ b/python/grass/pygrass/gis/region.py @@ -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 diff --git a/python/grass/pygrass/raster/history.py b/python/grass/pygrass/raster/history.py index 5ec855cf1bb..8f227affabc 100644 --- a/python/grass/pygrass/raster/history.py +++ b/python/grass/pygrass/raster/history.py @@ -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() diff --git a/python/grass/pygrass/vector/table.py b/python/grass/pygrass/vector/table.py index 4b7e99c0a83..634c440a583 100644 --- a/python/grass/pygrass/vector/table.py +++ b/python/grass/pygrass/vector/table.py @@ -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 diff --git a/python/grass/script/task.py b/python/grass/script/task.py index 35234ba65e6..8e1f0a12844 100644 --- a/python/grass/script/task.py +++ b/python/grass/script/task.py @@ -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.""" diff --git a/scripts/g.search.modules/g.search.modules.py b/scripts/g.search.modules/g.search.modules.py index a3bab4325c2..574b8133a9e 100755 --- a/scripts/g.search.modules/g.search.modules.py +++ b/scripts/g.search.modules/g.search.modules.py @@ -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):