Skip to content

Commit

Permalink
style: Fix collapsible-else-if (PLR5501) (#4045)
Browse files Browse the repository at this point in the history
* style: Fix collapsible-else-if (PLR5501)

Ruff rule: https://docs.astral.sh/ruff/rules/collapsible-else-if/

* style: Fix collapsible-else-if (PLR5501)

Ruff rule: https://docs.astral.sh/ruff/rules/collapsible-else-if/

* style: Fix collapsible-else-if (PLR5501)

Ruff rule: https://docs.astral.sh/ruff/rules/collapsible-else-if/

* Apply suggestions from code review

Co-authored-by: Stefan Blumentrath <stefan.blumentrath@gmx.de>

* style: Combine if conditions in wxpython/gmodeler/model.py

* style: Simplify if conditions in wxpython/gui_core

---------

Co-authored-by: Stefan Blumentrath <stefan.blumentrath@gmx.de>
  • Loading branch information
echoix and ninsbl authored Jul 17, 2024
1 parent 692e330 commit f99780c
Show file tree
Hide file tree
Showing 90 changed files with 871 additions and 1,042 deletions.
2 changes: 1 addition & 1 deletion gui/wxpython/animation/anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _arrivedToEnd(self):
self.orientation = Orientation.BACKWARD
self.currentIndex = self.count - 2 # -1
self.callbackOrientationChanged(Orientation.BACKWARD)
else:
else: # noqa: PLR5501
if self.replayMode == ReplayMode.REPEAT:
self.currentIndex = self.count - 1
elif self.replayMode == ReplayMode.REVERSE:
Expand Down
25 changes: 11 additions & 14 deletions gui/wxpython/animation/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def PauseAnimation(self, paused):
if self.timer.IsRunning():
self.timer.Stop()
self.DisableSliderIfNeeded()
else:
else: # noqa: PLR5501
if not self.timer.IsRunning():
self.timer.Start(int(self.timeTick))
self.DisableSliderIfNeeded()
Expand Down Expand Up @@ -555,9 +555,8 @@ def _export(self, exportInfo, decorations):
if frameId is not None:
bitmap = self.bitmapProvider.GetBitmap(frameId)
lastBitmaps[i] = bitmap
else:
if i not in lastBitmaps:
lastBitmaps[i] = wx.NullBitmap()
elif i not in lastBitmaps:
lastBitmaps[i] = wx.NullBitmap()
else:
bitmap = self.bitmapProvider.GetBitmap(frameId)
lastBitmaps[i] = bitmap
Expand Down Expand Up @@ -593,17 +592,15 @@ def _export(self, exportInfo, decorations):
"dash": "\u2013",
"to": timeLabel[1],
}
elif (
self.temporalManager.GetTemporalType() == TemporalType.ABSOLUTE
):
text = timeLabel[0]
else:
if (
self.temporalManager.GetTemporalType()
== TemporalType.ABSOLUTE
):
text = timeLabel[0]
else:
text = _("%(start)s %(unit)s") % {
"start": timeLabel[0],
"unit": timeLabel[2],
}
text = _("%(start)s %(unit)s") % {
"start": timeLabel[0],
"unit": timeLabel[2],
}

decImage = RenderText(
text, decoration["font"], bgcolor, fgcolor
Expand Down
10 changes: 4 additions & 6 deletions gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,8 @@ def GetOptData(self, dcmd, layer, params, propwin):

if not self.legend.IsChecked():
self.legend.SetValue(True)
else:
if not self._tmpLegendCmd and not self.animationData.legendCmd:
self.legend.SetValue(False)
elif not self._tmpLegendCmd and not self.animationData.legendCmd:
self.legend.SetValue(False)

def _update(self):
if self.nDChoice.GetSelection() == 1 and len(self._layerList) > 1:
Expand Down Expand Up @@ -1623,9 +1622,8 @@ def SetStdsProperties(self, layer):
else:
signal = self.cmdChanged
signal.emit(index=self._layerList.GetLayerIndex(layer), layer=layer)
else:
if hidden:
self._layerList.RemoveLayer(layer)
elif hidden:
self._layerList.RemoveLayer(layer)
dlg.Destroy()
self._update()
self.anyChange.emit()
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/animation/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def _updateFrameIndex(self, index):
}
else:
label = _("to %(to)s") % {"to": self.timeLabels[index][1]}
else:
else: # noqa: PLR5501
if self.temporalType == TemporalType.ABSOLUTE:
label = start
else:
Expand Down
29 changes: 13 additions & 16 deletions gui/wxpython/animation/nviztask.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ def _processSurface(self, surface, mapName):
mapname = surface["attribute"][attr]["value"]
else:
const = surface["attribute"][attr]["value"]
else:
if attr == "transp":
const = 0
elif attr == "color":
mapname = mapName
elif attr == "transp":
const = 0
elif attr == "color":
mapname = mapName

