Skip to content

Commit

Permalink
style: Fix unnecessary-assign (RET504) (OSGeo#4043)
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix authored Jul 13, 2024
1 parent 3b309db commit b01a67d
Show file tree
Hide file tree
Showing 58 changed files with 90 additions and 195 deletions.
3 changes: 1 addition & 2 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,7 @@ def unregisterPid(pid):
def get_shell_pid(env=None):
"""Get shell PID from the GIS environment or None"""
try:
shell_pid = int(grass.gisenv(env=env)["PID"])
return shell_pid
return int(grass.gisenv(env=env)["PID"])
except (KeyError, ValueError) as error:
Debug.msg(
1, "No PID for GRASS shell (assuming no shell running): {}".format(error)
Expand Down
8 changes: 2 additions & 6 deletions gui/wxpython/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def __filterValue(self, value):
:param value:
"""
value = value.replace("&lt;", "<")
value = value.replace("&gt;", ">")

return value
return value.replace("&gt;", ">")

def __getNodeText(self, node, tag, default=""):
"""Get node text"""
Expand Down Expand Up @@ -1043,9 +1041,7 @@ def __filterValue(self, value):
"""Make value XML-valid"""
value = value.replace("<", "&lt;")
value = value.replace(">", "&gt;")
value = value.replace("&", "&amp;")

return value
return value.replace("&", "&amp;")

def __writeLayer(self, mapTree, item):
"""Write bunch of layers to GRASS Workspace XML file"""
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ def _getValidSavedGrassDBs(self):
dbs = UserSettings.Get(
group="datacatalog", key="grassdbs", subkey="listAsString"
)
dbs = [db for db in dbs.split(",") if os.path.isdir(db)]
return dbs
return [db for db in dbs.split(",") if os.path.isdir(db)]

def _saveGrassDBs(self):
"""Save current grass dbs in tree to settings"""
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ def _getOverWriteDialog(self, maptype, overwrite):
map_name = "<{}>".format(found["name"])

if found["name"] and not overwrite:
overwrite_dlg = wx.MessageDialog(
return wx.MessageDialog(
self.GetParent(),
message=_(
"The {map_type} map {map_name} exists. "
Expand All @@ -1804,7 +1804,6 @@ def _getOverWriteDialog(self, maptype, overwrite):
caption=_("Overwrite?"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
return overwrite_dlg

def OnGeorect(self, event):
"""
Expand Down
7 changes: 2 additions & 5 deletions gui/wxpython/gmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2027,9 +2027,7 @@ def _filterValue(self, value):
:param value:
"""
value = value.replace("&lt;", "<")
value = value.replace("&gt;", ">")

return value
return value.replace("&gt;", ">")

def _getNodeText(self, node, tag, default=""):
"""Get node text"""
Expand Down Expand Up @@ -2342,8 +2340,7 @@ def _filterValue(self, value):
:param value: string to be escaped as XML
:return: a XML-valid string
"""
value = saxutils.escape(value)
return value
return saxutils.escape(value)

def _header(self):
"""Write header"""
Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/gui_core/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,7 @@ def _filter(self, data):
"""Apply filter for strings in data list"""
flt_data = []
if len(self.flt_pattern) == 0:
flt_data = data[:]
return flt_data
return data[:]

for dt in data:
try:
Expand Down Expand Up @@ -1872,8 +1871,7 @@ def __init__(
def GetOpacity(self):
"""Button 'OK' pressed"""
# return opacity value
opacity = float(self.value.GetValue()) / 100
return opacity
return float(self.value.GetValue()) / 100

def OnApply(self, event):
self.applyOpacity.emit(value=self.GetOpacity())
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3062,8 +3062,7 @@ def AddBitmapToImageList(self, section, imageList):
image = wx.Image(iconSectionDict[section]).Scale(
16, 16, wx.IMAGE_QUALITY_HIGH
)
idx = imageList.Add(BitmapFromImage(image))
return idx
return imageList.Add(BitmapFromImage(image))

return -1

Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/gui_core/gselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,7 @@ def AddItem(self, value, mapset=None, node=True, parent=None):

data = {"node": node, "mapset": mapset}

item = self.seltree.AppendItem(parent, text=value, data=data)
return item
return self.seltree.AppendItem(parent, text=value, data=data)

def OnKeyUp(self, event):
"""Enables to select items using keyboard
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/gui_core/pyedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ def _openFile(self, file_path):
"""
try:
with open(file_path, "r") as f:
content = f.read()
return content
return f.read()
except PermissionError:
GError(
message=_(
Expand Down
12 changes: 4 additions & 8 deletions gui/wxpython/gui_core/simplelmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,31 +377,27 @@ def GetOptData(self, dcmd, layer, params, propwin):

def AddRaster(self, name, cmd, hidden, dialog):
"""Ads new raster layer."""
layer = self._layerList.AddNewLayer(
return self._layerList.AddNewLayer(
name=name, mapType="raster", active=True, cmd=cmd, hidden=hidden
)
return layer

def AddRast3d(self, name, cmd, hidden, dialog):
"""Ads new raster3d layer."""
layer = self._layerList.AddNewLayer(
return self._layerList.AddNewLayer(
name=name, mapType="raster_3d", active=True, cmd=cmd, hidden=hidden
)
return layer

def AddVector(self, name, cmd, hidden, dialog):
"""Ads new vector layer."""
layer = self._layerList.AddNewLayer(
return self._layerList.AddNewLayer(
name=name, mapType="vector", active=True, cmd=cmd, hidden=hidden
)
return layer

def AddRGB(self, name, cmd, hidden, dialog):
"""Ads new vector layer."""
layer = self._layerList.AddNewLayer(
return self._layerList.AddNewLayer(
name=name, mapType="rgb", active=True, cmd=cmd, hidden=hidden
)
return layer

def GetLayerInfo(self, layer, key):
"""Just for compatibility, should be removed in the future"""
Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/gui_core/treeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def OnGetItemText(self, index, column=0):
"""
node = self._model.GetNodeByIndex(index)
# remove & because of & needed in menu (&Files)
label = node.label.replace("&", "")
return label
return node.label.replace("&", "")

def OnGetChildrenCount(self, index):
"""Overridden method necessary to communicate with tree model."""
Expand Down Expand Up @@ -258,8 +257,7 @@ def OnGetItemText(self, index, column=0):
if column > 0:
return node.data.get(self._columns[column], "")
else:
label = node.label.replace("&", "")
return label
return node.label.replace("&", "")

def OnRightClick(self, event):
"""Select item on right click.
Expand Down
6 changes: 1 addition & 5 deletions gui/wxpython/gui_core/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,11 +1338,7 @@ def _searchModule(self, keys, value):
nodes.sort(key=self._model.GetIndexOfNode)
self._results = nodes
self._resultIndex = -1
commands = sorted(
[node.data["command"] for node in nodes if node.data["command"]]
)

return commands
return sorted([node.data["command"] for node in nodes if node.data["command"]])

def OnSelectModule(self, event=None):
"""Module selected from choice, update command prompt"""
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/history/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,10 @@ def _timestampToDay(self, timestamp=None):
return OLD_DATE

timestamp_datetime = datetime.datetime.fromisoformat(timestamp)
day_midnight = datetime.datetime(
return datetime.datetime(
timestamp_datetime.year, timestamp_datetime.month, timestamp_datetime.day
).date()

return day_midnight

def _initHistoryModel(self):
"""Fill tree history model based on the current history log."""
content_list = self.ReadFromHistory()
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/iclass/digit.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def _getNewFeaturesLayer(self):
return 1

def _getNewFeaturesCat(self):
cat = self.mapWindow.GetCurrentCategory()
return cat
return self.mapWindow.GetCurrentCategory()

def DeleteAreasByCat(self, cats):
"""Delete areas (centroid+boundaries) by categories
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/iscatt/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ def _newScatterPlotName(self, scatt_id):
return name

def _getScatterPlotName(self, i):
name = "scatter plot %d" % i
return name
return "scatter plot %d" % i

def NewScatterPlot(self, scatt_id, transpose):
# TODO needs to be resolved (should be in this class)
Expand Down
8 changes: 2 additions & 6 deletions gui/wxpython/iscatt/iscatt_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,7 @@ def GetBandsInfo(self, scatt_id):
b1_info = self.an_data.GetBandInfo(b1)
b2_info = self.an_data.GetBandInfo(b2)

bands_info = {"b1": b1_info, "b2": b2_info}

return bands_info
return {"b1": b1_info, "b2": b2_info}

def DeleScattPlot(self, cat_id, scatt_id):
if cat_id not in self.cats:
Expand Down Expand Up @@ -784,15 +782,13 @@ def idBandsToidScatt(band_1_id, band_2_id, n_bands):

n_b1 = n_bands - 1

scatt_id = int(
return int(
(band_1_id * (2 * n_b1 + 1) - band_1_id * band_1_id) / 2
+ band_2_id
- band_1_id
- 1
)

return scatt_id


def GetRegion():
ret, region, msg = RunCommand("g.region", flags="gp", getErrorMsg=True, read=True)
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/iscatt/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,7 @@ def GetCoords(self):
if self.empty_pol:
return None

coords = deepcopy(self.pol.xy)
return coords
return deepcopy(self.pol.xy)

def SetEmpty(self):
self._setEmptyPol(True)
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2336,13 +2336,12 @@ def MsgDisplayResolution(self, limitText=None):
)
if limitText:
message += "\n\n%s" % _(limitText)
dlg = wx.MessageDialog(
return wx.MessageDialog(
parent=self,
message=message,
caption=_("Constrain map to region geometry?"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION | wx.CENTRE,
)
return dlg

def _onMapsetWatchdog(self, map_path, map_dest):
"""Current mapset watchdog event handler
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2428,12 +2428,11 @@ def _createCommandCtrl(self):
height = 25
if sys.platform in {"win32", "darwin"}:
height = 40
ctrl = TextCtrl(
return TextCtrl(
self,
id=wx.ID_ANY,
value="",
pos=wx.DefaultPosition,
size=(self.GetSize()[0] - 100, height),
style=wx.TE_PROCESS_ENTER | wx.TE_DONTWRAP,
)
return ctrl
7 changes: 2 additions & 5 deletions gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,7 @@ def GetSortImages(self):
def OnGetItemText(self, item, col):
"""Get item text"""
index = self.itemIndexMap[item]
s = str(self.itemDataMap[index][col])
return s
return str(self.itemDataMap[index][col])

def OnGetItemImage(self, item):
return -1
Expand Down Expand Up @@ -2795,9 +2794,7 @@ def CreateProj4String(self):
for item in datumparams:
proj4string = "%s +%s" % (proj4string, item)

proj4string = "%s +no_defs" % proj4string

return proj4string
return "%s +no_defs" % proj4string

def OnHelp(self, event):
"""'Help' button clicked"""
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/main_window/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2430,13 +2430,12 @@ def MsgDisplayResolution(self, limitText=None):
)
if limitText:
message += "\n\n%s" % _(limitText)
dlg = wx.MessageDialog(
return wx.MessageDialog(
parent=self,
message=message,
caption=_("Constrain map to region geometry?"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION | wx.CENTRE,
)
return dlg

def _onMapsetWatchdog(self, map_path, map_dest):
"""Current mapset watchdog event handler
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/nviz/mapwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def GetContentScaleFactor(self):

def InitFly(self):
"""Initialize fly through dictionary"""
fly = {
return {
"interval": 10, # interval for timerFly
"value": [0, 0, 0], # calculated values for navigation
"mode": 0, # fly through mode (0, 1)
Expand All @@ -264,8 +264,6 @@ def InitFly(self):
"flySpeedStep": 2,
}

return fly

def OnTimerFly(self, event):
"""Fly event was emitted, move the scene"""
if self.mouse["use"] != "fly":
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/nviz/wxnviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,9 +2212,7 @@ def Load(self):
]
wx.EndBusyCursor()

id = Nviz_load_image(im, self.width, self.height, self.image.HasAlpha())

return id
return Nviz_load_image(im, self.width, self.height, self.image.HasAlpha())

def Draw(self):
"""Draw texture as an image"""
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/psmap/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3200,8 +3200,7 @@ def getColsChoice(self, parent):
else:
cols = []

choice = Choice(parent=parent, id=wx.ID_ANY, choices=cols)
return choice
return Choice(parent=parent, id=wx.ID_ANY, choices=cols)

def update(self):
# feature type
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/psmap/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2613,9 +2613,7 @@ def ImageRect(self):
iH = iH * self.currScale
x = cW / 2 - iW / 2
y = cH / 2 - iH / 2
imageRect = Rect(int(x), int(y), int(iW), int(iH))

return imageRect
return Rect(int(x), int(y), int(iW), int(iH))

def RedrawSelectBox(self, id):
"""Redraws select box when selected object changes its size"""
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/psmap/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1913,8 +1913,7 @@ def __init__(self, id, env):
self.instruction = dict(self.defaultInstruction)

def __str__(self):
instr = string.Template("raster $raster").substitute(self.instruction)
return instr
return string.Template("raster $raster").substitute(self.instruction)

def Read(self, instruction, text):
"""Read instruction and save information"""
Expand Down
Loading

0 comments on commit b01a67d

Please sign in to comment.