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: Fix if-else-block-instead-of-if-exp (SIM108) (part 3) #271

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,10 +1619,7 @@ def SetStdsProperties(self, layer):
dlg.CenterOnParent()
if dlg.ShowModal() == wx.ID_OK:
layer = dlg.GetLayer()
if hidden:
signal = self.layerAdded
else:
signal = self.cmdChanged
signal = self.layerAdded if hidden else self.cmdChanged
signal.emit(index=self._layerList.GetLayerIndex(layer), layer=layer)
elif hidden:
self._layerList.RemoveLayer(layer)
Expand Down
17 changes: 4 additions & 13 deletions gui/wxpython/animation/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,11 @@ def OnStop(self, event):
self.controller.EndAnimation()

def OnOneDirectionReplay(self, event):
if event.IsChecked():
mode = ReplayMode.REPEAT
else:
mode = ReplayMode.ONESHOT
mode = ReplayMode.REPEAT if event.IsChecked() else ReplayMode.ONESHOT
self.controller.SetReplayMode(mode)

def OnBothDirectionReplay(self, event):
if event.IsChecked():
mode = ReplayMode.REVERSE
else:
mode = ReplayMode.ONESHOT
mode = ReplayMode.REVERSE if event.IsChecked() else ReplayMode.ONESHOT
self.controller.SetReplayMode(mode)

def OnAdjustSpeed(self, event):
Expand Down Expand Up @@ -642,11 +636,8 @@ def _updateFrameIndex(self, index):
}
else:
label = _("to %(to)s") % {"to": self.timeLabels[index][1]}
else: # noqa: PLR5501
if self.temporalType == TemporalType.ABSOLUTE:
label = start
else:
label = ""
else:
label = start if self.temporalType == TemporalType.ABSOLUTE else ""
self.label2.SetLabel(label)
if self.temporalType == TemporalType.RELATIVE:
self.indexField.SetValue(start)
Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/animation/temporal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,8 @@ def _getLabelsAndMaps(self, timeseries):

elif self.temporalType == TemporalType.RELATIVE:
unit = self.timeseriesInfo[timeseries]["unit"]
if self.granularityMode == GranularityMode.ONE_UNIT:
gran = 1
else:
gran = granNum
gran = 1 if self.granularityMode == GranularityMode.ONE_UNIT else granNum