if mapname:
self._setMultiTaskParam(params[0], mapname)
Expand Down Expand Up @@ -194,21 +193,19 @@ def _processVolume(self, volume, mapName):
mapname = isosurface[attr]["value"]
else:
const = float(isosurface[attr]["value"])
else:
if attr == "transp":
const = 0
elif attr == "color":
mapname = mapName
elif attr == "transp":
const = 0
elif attr == "color":
mapname = mapName

if mapname:
self._setMultiTaskParam(params[0], mapname)
elif attr == "topo":
# TODO: we just assume it's the first volume, what
# to do else?
self._setMultiTaskParam(params[1], "1:" + str(const))
else:
if attr == "topo":
# TODO: we just assume it's the first volume, what
# to do else?
self._setMultiTaskParam(params[1], "1:" + str(const))
else:
self._setMultiTaskParam(params[1], const)
self._setMultiTaskParam(params[1], const)
if isosurface["inout"]["value"]:
self.task.set_flag("n", True)
# slices
Expand Down
23 changes: 11 additions & 12 deletions gui/wxpython/animation/temporal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,19 @@ def _getLabelsAndMaps(self, timeseries):
# map exists, stop point mode
listOfMaps.append(series)
afterPoint = False
else:
elif afterPoint:
# check point mode
if afterPoint:
if followsPoint:
# skip this one, already there
followsPoint = False
continue
else:
# append the last one (of point time)
listOfMaps.append(lastTimeseries)
end = None
if followsPoint:
# skip this one, already there
followsPoint = False
continue
else:
# append series which is None
listOfMaps.append(series)
# append the last one (of point time)
listOfMaps.append(lastTimeseries)
end = None
else:
# append series which is None
listOfMaps.append(series)
timeLabels.append((start, end, unit))

return timeLabels, listOfMaps
Expand Down
9 changes: 4 additions & 5 deletions gui/wxpython/core/globalvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,10 @@ def UpdateGRASSAddOnCommands(eList=None):
and name not in grassScripts[ext]
):
grassScripts[ext].append(name)
else:
if fname not in grassCmd:
grassCmd.add(fname)
Debug.msg(3, "AddOn commands: %s", fname)
nCmd += 1
elif fname not in grassCmd:
grassCmd.add(fname)
Debug.msg(3, "AddOn commands: %s", fname)
nCmd += 1

Debug.msg(1, "Number of GRASS AddOn commands: %d", nCmd)

