Skip to content

Commit

Permalink
style: Fix R1703: The if statement can be replaced with 'var = bool(t…
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix committed Dec 27, 2024
1 parent 306d596 commit 60d91fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
5 changes: 1 addition & 4 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,10 +1802,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
value = self._getValue(p)

if prompt == "layer":
if p.get("element", "layer") == "layer_all":
all = True
else:
all = False
all = bool(p.get("element", "layer") == "layer_all")
if p.get("age", "old") == "old":
win = gselect.LayerSelect(
parent=which_panel, all=all, default=p["default"]
Expand Down
8 changes: 3 additions & 5 deletions gui/wxpython/modules/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,9 @@ def AddLayers(self, returncode, cmd=None, userData=None):
if self.importType == "gdal":
nBands = int(userData.get("nbands", 1)) if userData else 1

if UserSettings.Get(group="rasterLayer", key="opaque", subkey="enabled"):
nFlag = True
else:
nFlag = False

nFlag = bool(
UserSettings.Get(group="rasterLayer", key="opaque", subkey="enabled")
)
for i in range(1, nBands + 1):
nameOrig = name
if nBands > 1:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ disable = [
"R0916", # (too-many-boolean-expressions)
"R0917", # (too-many-positional-arguments)
"R1702", # (too-many-nested-blocks)
"R1703", # The if statement can be replaced with %s (simplifiable-if-statement)
"R1704", # Redefining argument with the local name %r (redefined-argument-from-local)
"R1705", # Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
"R1710", # Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
Expand Down
25 changes: 8 additions & 17 deletions python/grass/script/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _process_module(self):
self.task.label = self._get_node_text(self.root, "label")
self.task.description = self._get_node_text(self.root, "description")

def _process_params(self):
def _process_params(self) -> None:
"""Process parameters"""
for p in self.root.findall("parameter"):
# gisprompt
Expand Down Expand Up @@ -347,15 +347,12 @@ def _process_params(self):
multiple = p.get("multiple", "no") == "yes"
required = p.get("required", "no") == "yes"

if (
hidden: bool = bool(
self.task.blackList["enabled"]
and self.task.name in self.task.blackList["items"]
and p.get("name")
in self.task.blackList["items"][self.task.name].get("params", [])
):
hidden = True
else:
hidden = False
)

self.task.params.append(
{
Expand All @@ -380,23 +377,17 @@ def _process_params(self):
}
)

def _process_flags(self):
def _process_flags(self) -> None:
"""Process flags"""
for p in self.root.findall("flag"):
if (
hidden: bool = bool(
self.task.blackList["enabled"]
and self.task.name in self.task.blackList["items"]
and p.get("name")
in self.task.blackList["items"][self.task.name].get("flags", [])
):
hidden = True
else:
hidden = False

if p.find("suppress_required") is not None:
suppress_required = True
else:
suppress_required = False
)

suppress_required: bool = bool(p.find("suppress_required") is not None)

self.task.flags.append(
{
Expand Down

0 comments on commit 60d91fb

Please sign in to comment.