# start sampling - now it can be used for both interval and point data
# after instance, there can be a gap or an interval
# if it is a gap we remove it and put there the previous instance instead
Expand Down
5 changes: 1 addition & 4 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,7 @@ def RunCommand(
kwargs["stdin"] = subprocess.PIPE

# Do not change the environment, only a local copy.
if env:
env = env.copy()
else:
env = os.environ.copy()
env = env.copy() if env else os.environ.copy()

if parent:
env["GRASS_MESSAGE_FORMAT"] = "standard"
Expand Down
10 changes: 2 additions & 8 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,7 @@ def write(self, s):

if "GRASS_INFO_PERCENT" in line:
value = int(line.rsplit(":", 1)[1].strip())
if value >= 0 and value < 100:
progressValue = value
else:
progressValue = 0
progressValue = value if value >= 0 and value < 100 else 0
elif "GRASS_INFO_MESSAGE" in line:
self.type = "message"
self.message += line.split(":", 1)[1].strip() + "\n"
Expand Down Expand Up @@ -632,10 +629,7 @@ def load_source(modname, filename):

return

if env:
env = env.copy()
else:
env = os.environ.copy()
env = env.copy() if env else os.environ.copy()
# activate computational region (set with g.region)
# for all non-display commands.
if compReg and "GRASS_REGION" in env:
Expand Down
32 changes: 8 additions & 24 deletions gui/wxpython/core/menutree.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,14 @@
shortcut = item.find("shortcut") # optional
wxId = item.find("id") # optional
icon = item.find("icon") # optional
if gcmd is not None:
gcmd = gcmd.text
else:
gcmd = ""
if desc.text:
desc = _(desc.text)
else:
desc = ""
if keywords is None or keywords.text is None:
keywords = ""
else:
keywords = keywords.text
if shortcut is not None:
shortcut = shortcut.text
else:
shortcut = ""
if wxId is not None:
wxId = eval("wx." + wxId.text)
else:
wxId = wx.ID_ANY
if icon is not None:
icon = icon.text
else:
icon = ""
gcmd = gcmd.text if gcmd is not None else ""
desc = _(desc.text) if desc.text else ""
keywords = (
"" if keywords is None or keywords.text is None else keywords.text
)
shortcut = shortcut.text if shortcut is not None else ""
wxId = eval("wx." + wxId.text) if wxId is not None else wx.ID_ANY

Check warning

Code scanning / Bandit

Use of possibly insecure function - consider using safer ast.literal_eval. Warning

Use of possibly insecure function - consider using safer ast.literal_eval.
icon = icon.text if icon is not None else ""
label = origLabel
if gcmd:
if self.menustyle == 1:
Expand Down
45 changes: 11 additions & 34 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ def __init__(
if mapfile:
self.mapfile = mapfile
else:
if ltype == "overlay":
tempfile_sfx = ".png"
else:
tempfile_sfx = ".ppm"
tempfile_sfx = ".png" if ltype == "overlay" else ".ppm"

self.mapfile = get_tempfile_name(suffix=tempfile_sfx)

Expand Down Expand Up @@ -790,10 +787,7 @@ def ReportProgress(self, env, layer=None):
stText += "..."

if self.progressInfo["range"] != len(self.progressInfo["rendered"]):
if stText:
stText = _("Rendering & ") + stText
else:
stText = _("Rendering...")
stText = _("Rendering & ") + stText if stText else _("Rendering...")

self.updateProgress.emit(
range=self.progressInfo["range"],
Expand Down Expand Up @@ -1260,16 +1254,8 @@ def GetListOfLayers(
:return: list of selected layers
"""
selected = []

if isinstance(ltype, str):
one_type = True
else:
one_type = False

if one_type and ltype == "overlay":
llist = self.overlays
else:
llist = self.layers
one_type = bool(isinstance(ltype, str))
llist = self.overlays if one_type and ltype == "overlay" else self.layers

# ["raster", "vector", "wms", ... ]
for layer in llist:
Expand Down Expand Up @@ -1332,10 +1318,7 @@ def Render(self, force=False, windres=False):
self.renderMgr.Render(force, windres)

def _addLayer(self, layer, pos=-1):
if layer.type == "overlay":
llist = self.overlays
else:
llist = self.layers
llist = self.overlays if layer.type == "overlay" else self.layers

# add maplayer to the list of layers
if pos > -1:
Expand Down Expand Up @@ -1426,12 +1409,9 @@ def DeleteLayer(self, layer, overlay=False):
"""
Debug.msg(3, "Map.DeleteLayer(): name=%s" % layer.name)

if overlay:
list = self.overlays
else:
list = self.layers
_list = self.overlays if overlay else self.layers

if layer in list:
if layer in _list:
if layer.mapfile:
base, mapfile = os.path.split(layer.mapfile)
tempbase = mapfile.split(".")[0]
Expand All @@ -1448,7 +1428,7 @@ def DeleteLayer(self, layer, overlay=False):
if os.path.isfile(layer._legrow):
os.remove(layer._legrow)

list.remove(layer)
_list.remove(layer)

self.layerRemoved.emit(layer=layer)
return layer
Expand Down Expand Up @@ -1583,13 +1563,10 @@ def GetLayerIndex(self, layer, overlay=False):
:return: layer index
:return: -1 if layer not found
"""
if overlay:
list = self.overlays
else:
list = self.layers
_list = self.overlays if overlay else self.layers

if layer in list:
return list.index(layer)
if layer in _list:
return _list.index(layer)

return -1

Expand Down
5 changes: 1 addition & 4 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,7 @@ def _readLegacyFile(self, settings=None):
del kv[0]
idx = 0
while idx < len(kv):
if subkeyMaster:
subkey = [subkeyMaster, kv[idx]]
else:
subkey = kv[idx]
subkey = [subkeyMaster, kv[idx]] if subkeyMaster else kv[idx]
value = kv[idx + 1]
value = self._parseValue(value, read=True)
self.Append(settings, group, key, subkey, value)
Expand Down
7 changes: 2 additions & 5 deletions gui/wxpython/core/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,12 @@ def __init__(self, label=None, data=None):
def label(self):
return self._label

def match(self, key, value, case_sensitive=False):
def match(self, key, value, case_sensitive=False) -> bool:
"""Method used for searching according to command,
keywords or description."""
if not self.data:
return False
if isinstance(key, str):
keys = [key]
else:
keys = key
keys = [key] if isinstance(key, str) else key

for key in keys:
if key not in {"command", "keywords", "description"}:
Expand Down
5 changes: 1 addition & 4 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,7 @@ def StoreEnvVariable(key, value=None, envFile=None):
)
)
return
if windows:
expCmd = "set"
else:
expCmd = "export"
expCmd = "set" if windows else "export"

for key, value in environ.items():
fd.write("%s %s=%s\n" % (expCmd, key, value))
Expand Down
22 changes: 5 additions & 17 deletions gui/wxpython/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,8 @@ def __processFile(self):
size = None

extentAttr = display.get("extent", "")
if extentAttr:
# w, s, e, n
extent = map(float, extentAttr.split(","))
else:
extent = None
# w, s, e, n
extent = map(float, extentAttr.split(",")) if extentAttr else None

# projection
node_projection = display.find("projection")
Expand Down Expand Up @@ -312,10 +309,7 @@ def __processLayer(self, layer):
)
)

if layer.find("selected") is not None:
selected = True
else:
selected = False
selected = layer.find("selected") is not None

#
# Vector digitizer settings
Expand All @@ -330,10 +324,7 @@ def __processLayer(self, layer):
# Nviz (3D settings)
#
node_nviz = layer.find("nviz")
if node_nviz is not None:
nviz = self.__processLayerNviz(node_nviz)
else:
nviz = None
nviz = self.__processLayerNviz(node_nviz) if node_nviz is not None else None

return (cmd, selected, vdigit, nviz)

Expand Down Expand Up @@ -729,10 +720,7 @@ def __processLayerNvizNode(self, node, tag, cast, dc=None):
try:
value = cast(node_tag.text)
except ValueError:
if cast == str:
value = ""
else:
value = None
value = "" if cast == str else None
if dc:
dc[tag] = {}
dc[tag]["value"] = value
Expand Down
5 changes: 1 addition & 4 deletions gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,10 +2016,7 @@ def _getNewMapName(self, message, title, value, element, mapset, env):
mapset=mapset,
)
dlg.SetValue(value)
if dlg.ShowModal() == wx.ID_OK:
name = dlg.GetValue()
else:
name = None
name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
dlg.Destroy()

return name
Expand Down
Loading
Loading