Expand Down
15 changes: 7 additions & 8 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,13 @@ def GetName(self, fullyQualified=True):
"""
if fullyQualified:
return self.name
else:
if "@" in self.name:
return {
"name": self.name.split("@")[0],
"mapset": self.name.split("@")[1],
}
else:
return {"name": self.name, "mapset": ""}

if "@" in self.name:
return {
"name": self.name.split("@")[0],
"mapset": self.name.split("@")[1],
}
return {"name": self.name, "mapset": ""}

def GetRenderedSize(self):
"""Get currently rendered size of layer as tuple, None if not rendered"""
Expand Down
33 changes: 18 additions & 15 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ def _parseValue(self, value, read=False):
value = float(value)
except ValueError:
pass
else: # -> write settings
else: # -> write settings # noqa: PLR5501
if isinstance(value, type(())): # -> color
value = str(value[0]) + ":" + str(value[1]) + ":" + str(value[2])

Expand Down Expand Up @@ -1062,13 +1062,13 @@ def Get(self, group, key=None, subkey=None, settings_type="user"):
if subkey is None:
if key is None:
return settings[group]
else:
return settings[group][key]
else:
if isinstance(subkey, tuple) or isinstance(subkey, list):
return settings[group][key][subkey[0]][subkey[1]]
else:
return settings[group][key][subkey]

return settings[group][key]

if isinstance(subkey, (list, tuple)):
return settings[group][key][subkey[0]][subkey[1]]

return settings[group][key][subkey]

except KeyError:
print(
Expand Down Expand Up @@ -1099,13 +1099,16 @@ def Set(self, group, value, key=None, subkey=None, settings_type="user"):
if subkey is None:
if key is None:
settings[group] = value
else:
settings[group][key] = value
else:
if isinstance(subkey, tuple) or isinstance(subkey, list):
settings[group][key][subkey[0]][subkey[1]] = value
else:
settings[group][key][subkey] = value
return
settings[group][key] = value
return

if isinstance(subkey, (list, tuple)):
settings[group][key][subkey[0]][subkey[1]] = value
return
settings[group][key][subkey] = value
return

except KeyError:
raise GException(
"%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey)
Expand Down
5 changes: 2 additions & 3 deletions gui/wxpython/core/toolboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,8 @@ def _indent(elem, level=0):
_indent(_elem, level + 1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
elif level and (not elem.tail or not elem.tail.strip()):
elem.tail = i


def expandAddons(tree):
Expand Down
5 changes: 2 additions & 3 deletions gui/wxpython/core/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,10 @@ def match(self, key, value, case_sensitive=False):
# start supported but unused, so testing last
if value in text or value == "*":
return True
else:
elif value.lower() in text.lower() or value == "*":
# this works fully only for English and requires accents
# to be exact match (even Python 3 casefold() does not help)
if value.lower() in text.lower() or value == "*":
return True
return True
return False


Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def ConvertValue(value, type, units):
f = 6.21371192237334e-4
elif units == "ft":
f = 3.28083989501312
else: # -> area
else: # -> area # noqa: PLR5501
if units == "me":
f = 1.0
elif units == "km":
Expand Down
33 changes: 16 additions & 17 deletions gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,25 +1293,24 @@ def OnPasteMap(self, event):
if not new_name:
return
# within one location, different mapsets
else:
if map_exists(
new_name,
element=self.copy_layer[i].data["type"],
elif map_exists(
new_name,
element=self.copy_layer[i].data["type"],
env=env,
mapset=self.selected_mapset[0].data["name"],
):
new_name = self._getNewMapName(
_("New name for <{n}>").format(
n=self.copy_layer[i].data["name"]
),
_("Select new name"),
self.copy_layer[i].data["name"],
env=env,
mapset=self.selected_mapset[0].data["name"],
):
new_name = self._getNewMapName(
_("New name for <{n}>").format(
n=self.copy_layer[i].data["name"]
),
_("Select new name"),
self.copy_layer[i].data["name"],
env=env,
mapset=self.selected_mapset[0].data["name"],
element=self.copy_layer[i].data["type"],
)
if not new_name:
return
element=self.copy_layer[i].data["type"],
)
if not new_name:
return

string = (
self.copy_layer[i].data["name"]
Expand Down
7 changes: 3 additions & 4 deletions gui/wxpython/dbmgr/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2165,11 +2165,10 @@ def OnApplySqlStatement(self, event):
# sort by key column
if sql and "order by" in sql.lower():
pass # don't order by key column
elif keyColumn > -1:
listWin.SortListItems(col=keyColumn, ascending=True)
else:
if keyColumn > -1:
listWin.SortListItems(col=keyColumn, ascending=True)
else:
listWin.SortListItems(col=0, ascending=True)
listWin.SortListItems(col=0, ascending=True)

wx.EndBusyCursor()

Expand Down
16 changes: 7 additions & 9 deletions gui/wxpython/dbmgr/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,19 @@ def GetSQLString(self, updateValues=False):
)
sqlCommands.append(None)
continue
else:
if self.action == "add":
continue
elif self.action == "add":
continue

if newvalue != value:
updatedColumns.append(name)
if newvalue == "":
updatedValues.append("NULL")
elif ctype != str:
updatedValues.append(str(newvalue))
else:
if ctype != str:
updatedValues.append(str(newvalue))
else:
updatedValues.append(
"'" + newvalue.replace("'", "''") + "'"
)
updatedValues.append(
"'" + newvalue.replace("'", "''") + "'"
)
columns[name]["values"][idx] = newvalue

if self.action != "add" and len(updatedValues) == 0:
Expand Down
7 changes: 3 additions & 4 deletions gui/wxpython/dbmgr/vinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ def SelectByPoint(self, queryCoords, qdist):
for key, value in record["Attributes"].items():
if len(value) < 1:
value = None
elif self.tables[table][key]["ctype"] != str:
value = self.tables[table][key]["ctype"](value)
else:
if self.tables[table][key]["ctype"] != str:
value = self.tables[table][key]["ctype"](value)
else:
value = GetUnicodeValue(value)
value = GetUnicodeValue(value)
self.tables[table][key]["values"].append(value)

for key, value in record.items():
Expand Down
Loading

0 comments on commit f99780c

Please sign in to comment.