Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Use any or all instead of for loop (SIM110) #4404

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
ninsbl marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -250,8 +250,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
"SIM114", # if-with-same-arms
"SIM116", # if-else-block-instead-of-dict-lookup
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 @@ -311,10 +311,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 any(keyword == current for current in module_keywords)
echoix marked this conversation as resolved.
Show resolved Hide resolved


def _manpage_search(pattern, name):
Expand Down
Loading